Learning path: AI System Design: Reliable, Fast and Affordable LLM Apps · Step 12 of 15
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.
What you will learn
- Explain the two failures of a shared platform: one tenant seeing another's answer, and one tenant using up everyone's limit
- Ask for requirements and promises (SLOs) before drawing any boxes
- Do a capacity estimate out loud, from tickets a day to tokens a minute at peak
- Write a release contract: dataset, baseline and a bar, set before you see results
Before you start
- The ML System Design Framework
- The RAG Pipeline Explained
Here's a system design question you can use again and again: design a support assistant that answers from each company's own documents, for 500 small businesses and 3 banks. The hard part isn't the model. The hard part is the sharing. So before any boxes, we ask who's using it and what we've promised them. Then we do the arithmetic in the open, and write down what must be true before it ships.
Every input here is assumed, for illustration. The few results come from small simulations with synthetic tickets, and each one says so.
One building, many flats
Each customer on a shared system is called a tenant. Think of a big apartment building:
- The flats are your tenants. Each family lives its own life.
- The plumbing is the shared platform. That's why this is cheap to run. But if one family runs every tap at once, the others lose their pressure.
- The lock on each door is isolation, so nobody walks into the wrong flat.
Sharing saves money, and it creates two failures you should name in the first minute.
A 429 is the provider's "too many requests, slow down" reply. A token is a small piece of text, and providers limit how many you use each minute.
In a small simulation with assumed traffic and an assumed limit, one bad minute looks like this: a bank sends 300 requests and fifty small shops send 4 each. The shared limit fills up, and 76 of the shops' 200 requests get turned away. That's why the sharing goes in your requirements.
The order of the answer
Say it in this order, out loud: requirements (who uses it, what have we promised), numbers (roughly how big is it), first diagram (one request moving through), and the contract (how we decide whether it ships). It's the same shape as the ML system design framework, applied to a shared AI system.
Requirements: who, how much, what promise
All inputs assumed, for illustration:
| Who | Assumed volume | Tickets a day |
|---|---|---|
| 500 small businesses | 40 tickets a day each | 20,000 |
| 3 banks | 6,000 tickets a day each | 18,000 |
So three customers send 47.4% of all tickets. Then the promises. An SLO, a service level objective, is simply a target we commit to:
- 95% of answers within 4 seconds (that's the p95; see Latency Math).
- 99.5% availability.
- Zero cross-tenant leaks. That one is just zero.
Every number here is an assumption. They're targets until something measures them, and you should say that.
A rough estimate, out loud
For illustration, with assumed inputs: tickets land in 600 busy minutes, the peak minute is 4 times the average, and the provider limit is 600,000 tokens a minute.
Each ticket costs tokens, a bit more for a bank, and at the peak that comes to 528,000 tokens a minute. Against an assumed 600,000 limit, 72,000 are spare. That's not much room.
The first diagram, with the tenant travelling along
Follow one request: gateway → limiter → cache → retrieval → model.
- The gateway works out who the tenant is. From here on, the request carries that tenant with it.
- The limiter checks this tenant's share before anything is spent.
- Then the cache, retrieval over this tenant's documents, and the model writes the answer.
Here's what the limiter costs, in the same simulated bad minute:
shared pool {'bank_ok': 157, 'bank_429': 143, 'small_ok': 124, 'small_429': 76, 'tokens_used': 600000}
20% per tenant {'bank_ok': 50, 'bank_429': 250, 'small_ok': 200, 'small_429': 0, 'tokens_used': 480000}
A cap of 20% per tenant takes the turned-away shop requests from 76 to 0. But the bank drops from 157 requests served to 50, and 120,000 tokens sit unused. Every shared box needs to know the tenant, and every fix costs something. Say who pays.
The cache needs the tenant too. In a stand-in simulation (no model call), a key that leaves the tenant out serves one company's "30 days after delivery" to another, with 1 model call. A key with the tenant gives the second company its own "14 days after purchase", with 2 model calls. Part 2 walks that leak in detail: Isolation, Cache and Failures.
The contract: dataset, baseline, bar
How do we know it's any good? We agree before we build.
- Dataset. In the small simulation: 8 documents, 6 tickets to work on, and 6 test tickets kept locked, all synthetic.
- Baseline, the simplest thing that could work: take the tenant's first document, no ranking. Right on 1 ticket in 6, 0.167. Filtering by tenant and ranking by shared words gets 5 in 6, 0.833.
- The bar, written in advance: at least 0.6 on test, a gain of at least 0.3, and zero leaks.
dev baseline {'hit_at_1': 0.167, 'leaks': 0}
dev retrieve {'hit_at_1': 0.833, 'leaks': 0}
test retrieve {'hit_at_1': 1.0, 'leaks': 0}
{'checks': {'quality': True, 'gain': True, 'leaks': True}, 'ship': True}
We open the test set once: 1.0, six out of six, zero leaks, so it ships. Read that honestly, though. One ticket shares no words with any document, so every score ties, and the first document just happened to be right. Six tickets is a small set, so don't quote that 1.0 to anybody.
After it ships
This part wasn't simulated, so there are no numbers, just the plan. Watch the same numbers per tenant, because an average can hide one customer having a bad week. Slice failures by tenant, topic and kind of question. Set alarms on the promises; any cross-tenant leak raises one straight away. Agree in advance how to roll back. And put bad answers back into the dataset.
Follow-ups
- Your estimate is off by a factor of two. What changes? The peak passes one million tokens a minute, over the limit we assumed. You'd need a bigger limit, or a queue for batch work (see Back Pressure).
- The customer wants fine-tuning first. Not before a baseline. Without one, you can't tell whether fine-tuning helped.
- Your test score is 1.0. Do you believe it? No. It's six tickets and one tie; I'd want a bigger locked set.
A simple rubric
| Level | What the answer has |
|---|---|
| Weak | Jumps to models and vector stores, with no numbers |
| Good | Requirements, an estimate, and the tenant running through the diagram |
| Strong | Also labels its assumptions, names what each fix costs, sets a baseline, and doubts its own best score |
The rubric is a judgement guide, not a measurement.
Recap
| Step | What to say |
|---|---|
| Requirements | Who the tenants are, and the promises: p95 4 s, 99.5%, zero leaks (assumed) |
| Numbers | 38,000 tickets a day to 528,000 tokens a minute at peak, every input labelled assumed |
| Diagram | The tenant travels with the request through every shared box |
| Contract | Dataset, baseline and bar, written before the results |
Try it yourself
Double the banks' traffic on paper, and say which promise breaks first.
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.