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 2 of 15

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.

Chaand Sheikh

·27 November 2026AI System Design

What you will learn

  • Explain back pressure and why a bigger buffer only makes the wait longer
  • Bound a queue and reply 429 with Retry-After when it is full
  • Separate chat and bulk work into lanes, and say who pays for it
  • Count tokens in flight and cancel work when the caller leaves

Before you start

  • Latency Math: p50, p95, p99
  • LLM Tokens, Context Windows and Cost

Back pressure means a slow part of your system tells the part before it to slow down, instead of piling up work that it can never finish. It matters a lot for LLM traffic, because one request can cost far more than another. And it's a favourite interview question.

The load and servers in this lesson are simulated. No provider was called.

Four moves

There are four moves, and that's also the shape of your answer:

  1. Bound the queue, so it can't grow forever.
  2. Give chat its own lane.
  3. Count tokens, not requests.
  4. Stop working when the caller leaves.

A bulk job buries the chat

A customer bulk uploads 50,000 documents at once, and chat latency triples. Design back pressure.

Latency is just how long you wait. Let's watch a smaller flood in a small simulation: 60 chat questions and 200 bulk jobs share one queue. The queue climbs to 199 requests waiting, and chat pays for it. The middle chat answer takes 80.2 seconds. Nothing was rejected, and every job finished. The server didn't break. It just got buried.

Think of a conveyor belt in a factory. At the end, a packer packs boxes at a steady speed: that's your GPU server. The belt is short, so it holds only a few boxes: that's the bounded queue. When the packer is full, the belt stops and the loader waits: that's the back pressure signal. The belt never grows. The loader slows down instead.

Move 1: bound it, and say no

The weak answer is a bigger buffer. It only makes the wait longer, until memory runs out. So give the queue a fixed size. When it's full, reply with a 429 and Retry-After, which tells the sender when to come back.

In the same simulated flood, the line stops at 20, not 199, and 178 bulk jobs get told to try again in 10 seconds. Be honest about this: those jobs didn't run, and the simulation doesn't send them back. We didn't create any capacity. We just said no early, and that beats saying yes and failing late.

Move 2: give chat its own lane

Chat gets one lane and bulk work gets another, so a chat question never stands behind a bulk job. When things get tight, bulk is the one that waits.

One queue against bound plus lanes One shared queue waiting at most: 199 middle chat answer: 80.2 s bulk jobs done: 200 rejected: 0 Bound + lanes waiting at most: 20 middle chat answer: 0.35 s bulk jobs done: 22 178 bulk: 429, retry in 10 s Simulated: 60 chat questions, 200 bulk jobs
Chat got fast, and bulk paid for it. Somebody always pays.

With the bound and the lanes together, the middle chat answer drops from 80.2 seconds to 0.35. We switched both on at once, so we can't split that credit. And bulk pays: 22 bulk jobs finished, not 200. Somebody always pays, so say who. The simulator's summary (simulated):

one queue
  chat_done 60
  chat_p50  80.2
  chat_p95  92.75
  bulk_done 200
  rejected  {}
  max_depth 199
lanes + bound
  chat_done 60
  chat_p50  0.35
  chat_p95  0.35
  bulk_done 22
  rejected  {'bulk': 178}
  retry_after 10.0
  max_depth 20

If p50 and p95 are new to you, see Latency Math: p50, p95, p99.

Move 3: count tokens, not requests

So far we've counted requests, but requests aren't equal. On our belt, one giant box takes far longer than a small one. A long request keeps the GPU busy far longer than a short one too. So keep a running count of tokens in flight, meaning the text the GPU is busy with right now. If the next request doesn't fit in the room that's left, it waits at the gate, and chat gets the room first. The request count can look fine while the GPU is full, and that's why you watch tokens. (This move is the idea only; the lesson has no numbers for it.)

Move 4: stop when the caller leaves

People forget this one. In a small simulation, half the callers hang up early, and the GPU keeps writing answers nobody will read.

Cancel when the caller leaves Last job finishes (simulated seconds) no cancel cancel 14.2 s 7.7 s 21,000 wasted tokens 0 wasted tokens 16 jobs done both times
Every token you spend should have someone waiting for it.

That wastes 21,000 tokens, and the last job finishes at 14.2 seconds. So when a caller leaves, cancel and give the tokens back. The waste falls to zero, the last job finishes at 7.7 seconds, and the same 16 jobs get done.

Follow-ups and a simple rubric

  • Bounded queue, or reject straight away? Usually a small bound to absorb short bursts, then reject.
  • How do you tell the uploader to slow down? A 429 with Retry-After says when to come back.
  • How do you prove it works? Watch queue depth, rejection rate and time in queue. Then flood it on purpose, and check that chat holds.
LevelSounds like
WeakA bigger buffer and more servers; never says what happens when it's full
GoodA bound, lanes and a 429
StrongAlso counts tokens, cancels when the caller leaves, and says who pays and how you'd measure it

The rubric is a guide for practice, not a guaranteed result. Back pressure works with the other side of the call: well-behaved retries (Retries and Backoff) and enough replicas (Sizing and Autoscaling an Inference Service). How work is spread across those replicas is in Load Balancing LLM Traffic.

Recap

MoveWhat to remember
BoundFixed size, 429 + Retry-After when full. Saying no early creates no capacity
LanesSimulated: middle chat answer 80.2 s to 0.35 s; bulk done 200 to 22
TokensCount tokens in flight, not requests
CancelSimulated: 21,000 wasted tokens to 0, last job 14.2 s to 7.7 s

Try it yourself

Picture those 178 rejected bulk jobs coming back after 10 seconds. What would you watch to see whether chat holds?

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 2 of 15

Previous
Fallback Models for an LLM App: A Chain That Checks Region and Fit, Flags Degraded Answers and Gets Rehearsed
Next post
Load Balancing LLM Traffic: Count the Work, Weigh the Prefix Cache, Check Real Health, Drain Before Deploys

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.

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.

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.

On this page

  • Four moves
  • A bulk job buries the chat
  • Move 1: bound it, and say no
  • Move 2: give chat its own lane
  • Move 3: count tokens, not requests
  • Move 4: stop when the caller leaves
  • Follow-ups and 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.