The design interview recipe
A repeatable 45-minute plan for any system design interview: what to do in each phase, how to drive it, how you are graded, worked through on Pastebin.
On this page
The problem: one vague sentence and 45 minutes
The interviewer says "Design Pastebin" and then stops talking. There is no spec, no list of features, no numbers. You have about 45 minutes, a whiteboard (or a shared drawing tool), and someone watching how you think.
Most people who do badly here are not short of knowledge. They fail in one of three predictable ways:
- They freeze, because there is no obvious first step.
- They sprint into boxes and arrows, and twenty minutes later discover they designed the wrong thing (no expiry, or accounts nobody asked for).
- They run out of time on one detail and never reach the parts that show seniority: trade-offs, scale and failure.
The fix is a recipe: the same seven phases, in the same order, every time. It gives you a first step, it makes sure nothing important is forgotten, and it lets the interviewer see where you are. Every case study in this course (from WhatsApp to YouTube) follows it.
The seven steps, and the two habits that matter as much
- A system design interview gives you about 45 minutes and a vague question, like “design Pastebin”. Strong answers follow the same recipe every time, so you never freeze and never forget a part.
- Two habits matter as much as the steps. Think out loud, so the interviewer can follow and steer you. And for every choice, name the trade-off: what you gain, what you give up. There is rarely one right answer, only well-argued ones.
The recipe, phase by phase
| Phase | Time | What you produce | What the interviewer is checking |
|---|---|---|---|
| 1. Clarify requirements | ~5 min | 3–5 functional requirements, 3–5 non-functional targets with numbers, an out-of-scope list | Do you design the right thing? Can you prioritise? |
| 2. Estimate | ~5 min | Requests per second (average and peak), storage per year, bandwidth, one or two numbers that size the system | Can you find the number that changes the design? |
| 3. API | ~5 min | 3–6 endpoints or events with their key fields | Do you think from the client's side? Idempotency, pagination |
| 4. Data model | ~5 min | The main entities, their keys, which kind of store and why | Do you match access patterns to storage? |
| 5. High-level design | ~10 min | Boxes and arrows, with the main flows traced through them | Is it coherent and does it meet the requirements? |
| 6. Deep dives | ~10–15 min | 2–3 hard problems: options, a choice, its cost, how it fails | Depth, trade-offs, the second-order failure |
| 7. Wrap up | ~2–3 min | Bottlenecks, failure modes, what you would monitor, what you'd do next | Do you see the system as something that runs and breaks? |
The times are a guide, not a law. If the interviewer says "skip the estimates", skip them. If they want to spend 20 minutes on one deep dive, follow them. The recipe tells you what to do when nobody is steering, which is most of the time.
Phase 1: clarify the requirements
Ask questions that change the design, not questions for their own sake. Good ones are about scale ("how many users?"), shape ("read-heavy or write-heavy?"), features that add whole components ("do pastes expire?", "do we need accounts?") and quality ("is a lost paste acceptable?").
Then write two lists on the board. Functional requirements are what the system does ("create a paste, get a link"). Non-functional requirements are how well it does it, and each one should carry a number: "reads under 100 ms at the 99th percentile" (p99 means 99% of requests are at least that fast), "99.9% available". Finish with an out-of-scope list said out loud. It shows you can control time, and it protects you from being marked down for things you chose not to build.
Phase 2: estimate
Back-of-the-envelope estimates exist to answer one question: which part of this system is big? Work from daily totals to per-second rates (a day is 86,400 seconds; round to 100,000), multiply out storage over the retention period, and note the read-to-write ratio. Then say what the number means: "36 TB a year is too big for one database's disk, comfortably small for object storage."
Spend no more than five minutes. Round aggressively; the goal is the right power of ten. A common trap is calculating ten numbers and drawing no conclusion from any of them.
Phase 3: the API
Name the handful of calls the client needs, with their important fields. This is where you show client-side thinking: what is returned, how lists are paginated (cursors, not page numbers, for data that changes), which calls must be idempotent (safe to retry without doing the work twice) and where rate limits go. REST over HTTP is the default; reach for WebSockets or server-sent events only when the server must push.
Phase 4: the data model
List the main entities with their primary key and the queries you will run against them. The store follows from the access pattern: lookups by key at huge scale point to a key-value store; relations and transactions point to SQL; large blobs belong in object storage. Say why in one sentence each.
Phase 5: the high-level design
Draw the request path from client to storage and back: clients, load balancer, stateless services, caches, databases, queues, object storage, CDN. Then trace one or two flows out loud, hop by hop. A diagram nobody walks through is just a picture; the trace is what proves it works. Keep it simple enough to meet the requirements, and no simpler.
Phase 6: deep dives
Pick the two or three hardest problems (or the ones the interviewer points at) and give each the same shape: the problem, two or three options, the choice, its cost, and how it breaks. This is where most of the grade for senior candidates comes from. Prefer the parts that are specific to this system (key generation for Pastebin, fan-out for Twitter) over generic ones (adding a load balancer).
Phase 7: wrap up
With a few minutes left, step back. Name the likely bottleneck as traffic grows 10×, what happens when each component fails, and the three or four metrics you'd put on a dashboard. If time is short, this is the phase to compress, but never drop it entirely: one sentence on failure is worth a lot.
Driving the conversation
The interviewer is grading the conversation, not just the final diagram. Four habits make it easy for them to give you credit:
- Think out loud. Silence for two minutes reads as being stuck. Narrate: "I'm deciding between a key-value store and Postgres; every lookup is by key, so…"
- Signpost. Say which phase you are in and when you move on: "That's the API. Next, the data model, unless you want to go deeper here?"
- Check in at the seams. After requirements and after the high-level design, ask "Does this match what you had in mind?" It invites steering while it is still cheap.
- Name the trade-off for every choice. "Object storage for the text: cheap and durable, at the cost of a second hop on every read, which the cache will hide." There is rarely one right answer, only well-argued ones.
How interviewers grade you: mid-level vs senior
The same question is asked at every level. What changes is how much you do without being asked.
| Signal | Mid-level (roughly 2–5 years) | Senior | Staff and above |
|---|---|---|---|
| Driving | Moves through the phases with some prompting | Drives the whole session; the interviewer mostly listens | Reshapes the problem ("do we even need X?") |
| Requirements | Gets the main features | Turns qualities into numbers and lets them drive the design | Asks about the business: cost, abuse, growth |
| Design | A working, conventional design | Choices justified with numbers; nothing unused on the board | Simplest design that will survive the next 3 years |
| Depth | Explains a component when asked | Goes deep on 2–3 areas with options and failure modes, unprompted | Covers operations, migrations, multi-region, team boundaries |
| Trade-offs | Knows the options | Picks one, states the cost, says when they'd switch | Weighs trade-offs across the whole system, including people and cost |
A mid-level candidate passes with a correct, complete design and sensible answers to follow-ups. A senior candidate is expected to find the hard parts themselves and to talk about how the design fails. That is why every case study here has "where this breaks" boxes.
Common mistakes
Worked example: Pastebin
Now run the recipe on a real question. Each phase starts with a Your turn box: write your answer first, then open ours and compare.
The question: Pastebin
- Let’s run the recipe on a small example: Pastebin. You paste some text, get a short link like pastebin.com/aB3xY9, and anyone with the link can read it until it expires.
Users paste text and get a short link to share. Anyone with the link can read it. Pastes expire. We don’t need user accounts, editing, or syntax highlighting today.
1. Clarify the requirements
You have been told only "Design Pastebin." Write the 4–6 questions you would ask, then the agreed list: functional requirements, non-functional requirements with a target each, and out of scope.
Compare with our answer
The questions that change the design: How many pastes a day? How big can one be? Do pastes expire, and who sets the expiry? Do we need accounts or editing? Can pastes be private? How long must links keep working?
A strong answer mentions: create and read by short link · expiry · a size limit · read-heavy traffic · availability and durability targets with numbers · links that cannot be walked through by counting · accounts and editing out of scope.
Requirements: what it does, and how well
- Step one, requirements. Functionally: create a paste and get a link, read a paste by its link, and expiry. Say out loud what you’re leaving out: no accounts, no editing.
- Non-functional requirements describe quality: highly available, fast reads, nothing lost, and links that can’t be guessed. Notice it’s read-heavy: about ten reads per write. That one fact shapes the whole design.
Functional: what it must do
- Create a paste: Text up to 1 MB → returns a short link
- Read a paste by its link: Anyone with the link can read it
- Expiry: Default 1 year; optional 1 hour, 1 day, 1 week
- Custom alias (optional): pastebin.com/my-notes if it’s free
Out of scope
User accountsEditing pastesSyntax highlighting
Non-functional: how well it must work
| Quality | Target | Why |
|---|---|---|
| Availability | 99.9%+ | Links are shared; a dead link is a bad experience |
| Read latency | < 100 ms (p99) | Reading should feel instant |
| Durability | No paste lost before it expires | People rely on the link |
| Read-heavy | ≈ 10 reads per write | So optimise and cache the read path |
| Unguessable links | Short but random | Links shouldn’t be enumerable |
The non-functional list is where the design comes from. "Read-heavy, about ten reads per write" says caching will pay off. "No paste lost before it expires" says the text needs durable, replicated storage. "Unguessable links" rules out the most obvious key scheme (counting 1, 2, 3…).
2. Back-of-the-envelope estimates
Assume 10 million new pastes a day, 10 reads per write, an average paste of 10 KB, kept for a year. Work out writes and reads per second, storage per year, read bandwidth, and how many links we need.
Compare with our answer
- Writes: 10 M ÷ ~100,000 s ≈ 100/s (116/s exactly); plan for 2–3× at peak.
- Reads: 10× that, about 1,200/s, peaking at a few thousand.
- Storage: 10 M × 10 KB = 100 GB a day, ≈ 36 TB a year before compression (text compresses 3–5×).
- Read bandwidth: 1,200/s × 10 KB ≈ 12 MB/s. Small.
- Links: 10 M × 365 ≈ 3.65 B a year; 7 base-62 characters give 3.5 trillion, plenty.
A strong answer mentions: per-second rates with a peak factor · storage over the retention period · the conclusion (the text is the big number and belongs in object storage) · key-space size · that the request rate itself is modest.
The numbers that shape the design
- Step two, estimates. Ten million pastes a day is about a hundred writes a second and a thousand reads. Storage is the big number: around thirty-six terabytes a year. That tells us text belongs in cheap object storage, not in the main database.
Assumptions: new pastes per day 10 M; reads per write 10; average paste size 10 KB; years kept 1.
| Number | Estimate | Why it matters |
|---|---|---|
| Writes per second | 116 / s | 10 M ÷ ~100,000 seconds in a day ≈ 100/s. |
| Reads per second | 1.16 K / s | Peak is often 2–3× the average. |
| Storage | 36.5 TB | 10 M × 10 KB = 100 GB a day → ~36 TB a year. |
| Read bandwidth | 11.6 MB/s | |
| Links needed | 3.65 B | 7 base-62 characters give 62⁷ ≈ 3.5 trillion links. |
- A day has 86,400 seconds; round it to 100,000 to do the maths in your head.
- Text compresses well (about 3–5×), so real storage is smaller.
- Metadata (link, expiry, size) is tiny next to the text itself.
What do these numbers say? The request rate is modest: a hundred writes a second is easy for any database, and a thousand reads a second is easy with a cache. The storage is the big number, and it is made of blobs, which tells you where the text goes. And the key space has room to spare, so 7 characters is enough.
Why is 7 characters the right length?
Base 62 (a–z, A–Z, 0–9) gives 62⁶ ≈ 57 billion keys for 6 characters and 62⁷ ≈ 3.5 trillion for 7. At 3.65 billion a year, 6 characters would be about 6% full after one year and crowded within a decade, which makes random keys collide often. 7 characters stays under 0.1% full per year. Each extra character multiplies the space by 62, so "make it longer" is the cheap answer whenever you need more room or more guess resistance.
3. API
Write the calls a browser needs, with their main fields and status codes. Which ones are cacheable, and which need protection from abuse?
Compare with our answer
A strong answer mentions: POST to create, returning the link and expiry · GET by key, returning 404 for missing or expired pastes · optional expiry and custom alias fields · a rate limit on creation · read responses that the CDN can cache · a way to delete (a secret token, since there are no accounts).
| Call | Request | Response | Notes |
|---|---|---|---|
POST /v1/pastes | { text, expiresIn?, alias? } | 201 { url, expiresAt } | Rate-limited per IP to stop spam |
GET /v1/pastes/{key} | – | 200 { text, createdAt, expiresAt } or 404 | Cacheable; served by the CDN for hot pastes |
DELETE /v1/pastes/{key} | deleteToken | 204 | Optional: the creator gets a secret delete token |
Two small details lift this API above the average. First, a GET for an expired paste returns 404 (or 410 Gone) even if the bytes are still in storage, because cleanup is lazy. Second, the delete token is a long random secret returned only to the creator: with no accounts, possession of the token is the permission.
4. Data model
Which pieces of data are there, what is each one's key, and which kind of store suits each? Think about size: a paste can be 1 MB.
Compare with our answer
A strong answer mentions: a small metadata record keyed by the short key · the text itself in object storage, with the metadata pointing at it · expiry stored as a timestamp on the metadata · a store that does fast key lookups at scale · where unused keys come from.
pastes (metadata) Key-value store (e.g. DynamoDB)
key: "aB3xY9" (primary key)object_url: s3://pastes/aB3xY9size_bytescreated_atexpires_at
Every lookup is by key, at huge scale, with no joins: a key-value store fits perfectly.
paste text Object storage (e.g. S3)
s3://pastes/{key}compressed text, up to 1 MB
Tens of terabytes of blobs, cheap and durable. The database only stores where each one lives.
unused keys Key generation service
pool of ready keyshanded out in batches to app servers
Pre-generates random 7-character keys so creating a paste never has to retry on collisions.
The decision that shapes everything is splitting metadata from content. The metadata row is a few hundred bytes and is read on every request; the text is up to 1 MB and is read once per cache miss. Different sizes and access patterns, so different stores.
There is also a hard reason not to put the text in DynamoDB: an item there is limited to 400 KB, so a 1 MB paste does not even fit. Object storage (S3, GCS) charges roughly a couple of US cents per GB per month and keeps data on several devices across facilities, so 36 TB costs around a thousand dollars a month and survives disk failures without us doing anything.
5. High-level design
Sketch the boxes for creating and reading a paste. Where does the key come from, where does each piece of data live, and what serves a paste that suddenly gets a million views?
Compare with our answer
Compare with the figure. The pieces people forget: the key generator (or another key scheme), keeping the text out of the database, the CDN for viral pastes, and something that cleans up expired pastes.
The architecture, then the create and read flows
- Step five, the high-level design. A load balancer in front of stateless paste servers. A key generator so links are random and unique. Metadata in a key-value store, the text itself in object storage, a cache and a CDN for hot pastes, and a cleaner that deletes expired ones.
- Creating a paste: the service grabs a ready-made key, stores the text in object storage, saves a small metadata row, and returns the link.
- Reading: popular pastes come straight from the CDN. Otherwise the service checks the cache, then the metadata store, then fetches the text from object storage, caching it on the way back.
| Component | What it does |
|---|---|
| CDN | Serves popular pastes from the edge; most reads never reach us |
| Paste service | Stateless; scale by adding instances behind the load balancer |
| Key generator | Hands out batches of unused random keys |
| Metadata DB | key → object location and expiry |
| Object store | The text itself: cheap, durable blobs |
| Expiry cleaner | Background job that deletes expired pastes in batches |
Trace both flows out loud, one hop at a time. Create: the browser posts the text; a stateless paste service takes a key from its local batch, writes the text to object storage, then writes the metadata row, and returns the link. The order matters: if the service dies between the two writes, we are left with an orphaned blob (harmless, cleaned up later) rather than a link that points at nothing.
Read: the CDN answers popular pastes from the edge. On a miss, the service checks the cache, reads the metadata (and checks expires_at), fetches the text from object storage, caches it and returns it. Pastes never change after creation, which makes every layer of caching safe.
6. Deep dives
Before reading on, write two or three sentences on each: how do you make keys unique and hard to guess across many servers? How do reads stay under 100 ms when object storage takes tens of milliseconds? How do expired pastes disappear?
Compare with our answer
A strong answer mentions:
- Options for keys (counter, hash, random, pre-generated) and the weakness of each.
- That object storage latency is hidden by a cache and a CDN, safe because pastes are immutable.
- Lazy expiry checks on read plus background or lifecycle cleanup.
- What happens to cached copies when a paste is deleted or expires.
How are keys generated?
Deep dive: generating keys
- Deep dive one: generating keys. Sequential IDs are guessable, hashes collide, so a small key generator hands out random unused keys in batches.
| Option | How | Catch |
|---|---|---|
| Auto-increment ID in base 62 | One database counter, encoded as aB3xY9 | Sequential, so anyone can enumerate every paste; the counter is a single bottleneck |
| Hash of the text (MD5, take 7 chars) | Same input, same key | Identical pastes collide on purpose; truncated hashes collide by accident, so you still need check-and-retry |
| Random key, insert-if-absent | Generate 7 random characters; a conditional write fails if the key exists | Simple and stateless; a collision is about 1 in 1,000 after a year, so a retry is rare but must be handled |
| Key generation service (KGS) | Pre-generates random unused keys; each app server takes a batch of, say, 1,000 | One more service to run; a crashed server's unused batch is lost (harmless with trillions of keys) |
Choice: either of the last two. The data's choice is a KGS, which makes creation a pure in-memory operation and never retries. A strong candidate notes that random keys with a conditional write are nearly as good and need no extra service, and picks based on scale: with the key space under 1% full, collisions are so rare that the retry path is almost never taken.
Where does the text live?
Covered by the data model: object storage for the text, a key-value store for metadata. The deep-dive version of the answer adds the numbers: a database holding 36 TB a year of blobs needs large disks, slow backups and painful re-sharding, while object storage scales without effort and costs a fraction as much.
How do reads stay fast?
Object storage typically takes tens of milliseconds to return the first byte, too slow to hit on every read against a 100 ms p99 target. Because pastes are immutable, they can be cached aggressively at every layer: an in-memory cache (Redis or Memcached) keyed by paste key, and a CDN in front for anonymous reads. Popularity is lopsided, so a cache holding the hottest few percent of pastes serves most reads.
How do expired pastes disappear?
Two parts. On read, compare expires_at with now and return 404 if it has passed; this is what makes expiry correct. In the background, a cleaner deletes expired metadata and text in batches at a quiet time; this is what reclaims space. Managed tools help: DynamoDB's TTL feature deletes expired items for you, but only eventually (typically within a few days), which is exactly why the read-time check is still needed. S3 lifecycle rules can expire objects by age, which suits the default one-year expiry.
7. Wrap up: bottlenecks, failures, monitoring
Scaling bottlenecks
| Bottleneck | Fix |
|---|---|
| Reads spike when a paste goes viral | CDN and cache absorb it; the paste never changes, so long cache times are safe |
| Metadata grows to billions of rows | A key-value store shards by key automatically |
| Spam and abuse | Rate limit creates per IP; size limits; scan for malware links |
When things fail
| Failure | What happens |
|---|---|
| A paste server crashes | The LB stops sending it traffic; servers are stateless, so nothing is lost |
| The key generator is down | Servers keep using their current batch of keys for a while; run two generators for safety |
| Cache node lost | Reads fall back to the database and object store; the cache refills |
What to monitor
Create and read latency (p50, p99)Error rateCache hit ratioUnused keys leftStorage growth per day
Wrap up, and the recipe in one line
- Finally, wrap up with bottlenecks and failures: what happens when a paste goes viral, when a server dies, when the key generator is down. That’s the recipe, and every design in this course follows it.
When the interviewer pushes
Answer these three in order before opening ours. 1) "Now add private pastes that only the creator can read." 2) "Traffic grows 100×: a billion new pastes a day." 3) "A security researcher says she found 5,000 pastes in an hour by guessing links. What do you change?"
Compare with our answer
A strong answer mentions:
- Private pastes need either an owner (so accounts come back into scope) or a long secret token in the link (16+ random characters); either way they skip the CDN, and the read path checks permission before returning text.
- A billion a day is about 12,000 writes/s: still fine for a sharded key-value store, but storage becomes ~3.6 PB a year, so compression, inline small pastes and tiered storage matter; key space use rises 100×, so move to 8 characters.
- 5,000 hits in an hour means guessing works: lengthen keys (each character is 62× harder), rate-limit and block clients with many 404s, and never treat a short link as access control for sensitive content.
How would you add user accounts?
Add a users table and an owner_id on pastes. Logged-in users can list and delete their pastes; anonymous pastes still work.
How would you support private pastes?
Store a visibility flag; private pastes need a signed token in the link or a logged-in owner, and must not be cached on the CDN.
What if one paste is read a million times a minute?
It’s served from the CDN edge with a long cache time; the origin barely notices.
- Seven phases: requirements (5) → estimates (5) → API (5) → data model (5) → high-level design (10) → deep dives (10–15) → wrap up (2–3).
- Requirements: functional list, non-functional targets with numbers, out of scope said aloud.
- Estimates: daily totals ÷ ~100,000 s; storage over retention; always end with "so…".
- Every choice: name what you gain and what you give up.
- Drive it: think aloud, signpost each phase, check in after requirements and after the diagram.
- Deep dive shape: problem → options → choice → cost → how it breaks.
- Senior signal: finds the hard parts and the failure modes without being asked.
- Pastebin: KGS or random keys with conditional writes · metadata in a key-value store, text in object storage · cache + CDN (immutable content) · lazy expiry check plus batch cleanup · purge caches on delete.
1. Ten minutes into an interview, a candidate has a detailed diagram, then learns pastes must expire and be deletable. What went wrong?
Expiry and deletion each add pieces (a cleaner, cache purges, delete tokens). Scoping first is what surfaces them; the order of the later phases matters less.
2. Pastebin gets 10 million new pastes a day. Roughly how many writes per second is that on average?
10 M ÷ 86,400 s ≈ 116/s. Rounding the day to 100,000 seconds gives 100/s, close enough to size the system. Peaks are 2–3× higher.
3. Which estimate should most change the Pastebin design?
The request rates are modest and easily handled. The storage volume, made of blobs, is what decides where the text lives.
4. Paste links are 7 random base-62 characters and a year's worth (3.65 billion) exist. What is true about guessing them?
3.65 B used out of 3.5 T possible is roughly 0.1%. Random keys stop enumeration, but sensitive pastes need longer keys or a real access check.
5. A user deletes a paste containing a password, but people can still open it for an hour. What is the most likely cause?
The read path checks metadata on every origin request, so a deleted row is caught there. The edge never asks: purge the CDN on delete and keep max-age short.
6. What best separates a senior answer from a mid-level one in the same interview?
Both levels should cover the phases. Seniors are expected to steer the session, quantify choices and raise failure modes without being asked; extra boxes and stubbornness count against you.
7. Why is DynamoDB TTL alone not enough to enforce paste expiry?
TTL deletion is a background process with no timing guarantee. Checking expires_at on every read makes expiry correct; the TTL or cleaner only reclaims space.
8. While you explain your choice of database, the interviewer asks "what if writes grow 50×?". What is the best response?
Pushback is usually steering. Recompute, find the first bottleneck and change only what must change, naming the trade-off as you go.
Score 60% or more and the lesson is marked complete.