AI System Design: Reliable, Fast and Affordable LLM Apps
Who it is for
What you will achieve
Prerequisites
Curriculum
- Step 1: 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.
- Step 2: 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.
- Step 3: 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.
- Step 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.
- Step 5: Caching for AI Apps: Four Layers, What Goes in Each Key, and How a Delete Travels
A support bot's cache can hit 97% of requests and still answer only 52% correctly. Four cache layers, the key each one needs, how a document delete has to travel through all of them, and a 200-request simulation that puts hit rate next to correct answers.
- Step 6: Semantic Caching: Why a Similarity Threshold Can't Stop Confident Wrong Answers
A semantic cache answers a question that sounds like an old one with the old answer. On 32 synthetic questions, "monthly plans" matched "annual plans" at 0.91, right and wrong scores overlapped, and the only threshold with zero false hits answered nothing on fresh questions.
- Step 7: LLM Model Routing: Rules, a Classifier or a Cascade, Judged on Cost per Win and Every Topic
Send easy tickets to a small model and the bill drops from 21.39 to 4.31 units per solved ticket, while refund disputes fall from 0.93 to 0.64. A 1,200-ticket simulation compares rules, a classifier and a cascade on cost per win, the confidence dial, and a per-topic gate.
- Step 8: Observability and Tracing for LLM Apps: A Span per Stage, Redaction First, Bad Traces Become Tests
"The agent booked the wrong meeting room yesterday. Explain why." A span for every stage shows the bug sat in retrieval, a simulated request shows a 900 ms tool span hiding inside 2,462 ms, redaction runs before storage, tail sampling keeps the 6 slow requests in 200, and an incident trace becomes a test that takes the eval set from 9/9 to 9/10.
- Step 9: Cutting p95 and Cost in Half for an LLM App: Read the Bill, Match the Lever, Guard Success
Asked to halve p95 and cost without hurting success, read the bill first. In a 200-request simulation, streaming the answer was 84% of the slowest request, a cheap router dropped success to 95.5%, and the careful router plus a cache cut cost to 31.6% while p95 fell only about 8%.
- Step 10: Guardrails for an LLM Agent: Check What Comes In, What It Wants to Do, and What Goes Out
An agent that reads customer emails and can refund up to $200. In a small simulation, a phrase filter still lets 6 of 8 written attacks do harm and blocks 2 honest users; plain checks outside the model take harm to 0 of 8, at a cost of 1 honest request failed and 2 held.
- Step 11: Embedding Migration With Zero Downtime: Two Indexes, a Dual-Write Backfill, a Shadow Check and a Flag
300 million chunks on an old embedding model, and a new one with a different dimension. Mixing models in one index drops the right document on top from 0.83 to 0.46 with no error (simulated). Size the job, backfill a second index while writes go to both, shadow-compare 18 of 23 agreeing, and flip a flag that a failed id check can refuse.
- Step 12: Design a Multi-Tenant RAG Assistant, Part 1: Requirements, Rough Numbers and a Contract
A support assistant for 500 small businesses and 3 banks. Requirements first, then the arithmetic in the open (38,000 tickets a day, 528,000 tokens a minute at an assumed peak), a first diagram where the tenant travels with every request, and a contract written before the test set is opened.
- Step 13: Design a Multi-Tenant RAG Assistant, Part 2: Tenant Isolation, a Scoped Cache and Walking an Outage
A shared cache gave one company's answer to another. In a small synthetic example with two tenants and four documents: filter before ranking, put tenant, user and version in the cache key, write negative tests (with the tenant check removed, 4 of 6 fail), pick pool or silo per segment, and refuse when scope is unavailable.
- Step 14: 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.
- Step 15: A 500 MB PDF From 50 s to 2 s, the Fast Path: Queue, Status, Streaming and an Acceptance Test That Fails
The fast path for a slow PDF assistant, in a small simulation: 20 chunks on a queue finish at 38.3 s with one worker and 7.9 s with eight, a status shows progress, streaming brings the first word to 0.9 s, and an acceptance test at 1.8 and 2.5 requests a second fails every rescue we tried.