Serving
Token streaming
Partial output is sent to the client token by token as the model writes it, so the user starts reading seconds before the full reply exists.
A model writes a reply one token at a time, but an interface can either wait until the reply is complete or forward each token the moment it exists. Streaming takes the second path: the server pushes partial output over a socket or a long-lived connection, and the client renders the words as they land.
Streaming changes nothing about what the model computes, so the total time and total cost are identical. What it changes is when the waiting happens: the long silent wait is replaced by a shorter wait for the first token followed by live output the user is already reading. Interfaces that buffer the whole reply, whether in the proxy, the client library, or the product code, quietly give up all of that, which makes them feel several times slower than they are.
The engineering notes: streaming should be measured at the client edge, because proxies add buffering of their own; the two metrics to pair are time to first token (when reading can start) and inter-token latency (how steady the typing looks). And some workloads - code execution, structured outputs - may prefer collecting the whole reply first, which is a product decision to make on purpose rather than by default.
A worked example
A 500-token reply from a model decoding at 24 tokens per second, with a first token arriving 0.5 s after the request.
- Full reply finish time: 0.5 s + 500 / 24 = 21.3 s after the request.
- Buffered: everything arrives at 21.3 s, and the user has read nothing until then.
- Streamed: the first words land at about 0.5 s, and reading at 5 words per second keeps pace with the tokens arriving.
- Same compute, same cost, but the wait before the user starts drops from 21 s to under 1 s.
Streaming does not make the model faster; it moves the wait to before the first token, where users can start reading.
Where this shows up
- Design ChatGPT: Tiers & Rate LimitsDesign ChatGPT is the most-cited systems design question at AI companies, and it is really one question: when everyone arrives at once, who gets served, who waits, and who is told no, all without the paying tier ever noticing. The answer interviewers grade against has three parts. First, three pools: a small provisioned pool whose cards exist for one tier only, a larger shared pool where paid requests carry priority over free ones, and the queue itself, which lives in card memory, not in a message broker. Second, a token-bucket rate limiter at the gateway, held in Redis for atomicity under concurrent writers, that admits free arrivals at a chosen share of demand and reconciles the token count after each grant, so a burst of arrivals is answered instantly without consulting a GPU. Third, shedding: a request refused at the gateway with a 429 costs nothing; the same request admitted into a saturated pool holds an expensive seat and lengthens every wait behind it, which is why the tail wait punishes utilization non-linearly, and why an incident that removes 30% of capacity can turn a 97 millisecond paid wait into an 850 millisecond one. Interviewers test this because every knob in the design is a money or trust decision: renting burst capacity for a launch day, tightening the bucket over a jammed pool, or letting the free tier shed so the subscribers do not notice an outage. The three challenges below work the mechanics: the admit count a token bucket grants, the queue wait the utilization formula quotes, and the shed arithmetic that keeps the shared pool from jamming.
- Serving AI ReliablyThe AI feature launched ten days ago and is the quietest thing you operate: the dashboard is a strip of green graphs, no complaints, nothing shipped this week. Then at 3am something changes, and running this feature is different because the dependency is a model you neither wrote nor can restart: a provider answers your users, and the provider can change its capacity, its pricing, or the model itself without telling you. So the board grows meters that watch the call rather than your code. p95 latency, the wait that 95 of every 100 requests stay under, catches a capacity squeeze that the median wait, p50, smooths right over. The error share catches a rate limit, a provider ceiling on how many calls fit in a minute that a launch surge can trip with zero code changes. Daily spend catches a prompt edit that quietly broke the prefix cache, the discount a provider grants while your requests resend the same opening text. And an eval set, a small fixed list of prompts with expected answers that your code reruns on a schedule, catches the scariest one: a silent quality drop after the provider swapped the model, the failure users notice and no latency meter ever blinks. What you do about it is the fallback ladder, an ordered list of answers to serve while the model misbehaves: retries with backoff first, then a smaller or older model, then a cached reply, ordered so the user meets slow long before they ever meet gone. Pinning, writing the exact model version into your config instead of floating on the provider default, is what turns a swap back into a rollback. Interviewers ask what you watch and what you do at 3am: a specific ladder is the answer of someone who ran a live AI feature, and we would monitor things is the answer of someone who has not. The three challenges below grade exactly that: the order you triage a crowded alert board in, the p95 and eval math that tells you to roll a model version back, and the share counters that say whether the ladder is holding.