Topic 3 of 5 · 5 min read
Interactive, queued and batch traffic lanes
Goal: Split a workload into interactive, queued and batch lanes and estimate the cost and latency of each.
Split traffic into lanes by how long the caller can wait: interactive for people, queued for background jobs, batch for work that can take hours. Each lane gets its own capacity, its own price and its own failure behaviour.
Check yourself · 1 of 3
A nightly job summarizes 40,000 support tickets, and nobody needs the result before 8 am. Which lane fits best?
Why it matters
A chat reply must start in a second or two. A nightly summary of 50,000 tickets can arrive by morning. If both use the same path, the summary job eats the quota and chat slows down. Splitting them protects users and lets you buy cheaper capacity for work that can wait.
The three lanes
- Interactive. A person is waiting. Streaming, short queue, tight timeout, and the first claim on quota. If it cannot run, fail fast with a clear message.
- Queued. A job runs soon but nobody is staring at it: webhooks, enrichment, email drafts. Put it on a queue with workers that pull at a controlled rate. A full queue pushes back on the caller (backpressure) instead of growing without limit.
- Batch. The result can wait hours. Providers such as Anthropic and OpenAI offer asynchronous batch endpoints with a completion window of up to 24 hours and a discount against normal prices. Check the current discount and limits in their docs. Batch usually has its own, separate rate limits, so it does not touch your interactive quota. Some providers also offer lower-priority or flex tiers for requests that tolerate slower or occasionally failed service.
How to do it
- List every call site and ask: how long can the caller wait?
- Assign each to a lane. When unsure, ask the product owner what happens if the answer is an hour late.
- Reserve quota for the interactive lane. Let queued work use what is left, and run it slower when interactive load is high.
- Give each lane a timeout, a retry rule and a dead-letter place for failures.
- Estimate cost and latency per lane, then compare to the single-lane design.
Before and after
Weak: the daily report job calls the same endpoint as chat, with 20 parallel workers. At 09:00 chat latency triples.
Better: chat has reserved quota. The report job moves to the batch endpoint, runs overnight at a lower price and no longer touches the chat quota.
What goes wrong
- Batching work a person is waiting on. Batch is not for anything with a user watching.
- An unbounded queue. Work piles up, results arrive stale and memory grows. Cap the queue and reject or shed load.
- No priority inside the queue. A large bulk job ahead of urgent items blocks them. Use separate queues or priority classes.
- Forgetting partial failure. Batches complete with some items failed. Read the results per item and retry only those.
Examples
A lane plan for one product
| Call | Wait allowed | Lane |
|---|---|---|
| Chat reply | 2 seconds to first token | Interactive |
| Auto-tag a new upload | 1 minute | Queued |
| Nightly summary of all tickets | 8 hours | Batch |
| Quarterly re-classification of the archive | 3 days | Batch |
Only the first row needs reserved quota and streaming. The last two cost less and cannot slow it down.
Backpressure on a queue
if queue.qsize() >= MAX_QUEUE:
raise Busy(retry_after=30) # tell the caller, do not grow forever
queue.put(job)
A caller that gets Busy can retry later or show a message. A queue with no limit just turns an overload into hours of delay.
Key points
- Assign each call site to a lane by how long the caller can wait: interactive, queued or batch.
- Reserve quota for interactive traffic and let background work use what is left.
- Bound every queue, so a full queue pushes back on callers instead of growing without limit.
- Batch endpoints take work that can wait up to a day, at a discount and with their own limits; check current terms in the provider docs.
- Batches finish with per-item results, so retry only the failed items.
Common mistakes
- Sending everything through one endpoint and letting background jobs compete with users.
- Using a batch endpoint for a task where a user is waiting for the answer.
- Leaving queues unbounded so overload shows up as stale results hours later.
- Treating a finished batch as all-or-nothing instead of checking each item.
Check yourself · 2 of 3
What does backpressure mean for a job queue in front of an LLM?
Check yourself · 3 of 3
A batch of 1,000 requests completes with 37 items marked failed. What is the right next step?
Practice items, not counted towards your mastery.
Start here
- Rate limits (Claude API docs) (opens in a new tab)DocsFree
Request and token limits per model, usage tiers, 429 errors and the retry-after and remaining-quota headers.
- Rate limits (OpenAI API) (opens in a new tab)DocsFree
How requests per minute, tokens per minute and usage tiers work, and how to back off after a 429.
- Batch processing (Claude) (opens in a new tab)DocsFree
How the asynchronous batch endpoint works, its discount and its completion window.
More for this topic
- Batch API (OpenAI) (opens in a new tab)DocsFree
The 24-hour batch endpoint for non-urgent work, with its separate rate limits and discount.