0:00Intro: MOFUSA Tech Academy
Welcome to MOFUSA Tech Academy. Beyond learning, towards mastery.
0:09500 customers at lunchtime: why serving is hard
Every day at lunchtime, Brightcart's chat traffic spikes: hundreds of customers at once. Requests pile up in a queue, the wait for the first word stretches past six seconds for the slowest customers, and the goodput we defined in episode seventy-seven collapses. Making the model faster helps each customer. Serving many customers at once is a different problem: how to share the hardware cleverly. Today: batching, managing cache memory, separating the two phases of generation, caching, and splitting work across many chips.
Season Five, Module Twenty-One, final stop: faster serving.
0:52Batching: one weight read, many customers
Remember why decoding is slow: every step reads all of the model's weights to produce just one token for one user. Batching fixes the waste. Process the next token for many users in the same step, and a single read of the weights serves all of them, like one delivery van dropping parcels at thirty-two houses, instead of thirty-two separate trips. In an idealised calculation, with our illustrative memory speed, one user tops out around a hundred and forty tokens a second, while a batch of thirty-two can reach thousands of tokens a second in total, with each user's speed staying similar, for short conversations.
With Brightcart's long prompts, reading each customer's KV cache becomes the limit well before a batch of thirty-two, so real gains are smaller, though still large. The trade-off: very large batches, or making requests wait to fill a batch, eventually slow individual customers down.
1:53Continuous batching: the bus that never waits
How you batch matters. Simple static batching is like a bus that waits until it's full, then drives the whole route, so a customer with a short reply is stuck until the longest reply in the batch finishes. Continuous batching is like a bus that never stops moving. At every single decoding step, requests that have finished get off, and new requests waiting in the queue get on. The hardware stays busy, short replies leave as soon as they're done, and new customers start sooner. Research systems introduced this kind of step-by-step scheduling around two thousand twenty-two, and it's now standard in modern serving engines.
2:38Paged KV-cache memory
Batching many users means holding many K-V caches at once, each growing token by token, and you never know in advance how long a reply will be. If the server reserves a large block of memory for the maximum possible length of every conversation, most of that memory sits unused, and it runs out quickly. A widely adopted solution, introduced in two thousand twenty-three, manages cache memory in small, fixed-size blocks handed out on demand, like the pages of a computer's memory. Far less is wasted, so many more conversations fit on the same hardware.
And conversations that start with the same text can even share those blocks.
3:24Separating prefill from decode
Remember the two phases: prefill, which is compute-heavy, and decode, which is memory-bound. On a busy server they get in each other's way. When a new customer's long prompt arrives, its big prefill can briefly hog the hardware, and everyone currently receiving a streamed reply sees it stutter. Two fixes are common. Chunked prefill splits a long prompt into pieces and interleaves them with everyone else's decoding steps. And at large scale, some systems separate the phases entirely: one pool of machines does prefill, another does decoding, and the cache is handed over in between, like a restaurant with separate prep and plating kitchens.
4:10Prompt (prefix) caching
Every one of Brightcart's prompts begins with exactly the same text: about six hundred tokens of instructions and tool descriptions. Without caching, the server re-reads that identical text for every single request. Prefix caching computes the cache for that shared beginning once, stores it, and reuses it for every request that starts the same way. Only the new parts, the retrieved policies, the conversation and the question, need processing. The first word appears sooner, and many providers also charge less for cached input tokens.
This is why we said in episode sixty-one: put stable content first, and changing content last. Change one word near the start of the prompt, and the cache can no longer be reused. Keep in mind that details like these change fast. They were correct when this video was published, so treat them as a snapshot, not a permanent fact.
5:09Response caching: exact and semantic
We can also cache whole answers. An exact cache returns a stored reply when the same question arrives again, perfect for "what are your opening hours?". A semantic cache goes further: it also returns stored replies for similar questions, found with embeddings, like "when are you open?". If, say, thirty percent of requests were answered from the cache, that would be fifteen thousand requests a month with no generation at all. But response caching needs care. Never serve one customer's personal, order-specific answer to someone else.
Clear the cache whenever a policy changes. And beware near-misses: "can I return a gift?" and "can I return a gift card?" look similar, but may have different answers. Use a strict similarity threshold, and test it on pairs exactly like that.
6:05Parallelism: splitting a model across chips
When one chip isn't enough, work is split across many, in four main ways. Replicas: full copies of the model on several machines, with requests spread between them, which is simple, if the model fits on one machine. Tensor parallelism splits each weight matrix across several chips, so they compute each layer together, which needs very fast connections between them. Pipeline parallelism puts different layers on different chips, like an assembly line. And expert parallelism places a mixture-of-experts model's experts on different chips, routing each token to the right one.
Around all this sits operations: queues that admit requests at a sustainable rate, autoscaling that adds capacity for the lunchtime peak, rate limits per user, which also defend against abuse, and graceful fallbacks, like switching to a smaller model under extreme load.
7:06Try it yourself: batching in the ideal case
With one customer, our illustrative GPU could produce at most about a hundred and forty-three tokens a second. In the ideal case, one read of the weights can serve a whole batch. With eight customers, what's the total? Pause.
Up to about eleven hundred tokens a second, while each customer still sees roughly the same speed. Remember that the maths units were idle more than ninety-nine percent of the time; batching puts them to work. In reality, reading each customer's KV cache and the extra arithmetic eventually limit the gain, but the improvement is still dramatic.
7:52Try it yourself: the cost of reserving memory
A simple server reserves KV-cache memory for the maximum context, eight thousand one hundred and ninety-two tokens, for every request. But Brightcart's requests use about three thousand seven hundred on average. What share of the reserved memory sits unused? Pause.
About fifty-five percent. More than half of the GPU's precious memory is wasted. Paged management allocates the cache in small blocks, only as each conversation actually grows, so the same GPU can serve many more customers at once.
8:32Pause & Predict: how busy should servers be?
Should servers run as close to one hundred percent busy as possible? Pause and think about queues at a supermarket. A simple queueing model says waiting time grows with busy divided by one minus busy. At fifty percent busy, call the wait one unit. At eighty percent, it's four times longer. At ninety percent, nine times. Near a hundred percent, queues explode. Running hardware flat out looks efficient on a spreadsheet and feels terrible to customers, so Brightcart plans for headroom.
9:11Prefix caching, in numbers
Prefix caching in numbers: about six hundred of the three thousand four hundred prompt tokens are identical on every request, the system instructions and tool definitions. That's nearly eighteen percent of every prefill that can be reused instead of recomputed, thirty million tokens a month. And the more stable content you put at the start, like examples, long tool lists or a fixed policy section, the bigger the saving. That's why prompt layout and serving efficiency are connected.
9:45When response caching goes wrong
Response caching can go wrong. A semantic cache has stored the answer to "Can I return a lamp?": yes, within thirty days. Then someone asks "Can I return a lamp I bought two months ago?". It looks very similar, so the cache returns "yes", which is wrong. The rules: cache only general, non-personal questions, use a strict similarity threshold, never cache answers that depend on a specific order, date or account, and clear the cache whenever a policy changes.
10:17Priority lanes for live chat and batch jobs
Not every request is equally urgent. Brightcart runs three lanes into the same model servers. Live chat gets top priority and strict latency targets. Agent drafts come next. Batch jobs, like catalogue tagging and weekly digests, come last, and can pause during the lunchtime peak, or run overnight, or through a provider's discounted batch service. Rate limits stop any single runaway job from starving the customers.
10:49Splitting a model across chips
When a model is too big for one chip, it has to be split. Tensor parallelism splits each layer's large matrices across several chips that work on the same token together, which needs very fast connections. Pipeline parallelism places different layers on different chips, like an assembly line. And when the model fits on one chip, the simplest approach is replicas: complete copies, each serving different customers. Brightcart's seven-billion-parameter model fits on one card, so it simply runs replicas.
11:25Brightcart's serving stack, assembled
Here's Brightcart's serving stack, assembled. Requests enter through a gateway that checks identity, applies rate limits and assigns a priority lane. General questions may be answered from the response cache. Everything else goes through retrieval and prompt building, then to model servers running continuous batching, paged KV-cache memory, prefix caching and a quantised model. Replies stream straight back to the customer. And every layer is monitored, which is where the next module begins.
11:59Try it yourself: the cold start
During the lunchtime peak, the autoscaler adds a new server. Before it can serve anyone, it has to load fourteen gigabytes of weights. At two gigabytes a second, how long is that? And what do customers feel if scaling only starts once queues are already long? Pause.
Seven seconds just to load the weights, before the software starts and warms up. Customers wait through all of it, at the worst possible moment. So Brightcart scales up ahead of the predictable lunchtime peak, keeps a warm spare server ready, and benefits from quantised weights, which load four times faster.
12:43Myth vs Fact
Myth: serving twice as many users means buying twice as many graphics cards. Fact: continuous batching, paged cache memory, prefix and response caching, and smart scheduling can multiply how many customers each chip serves. Measure goodput under realistic load before buying more hardware.
13:05Recap
Let's recap. Batching lets one read of the weights serve many customers, raising throughput dramatically. Continuous batching lets requests join and leave at every step. Paged cache memory fits far more conversations on the same hardware. Chunked or separate prefill stops new prompts from stalling others. Prefix caching avoids re-reading shared instructions, and response caching skips generation entirely, used carefully. And parallelism, plus queues, autoscaling and rate limits, handles the biggest peaks. One sentence to remember: share every weight read, never re-read the same prompt, and keep the bus moving.
13:48Next: the full AI architecture
Mission complete. At lunchtime, Brightcart's assistant now batches continuously, manages cache memory in pages, reuses its shared instructions, answers common questions from a careful cache, and scales up automatically, keeping the first word under a second for nearly everyone. That completes Module Twenty-One. And now, the final module of the entire course: assembling everything, retrieval, agents, guardrails, routing, caching and monitoring, into one production architecture, and closing the loop with user feedback.
See you on the map.