Learning path: AI System Design: Reliable, Fast and Affordable LLM Apps · Step 14 of 15
A 500 MB PDF Takes 50 s to Answer, Get It to 2 s: Measure First, Then Promise Per Path
Interview question: a 500 MB PDF takes 50 seconds to answer, get it to 2. In a small simulation the 50 s splits into 46 s of one-time prep and 4 s per question, so a faster model can't fix it. Two paths, two promises, a first-word budget with 1.1 s spare, and a target that names its load.
What you will learn
- Split one slow number into stages before choosing any fix
- Separate the cold path (once per document) from the warm path (every question)
- Write a latency budget with a named clock: first word or last word
- State an honest target with its clock, share of people, documents and load, plus a measuring plan
Before you start
- Latency Math: p50, p95, p99
- The RAG Pipeline Explained
A customer uploads a huge PDF, asks one question, and stares at the screen for fifty seconds. The interviewer says: a 500 MB PDF takes 50 seconds to answer. Get it to two.
Those three numbers are part of the question. Nobody has promised them. The timings below come from a small simulation where the seconds were chosen for illustration and no real PDF was read. And in this part we won't fix a thing. We only measure, because that's what a strong answer does first. The fixes come in Part 2: the fast path.
The thirty-second answer
- Don't treat fifty seconds as one number. Split it by stage.
- Separate the part that runs once from the part that runs on every question.
- Give each part its own promise, with a named clock.
- Before calling anything fixed, write down how you'll measure it.
Think of a restaurant kitchen. Early in the day the cooks chop, boil stock and make sauces. That takes long, and it happens once. Later an order comes in, and plating takes a few minutes, because the prep is done. If you order just as the kitchen opens, you wait a long time and blame the waiter. A faster waiter saves you almost nothing, because you were waiting on the prep. Prep and plating are two jobs, and you time them separately.
What's inside fifty seconds
Many teams start with one bar: fifty seconds, upload to answer. It can't tell you where the time went. So time each stage:
1. One span or many (simulated)
upload 6.0 s
extract 8.0 s
ocr 14.0 s
embed 16.0 s
index 2.0 s
cold 46.0 s + warm 4.0 s = 50.0 s
Here's the trap. A weak candidate hears "slow answer" and says "use a faster model". But the model sits inside the 4 seconds. Measuring first just saved us from fixing the wrong thing.
Two paths, two promises
| Path | Runs | Honest promise |
|---|---|---|
| Cold | Once per document | Progress: you can't promise two seconds here |
| Warm | Every question, on an already indexed document | Speed: this is where a two-second target makes sense |
The line to say in the interview: we aren't turning fifty seconds into two. We're giving people a two-second experience on the part that can have one.
The budget, written down
On the warm path, the first question is which clock.
- First word. If words go out as they're written, the simulation has the first word ready at 0.9 s. Against a target of 2 s, that leaves 1.1 s spare. Anything new on this path, like one more check, pays for its time out of that 1.1 s.
- Last word. It lands at 4.0 s. So two seconds for the whole answer isn't met, and we say so.
An honest target
Harder version: a customer says "I need cited answers in two seconds at peak traffic." How do you agree a target without overpromising? Write one sentence with four parts:
- Which clock? The first word.
- Which share of people? 95 out of 100 (the p95; see Latency Math).
- Which documents? The ones already indexed.
- At what load? People forget this one.
In the simulation, at 1 request a second, p95 to the first word is 0.90 s. At 1.8 requests a second it's about 4 s. Same system, and now it misses the target.
4. Acceptance under load (SLO p95 TTFT 2 s)
1.0 req/s none p95 0.90 s rejected 0.0% short 0.0% PASS
1.8 req/s none p95 4.06 s rejected 0.0% short 0.0% FAIL
So you don't argue about it. You load test, show those numbers, and the customer chooses between paying for more capacity and agreeing what happens above that load. A target is something you test against. It isn't a guarantee, and you should say that out loud.
The measuring plan
- Dataset: a fixed set of test documents, with some big scanned ones in it.
- Baseline: today's time for each stage, before anybody changes anything.
- Metrics: p95 per stage, time to first word, time to last word, and whether the answer is still correct with its citations. A quick wrong answer is no win.
- Failure slices: scanned pages, huge tables, many people at once. Report them separately; an average hides them.
- Thresholds, labelled illustrative until you've measured them on your own system.
Only then do you start fixing, and now you can prove the fix helped.
Follow-ups
- Can you promise two seconds on a fresh upload? No. The cold path hasn't finished, so you show progress, and the target covers indexed documents only.
- Why p95 and not the average? Because an average hides the unlucky people.
- The customer insists on the whole answer in two seconds. Show the measured gap, offer the first-word target, and say what the other one would take.
A simple rubric
| Level | What the answer has |
|---|---|
| Weak | Picks a faster model and promises two seconds |
| Solid | Splits by stage, separates cold from warm, names the clock |
| Strong | All of that, plus the load inside the target, a measuring plan, and every number called an assumption until measured |
Suggested levels only, not any company's official sheet.
Recap
| Idea | What to remember |
|---|---|
| Split the bar | Simulated: 46 s of the 50 s was the cold part, so a faster model couldn't fix it |
| Two paths | Cold promises progress, warm promises speed |
| Budget | First word 0.9 s against 2 s: 1.1 s spare; last word 4.0 s |
| Target | Clock, share of people, documents and load |
Try it yourself
Pick a slow feature you use. Say which part runs once, which part runs every time, and what you'd promise for each.
Related course on Udemy
Machine Learning Engineer: From First Model to ML Engineer
Learn machine learning in Python, then ship it: data analysis, regression, classification, tuning, deployment and MLOps.View on Udemy ↗: Machine Learning Engineer: From First Model to ML Engineer (paid course, opens in a new tab)Related posts
Fallback Models for an LLM App: A Chain That Checks Region and Fit, Flags Degraded Answers and Gets Rehearsed
When the main model goes down, the backup has to be allowed to take the data, able to read the whole request and tested before the bad day. A simulated four-model chain for an EU customer: a 6,000-token request lands on mid-eu, flagged degraded; a 10,000-token request is served by nobody, on purpose.
Back Pressure for LLM Traffic: Bound the Queue, Give Chat Its Own Lane, Count Tokens, Cancel When the Caller Leaves
A bulk upload buries the chat. In a small simulation, one shared queue grows to 199 waiting and the middle chat answer takes 80.2 s. A bound plus a chat lane brings it to 0.35 s while 178 bulk jobs are told to retry in 10 s, and cancelling abandoned calls saves 21,000 wasted tokens.
Load Balancing LLM Traffic: Count the Work, Weigh the Prefix Cache, Check Real Health, Drain Before Deploys
Six GPU replicas, two at 95% and four at 30%: round robin counts requests, and requests aren't equal. In a small simulation, least outstanding requests cuts p95 from 6.52 s to 3.05 s, prefix affinity lifts cache hits to 95% but pushes p95 to 11.45 s, a real health check takes errors from 48 to 2, and draining cuts 0 answers instead of 4.
A Message Queue for Document Ingestion: At Least Once, Leases, an Idempotent Consumer and a Dead Letter Queue
A queue doesn't lose a document, but it can hand one out twice. In a small simulation, a worker crash makes document two go from 3 to 6 chunks and the index holds 11 when the documents hold 8. An idempotent consumer brings it back to 8 with the same two deliveries, and a limit of three tries moves a poison file to a dead letter queue.