Single logo
  • Courses
  • Blog
  • About
Join free on SkoolJoin free on Skool

Learning path · 15 steps

AI System Design: Reliable, Fast and Affordable LLM Apps
  1. 1
    Fallback Models for an LLM App: A Chain That Checks Region and Fit, Flags Degraded Answers and Gets Rehearsed
  2. 2
    Back Pressure for LLM Traffic: Bound the Queue, Give Chat Its Own Lane, Count Tokens, Cancel When the Caller Leaves
  3. 3
    Load Balancing LLM Traffic: Count the Work, Weigh the Prefix Cache, Check Real Health, Drain Before Deploys
  4. 4
    A Message Queue for Document Ingestion: At Least Once, Leases, an Idempotent Consumer and a Dead Letter Queue
  5. 5
    Caching for AI Apps: Four Layers, What Goes in Each Key, and How a Delete Travels
  6. 6
    Semantic Caching: Why a Similarity Threshold Can't Stop Confident Wrong Answers
  7. 7
    LLM Model Routing: Rules, a Classifier or a Cascade, Judged on Cost per Win and Every Topic
  8. 8
    Observability and Tracing for LLM Apps: A Span per Stage, Redaction First, Bad Traces Become Tests
  9. 9
    Cutting p95 and Cost in Half for an LLM App: Read the Bill, Match the Lever, Guard Success
  10. 10
    Guardrails for an LLM Agent: Check What Comes In, What It Wants to Do, and What Goes Out
  11. 11
    Embedding Migration With Zero Downtime: Two Indexes, a Dual-Write Backfill, a Shadow Check and a Flag
  12. 12
    Design a Multi-Tenant RAG Assistant, Part 1: Requirements, Rough Numbers and a Contract
  13. 13
    Design a Multi-Tenant RAG Assistant, Part 2: Tenant Isolation, a Scoped Cache and Walking an Outage
  14. 14
    A 500 MB PDF Takes 50 s to Answer, Get It to 2 s: Measure First, Then Promise Per Path
  15. 15
    A 500 MB PDF From 50 s to 2 s, the Fast Path: Queue, Status, Streaming and an Acceptance Test That Fails
  1. Blog
  2. /
  3. AI Engineering
  4. /
  5. AI System Design

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.

Chaand Sheikh

·27 November 2026AI System Design

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

  1. Don't treat fifty seconds as one number. Split it by stage.
  2. Separate the part that runs once from the part that runs on every question.
  3. Give each part its own promise, with a named clock.
  4. 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
One opaque bar becomes five stages plus the answer upload 6 extract 8 OCR 14 embed 16 index 2 4 Cold path: 46 s, once per document Warm The model sits inside the red 4 seconds. Simulated seconds, for illustration.
Make the warm part take no time at all, and a fresh upload still takes 46 seconds.

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

PathRunsHonest promise
ColdOnce per documentProgress: you can't promise two seconds here
WarmEvery question, on an already indexed documentSpeed: 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.
Two clocks on the warm path 1.1 s spare 0 s first word 0.9 s target 2 s last word 4.0 s Simulated seconds, for illustration
Two clocks, two numbers. Always say which one you mean.

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:

  1. Which clock? The first word.
  2. Which share of people? 95 out of 100 (the p95; see Latency Math).
  3. Which documents? The ones already indexed.
  4. 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

  1. Dataset: a fixed set of test documents, with some big scanned ones in it.
  2. Baseline: today's time for each stage, before anybody changes anything.
  3. 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.
  4. Failure slices: scanned pages, huge tables, many people at once. Report them separately; an average hides them.
  5. 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

LevelWhat the answer has
WeakPicks a faster model and promises two seconds
SolidSplits by stage, separates cold from warm, names the clock
StrongAll 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

IdeaWhat to remember
Split the barSimulated: 46 s of the 50 s was the cold part, so a faster model couldn't fix it
Two pathsCold promises progress, warm promises speed
BudgetFirst word 0.9 s against 2 s: 1.1 s spare; last word 4.0 s
TargetClock, 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.

Tried the exercise? Share your answer or ask a question.

The StudyEasy AI Community is free to join, with the lesson files, notebooks and code.

Join free on Skool

Keep going in the learning path AI System Design: Reliable, Fast and Affordable LLM Apps · step 14 of 15

Previous
Design a Multi-Tenant RAG Assistant, Part 2: Tenant Isolation, a Scoped Cache and Walking an Outage
Next post
A 500 MB PDF From 50 s to 2 s, the Fast Path: Queue, Status, Streaming and an Acceptance Test That Fails

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.

On this page

  • The thirty-second answer
  • What's inside fifty seconds
  • Two paths, two promises
  • The budget, written down
  • An honest target
  • The measuring plan
  • Follow-ups
  • A simple rubric
  • Recap
  • Try it yourself
Community · Free to join
Single logo

StudyEasy AI Community

Hosted onSkool

Learn AI engineering, share what you build, and connect with other learners.

  • Free resources: lesson files, notebooks and code

  • Ask questions and join engineering discussions

  • Meet real people learning and building with AI

Join free on Skool

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)

Single logo

Empowering Education, One Course at a Time

About
About usContact usFAQs
Legal
Terms of ServicePrivacy Policy

© 2026 StudyEasy Organization. All rights reserved.