- Published on
One Template to Start (Almost) Any System Design Question
- Authors

- Name
- Syamil Yusof
Introduction
The first time I saw a system design question like "Design YouTube", my brain went blank. Where do I even start? Database first? Servers? Microservices?? 😵
Then I found a video by System Design School on YouTube and learned that most of these questions can start from the same simple picture. Once you know it, you don't start from zero anymore. You draw the picture, then you only talk about what makes this question different. In this post I'm gonna explain that picture the way I finally understood it: with a busy restaurant hehe.
NOTE
This post is written from my own understanding of the video, so some parts might be wrong or oversimplified. If you spot a mistake, let me know! For the full and correct version, watch the original video.
The whole idea in one sentence:
Writes go into a queue, workers do the actual work, and reads come from a cache.
Building It One Box at a Time
Let's start from the smallest thing that works, then add a box only when something breaks. Imagine we're opening a restaurant.
Step 0: one server, one database. A request comes in, the server reads or writes the database, and sends back a response. Like a tiny stall with one person doing everything. For a side project, this is totally fine.
Step 1: more servers + a load balancer. One machine can only take so many requests a second. So we run several copies of the server and put a load balancer in front, a box that spreads the requests across them. In the restaurant, that's the host at the door sending each customer to whichever waiter is free.
For this to work, the servers must be stateless: they don't remember anything about a user between requests. So any waiter can serve any customer, and if one waiter goes home, the host just sends the next customer to someone else.
Step 2: a cache. Now all those servers hammer the database, and most of what they ask is the same rows again and again. So we put a cache in front: an in-memory store that's way faster than the database. The server checks the cache first and only goes to the database when the answer isn't there. That's the "Today's specials" board. If 9 out of 10 reads hit the cache, the database only sees 1 in 10.
Step 3: read replicas. The database still takes the cache misses plus all the writes, and it's still one machine. So we make read replicas: the main database (the primary) takes the writes and copies them to a few replicas, and reads can go to those. Like photocopies of the order book for the front counter. The copy takes a moment, so a replica can be a little behind. For most apps, nobody notices.
Step 4: a queue and workers. This is the part the whole template is built around. Some writes are slow because they do real work, and sometimes a lot of them come at once. If the user waits for all that, the app feels slow, and a burst can knock the servers over. So we put a message queue in between:
- The server drops the write in the queue and answers straight away: "Got it."
- Workers pull jobs off the queue, do the work, save the result to the database and update the cache.
- When a burst comes, the queue just gets longer for a while, and the workers catch up at their own pace.
In the restaurant: the waiter pins the ticket on the rail and goes back to the customer. The cooks clear the tickets one by one. 50 orders at once? The rail gets longer, nobody's order is forgotten.
Put all the boxes together and you get this:
The Restaurant Cheat Sheet
| In the restaurant | In the system | Its job |
|---|---|---|
| Host at the door | Load balancer | Sends each request to a free server |
| Waiters | Stateless servers | Take requests; any waiter can serve anyone |
| Order tickets on the rail | Queue | Holds writes in line so none get lost in a rush |
| Cooks | Workers | Do the slow work, update the database and cache |
| The kitchen's order book | Database (primary) | The official record of everything |
| Photocopies of the order book | Read replicas | Extra copies just for reading |
| "Today's specials" board | Cache | Quick answers for the questions everyone asks |
The Picture
This is the short version from System Design School. It hides the load balancer and replicas, but the flow is the same:
Write path: user → server → queue ("got it") → workers → database + update the cache.
Read path: user → server → cache. Not there? Read it from a database replica, then fill the cache for next time.
Why split them? Because most apps get way more reads than writes. Think how many times you scroll Instagram compared to how many times you actually post. So reads should be fast and cheap, and writes should be safe.
Two Plug-ins for When You Need Them
Some questions need one of these extra boxes. Each one is really just a bigger or more specialised version of a box we already have.
1. Object storage + CDN (for big files). Images and videos are way too big for the database or the cache. So they go into object storage, which you'll often hear called a bucket (like Amazon S3). In front of it sits a CDN (content delivery network), a bunch of servers around the world that keep copies of the files, so people download from a server near them.
- Object storage = the database, but for big files. Like the restaurant's big storeroom.
- CDN = the cache, but for big files and close to the users. Like branch kiosks in every city selling the popular items, so customers don't all travel to HQ.
2. A search index (for text search). A normal database isn't built for "find posts that contain these words". So text search gets its own search index. Like the index at the back of a recipe book: for each word, a list of the pages that mention it.
NOTE
Names you'll hear: Kafka or RabbitMQ for queues, Redis for caches, Amazon S3 or Google Cloud Storage for buckets, Cloudflare or CloudFront for CDNs, and Elasticsearch for search.
The Catch
Because the waiter says "got it" before the food is cooked, there's a short moment where what you saved and what other people see don't match yet.
Example: a seller changes a price from RM50 to RM45 and sees "Saved". For a second or two, a buyer might still see RM50.
For most things, this is totally fine. Nobody gets hurt if a like count is one second late. But be careful when lots of people want the same thing at the same time (seats, tickets, stock) or when money moves. Waiting in the queue there means 20 people all hear "got it" for one seat. We'll see how to fix that in the Ticketmaster example below.
How to Use It: 4 Steps
The video gives a simple method for any question:
- List what users do. These are the verbs in the question: submit, upload, search, send.
- Sort them into reads and writes.
- Find the writes that are slow or come in bursts, and the reads that repeat a lot.
- Find the part of the template that carries it. Slow writes lean on the queue and workers. Repeated reads lean on the cache.
Words in the question like fast, real time or reliable usually tell you which part matters most.
TIP
In the interview, don't just draw the full template straight away, it looks memorised. Start from the question, then add the boxes one by one and say which requirement each box is there for.
Seven Questions, One Template
Five of these fit the template as it is. The last two need one extra piece. In every diagram, blue is the part doing the heavy lifting and orange is what's new for that question, so you can see what changes at a glance.
1. LeetCode: the cleanest queue problem
- Read: opening a problem. Everyone reads the same few problems, so they come from the cache.
- Write: submitting code. It's slow (compile, run hidden tests in a sandbox, a locked-down box for running a stranger's code) and it comes in bursts when a contest starts.
- So submit drops a job in the queue and replies right away with a submission ID and status "queued". Workers run the code and save the verdict. The app checks the submission ID every second or so until the verdict appears.
The numbers are what make it click for me: 5 million submissions a day is only ~60 a second, but a contest peaks at ~670 a second. Each run takes ~3 seconds, so you need ~250 worker machines at the peak versus ~20 on a normal day. While new machines start up, the queue grows to around 30,000 submissions and someone at the back waits maybe 45 seconds. But nothing gets dropped and the submit button stays fast. About 5–6 minutes in, the line is gone.
2. YouTube: a slow write, but huge
- Write: uploading. Each video must be converted before anyone can watch, so that's queue + workers.
- Read: watching, way more than uploading.
- What's different: size. A video is gigabytes, so it uses the object storage + CDN plug-in.
- The upload doesn't even go through our servers. The app gives the phone a pre-signed URL, a link that only works for a few minutes, and the phone uploads straight into the bucket. Then a job goes into the queue and workers convert the video into a few sizes (so a phone on weak signal plays a small one, a TV plays a big one). Around 500 hours of video get uploaded every minute, so the queue has a lot to do.
- Watching: the video is served in small chunks of a few seconds each, copied to CDN servers near viewers. Someone in Tokyo mostly hits a server near Tokyo.
3. URL shortener: almost all reads
- Write: shortening a link. Read: opening a short link (redirect).
- Say 100 million daily users, 1 million links a day, and 100 opens per link. That's ~12 writes a second vs ~1,200 reads. So this time the cache does the work, and the queue barely has anything to do (that's fine!).
- New piece: making a unique short code when you have many servers. Give each machine its own ID and let it count up (1, 2, 3...) with its ID in front, so two machines never give the same number. Then write the number in base 62 (0–9, a–z, A–Z). Six characters gives you about 56 billion codes.
4. Post search: a read the cache can't do
- Write: publishing a post, can finish in the background, so it goes through the queue.
- Read: searching words across billions of posts. You can't look that up by key like a cache, so the search index plug-in does the reading.
- It uses an inverted index (the recipe-book index again): for each word, the list of posts containing it. Search for two words, look up two lists, find the posts in both.
- When someone posts, an indexing worker splits the text into words and adds the post to each word's list. The post shows up in search a few seconds later. Popular searches get cached too.
5. Chat: uses almost every box
- Write: sending a message, saved to the database. Read: getting messages, but they must arrive without you asking. The keyword is real time.
- So the app keeps a WebSocket open, a connection that stays open both ways. The servers holding these connections now know which users are on them, so they're not stateless anymore. We call them gateways. 100 million people online at ~100,000 connections each = ~1,000 gateways.
- Alice (gateway 7) messages Bob (gateway 42): save it to the database with the next number in the conversation → Alice gets her tick → gateway 7 looks Bob up in a small in-memory registry (that's the cache) → publishes on a pub/sub channel (like a queue) that gateway 42 listens to → 42 pushes it to Bob.
- Bob offline? A job goes to the queue and a worker sends a push notification. When he reconnects, he says "the last one I saw was number 3" and gets 4, 5 and 6 from the database.
6. Ticketmaster: everyone wants the same seat
1 million people show up in the first minute for 50,000 seats. That's 20 people per seat.
- Browsing the seat map is a read, from the cache. A seat map one second old is okay.
- Holding a seat is the problem. If every click goes into the queue, all 20 people hear "got it", then 19 get "sorry" later. Not nice.
- Fix 1: a waiting room. For the hot concert's buying pages only, people without a token get sent to a waiting room page instead of the app servers. It keeps everyone's place in line, and when it's your turn, it gives you a token to go through. (That's how Cloudflare, Queue-it and AWS waiting rooms work.)
- Fix 2: skip the queue for the hold. The server does one atomic step in the in-memory store: "set seat A12 to held, only if it's free, with an expiry". First click wins, the other 19 hear no right away. If the winner doesn't pay in time, the hold expires and the seat goes back. The database only gets written when someone actually pays.
7. News feed: one write, millions of readers
- Posting is a write, opening your feed is a read that happens way more often.
- Usual design: when you post, a worker copies the post ID into each follower's feed in the cache. Opening your feed = one cache read.
- The problem: a celebrity with 50 million followers means 50 million feed writes for one post, and everyone else's posts wait behind it 💀
- Fix (one extra arrow, no new box): accounts under ~100,000 followers still get pushed through the queue. Bigger accounts don't. When you open your feed, the server also grabs their recent posts from the database and mixes them in. Most people follow only a few accounts that big, so it's just a read or two extra.
Remember It in Five Lines
- Write → queue → workers → database + cache
- Read → cache (not there? → replica, then fill the cache)
- Big files → bucket + CDN. Text search → search index.
- Everyone fighting for one thing? Skip the queue with an atomic hold (plus a waiting room).
- One write to millions? Push for normal accounts, pull for celebrities.
TIP
Bonus from my performance testing side: with this design, a fast "Saved" doesn't mean the work is done. It only means the ticket is on the rail. When load testing, watch how long the queue gets and how fast the workers clear it, or your results will look better than the system really is.