One Request Through Every Pattern: a Map of 25 AI System Design Patterns, Stop by Stop
Follow one support question through five stops (front door, gateway, retrieval, model, way back) and meet 17 patterns on the way, then four more on the slower PDF and agent routes and four in the data layer. The interview move: draw the map, walk one failure, name the box that catches it.
What you will learn
- Place 25 AI system design patterns on one request route: front door, gateway, retrieval, model and the way back
- Tell the quick question route apart from the slower routes taken by a PDF upload and an agent job
- Name the data layer every route depends on
- Answer a design question by drawing the map, walking one failure and naming the box that catches it
Before you start
- The Answer Framework for interview questions
- The RAG Pipeline in One Picture
There are a lot of patterns in AI system design: rate limits, caches, breakers, fallbacks, queues, indexes. Learned as a list, they blur together. This article draws one map instead. We follow one support question from start to finish, then a PDF and an agent job on their own routes, and meet 25 patterns on the way, one line each. The point is to see where each one sits.
Follow it depot by depot
Think of a parcel you ordered online. It moves along, and you can track it at every depot. Each depot has one job: it sorts, or it loads, or it delivers. No depot tries to do everything. A request travels the same way, and each stop can catch one kind of failure.
Stop 1: the front door, who gets in
The question comes from one tenant, one small business on a shared platform. A load balancer sends it to a healthy server. Rate limiting decides how many requests each tenant gets, so one busy tenant can't take everything. Token rate limits count tokens, not only requests, because one long request can cost a hundred short ones. And token budgets cap what one task may spend. Most bad traffic can stop right here, before it costs anything.
Stop 2: the gateway, do we even need the model?
The LLM gateway is one service every model call passes through, so keys, quotas and logs sit in one place. Caching means the same question doesn't get a second bill. Semantic caching reuses answers for similar questions, and needs care, because two questions can look similar and mean the opposite. Guardrails check what's coming in. A cache hit ends the journey early, and cheaply.
Stop 3: retrieval, find the evidence
Tenant isolation comes first: filter down to this customer's data only. Hybrid search looks at keywords and meaning together, so an exact error code is found as well as the general topic. A vector index finds the close chunks quickly without scanning everything. If the filter comes after the search, it's already too late: the wrong tenant's data has been read.
Stop 4: the model, the expensive stop
This is the most expensive stop, and the one most likely to fail. Model routing picks a small model when that's enough and keeps the large one for hard questions. Retries with backoff only when they can help: a timeout is worth retrying, a bad request is not. A circuit breaker (same article) stops calls to a failing provider, so you don't keep waiting on something that's down. Fallback models give a tested second choice. Most outages are caught at this one stop.
Stop 5: the way back
Streaming responses send the first words early, so the wait feels shorter, even though the full answer takes the same time. Agent tracing keeps one record of every step, so later you can ask "what happened?" and get an answer. Count them up: 17 patterns on one route.
Not everything is a quick question
A big PDF upload and a refund agent take their own, slower routes:
- A message queue holds the upload jobs, and they survive a crash.
- Back pressure means a full queue pushes back on whoever is sending, instead of falling over.
- Durable execution lets an agent resume where it stopped, instead of starting again and repeating a refund.
- Sandbox execution keeps generated code inside its box.
Where the data actually sits
Underneath every route, the data is stored somewhere. A database index turns a full scan into a quick lookup. Replication keeps copies for reading and failover. Sharding splits the data when one node is full. And embedding migration moves you to a new embedding model safely, because vectors from two models can't be mixed. That's 25.
Draw the map, walk one failure
Here's the interview move, and it works for almost any design question. Draw this map, then walk one failure along it, and name the box that catches it. That turns a list of patterns into a design.
| Failure | Where it's caught |
|---|---|
| The provider goes down | Model stop: the breaker opens, retries stop, the fallback answers |
| A tenant sees another tenant's data | Retrieval and gateway: filter first, and put the tenant in every cache key |
| A huge upload arrives | Slow route: the queue has a limit, and chat keeps its own lane |
For the shape of the answer itself (30-second answer, mechanism, trade-off, metric, failure test), see The Answer Framework, and for starting from the symptom, From Symptom to Pattern.
Recap
| Where | Patterns |
|---|---|
| Front door | Load balancer, rate limiting, token rate limits, token budgets |
| Gateway | LLM gateway, caching, semantic caching, guardrails |
| Retrieval | Tenant isolation, hybrid search, vector index |
| Model | Model routing, retries, circuit breaker, fallback models |
| Way back | Streaming, agent tracing |
| Slow routes | Message queue, back pressure, durable execution, sandbox execution |
| Data layer | Database index, replication, sharding, embedding migration |
A pattern only makes sense where it sits.
Try it yourself
Pick one more failure: the vector index is rebuilt with a new embedding model and half the answers stop citing the right page. Walk it along the map and name the box that should have caught it.
Related course on Udemy
The Python Architect Masterclass: Full Stack to AI Engineer
Python, Django, FastAPI, React, Docker, AWS, LLMs, RAG, agents and MCP, from first steps to AI engineer.View on Udemy ↗: The Python Architect Masterclass: Full Stack to AI 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.
