Home / Blog / Programming / System Design
Top 50 System Design Interview Questions with Answers
Programming · System Design · 35 min read
Fifty system design interview questions with answers, from the interview framework to the classic designs. Every number is worked in the open and checked.
How this sheet works
This sheet carries fifty system design interview questions, grouped by topic. Foundations come first. Building blocks follow. Then come the classic designs, with six five-minute design walkthroughs last.
Every number below is worked in the open. Each estimate shows its arithmetic, so a reader can check it and change an assumption. No number is taken on trust.
Work through the questions in order, one at a time. Speak your own answer first, then read the one here. Draw each design on paper before you read the one here. Speaking and drawing fix the ideas in memory better than reading alone does.
The System Design track holds 177 lessons in five courses. Beginner has 47. Intermediate has 9. Advanced has 29. Classics has 64. Machine Learning has 28.
Three honest limits. This sheet is not a substitute for the full design articles. Each classic design gets one complete article in the track. Machine learning systems need their own study, in the Machine Learning course. And no vendor's limits appear here: the numbers are worked from stated assumptions, not from any provider's documentation.
1. What is system design, and what is it used for?
System design is the planning of a whole software system before it is built. The plan names the parts of the system. The plan also names how those parts work together.
System design is used when a system must serve many people at once. It is used when data must be stored safely. It is used when one part fails and the rest must keep working.
A good design starts from the problem, not from a favourite tool. The problem sets the scale. The scale sets the parts that are needed.
The What Is System Design lesson teaches this idea.
2. Why do interviews ask system design questions?
System design interviews test judgement about large systems. The interviewer watches how a candidate breaks a vague problem into parts. The interviewer also watches how a candidate weighs one choice against another.
System design is asked because real systems are built by teams. A single person cannot hold every detail of a large system. The interview checks whether a candidate can reason about the whole system and still notice the details that matter.
There is no single right answer in a system design interview. A clear chain of reasoning matters more than a perfect diagram. A candidate who states each assumption and each trade-off gives the interviewer something real to judge.
The What Is System Design lesson teaches this idea.
3. How should a system design interview answer be structured?
A system design answer follows four steps in order. The steps are clarify the requirements, draw the high-level design, deep-dive on one part, and discuss trade-offs. The steps give the answer a shape that an interviewer can follow.
Each step has a different job. Clarifying the requirements fixes what is being built. The high-level design shows the main parts and how data flows between them.
The deep-dive shows depth in one hard part. The trade-offs step shows honesty about what the design gives up. A strong answer leaves time for that last step.
The Clarify the Requirements lesson and the High-Level Design First lesson teach this idea.
4. What should be clarified before designing a system?
Clarifying the requirements means asking questions before drawing anything. The candidate asks who uses the system. The candidate asks what the system must do and what it need not do.
Scale questions come next. The candidate asks how many users the system serves. The candidate asks how much data it stores and how fast it must answer.
Clarifying also covers the hard limits. The candidate asks what must never be lost. The candidate asks what may be slow and what must be fast. Those answers shape every choice that follows.
The Clarify the Requirements lesson teaches this idea.
5. What is a high-level design, and what belongs in it?
A high-level design is a simple drawing of the main parts of a system. The drawing shows clients, servers, storage, and the paths between them. It shows the shape of the system before any single part is built in detail.
A high-level design belongs early in the answer. It gives the interviewer a map of the whole system. It also gives the candidate a map to return to during the deep-dive.
Only the main parts belong in a high-level design. Extra detail at this stage hides the shape. The detail comes later, in the deep-dive on one part.
The High-Level Design First lesson teaches this idea.
6. What does it mean to deep-dive on one part of a system?
A deep-dive means taking one hard part of the design and working through it in detail. The candidate picks the part where the design is most likely to fail. The candidate then shows how that part works step by step.
A deep-dive shows depth rather than breadth. The candidate explains the data the part stores. The candidate explains how the part handles growth, failure, and heavy load.
The deep-dive must link back to the high-level design. The part still fits the map drawn earlier. A deep-dive that drifts away from that map loses the thread of the answer.
The Deep-Dive on One Part lesson teaches this idea.
7. Why does a system design answer end with trade-offs?
Trade-offs are the costs that come with a design choice. Every choice gains something and gives up something else. A design with no stated cost is a design that has not been thought through.
The trade-offs step names what the design gives up. A fast read may cost extra storage. A simple design may cost the ability to grow later.
The wrap-up gathers the answer into a short close. The candidate restates the main parts and the main costs. The candidate also names what would change first if the system grew.
The Trade-Offs and Wrap-Up lesson teaches this idea.
8. What does thinking in scale mean in system design?
Thinking in scale means turning a daily total into a rate the system must handle. A total such as one million requests a day says little on its own. A rate such as requests per second says what the system must do at any moment.
A day holds 86,400 seconds. That number comes from 24 hours times 60 minutes times 60 seconds. Every daily total is divided by that number to give requests per second.
One million requests a day divided by 86,400 is 12 per second. One hundred million a day is 1,157 per second.
Scale thinking also means watching the shape of the load. Traffic is rarely flat across a day. A system built only for the average rate fails at the peak.
The Thinking in Scale lesson teaches this idea.
9. How do you work out requests per second from a daily total?
Requests per second is a daily total divided by the seconds in a day. The divisor is always 86,400. The result is the average rate across the whole day.
The average rate is only the start of the answer. Real traffic rises and falls during the day. A peak rate is often two or three times the average. The system must be sized for the peak, not the average. At twice the average, the peak reaches 232 requests per second.
A quick check keeps the arithmetic honest. Ten million requests a day is about 116 requests per second. One billion requests a day is about 11,574 requests per second.
The Thinking in Scale lesson teaches this idea.
10. What is the difference between latency and throughput?
Latency is the time one request takes from start to finish. Throughput is the number of requests a system finishes in a unit of time. The two measure different things, and a system can be good at one and poor at the other.
Low latency means a single request is answered quickly. High throughput means many requests are answered in each second. A fast road with one lane has low latency and low throughput.
A worker taking 200 ms per request finishes 5 requests per second. Ten such workers finish 50 per second.
More workers raise throughput without changing latency. Each worker still takes the same time per request. The system simply finishes more requests in parallel.
The Latency and Throughput lesson teaches this idea.
11. How slow is disk compared with memory?
Latency numbers give a sense of how long each kind of storage takes. The track teaches that reading 1 MB from memory takes 0.25 ms. Reading the same 1 MB from disk takes 20 ms.
Disk is 80 times slower than memory for that 1 MB read. The gap is large enough to change a design. A system that reads from disk on every request pays that cost on every request.
The gap grows with the amount of data. Reading 100 MB from memory takes 25 ms. Reading 100 MB from disk takes 2,000 ms, which is 2 seconds.
The Latency Numbers lesson teaches this idea.
12. What is back-of-envelope estimation?
Back-of-envelope estimation is rough arithmetic done without a calculator. The aim is an answer that is close enough to judge a design. An answer within a factor of two is good enough for most design choices.
The method uses round numbers and powers of ten. A day is rounded from 86,400 seconds to 100,000 seconds. The division then becomes easy, and the small error does not change the design.
One million requests a day is about 10 per second with the round divisor, beside the exact 12. A year holds 31,536,000 seconds.
A good estimate states its assumptions in the open. The reader can then check the arithmetic. The reader can also change an assumption and see how the answer moves.
The Back-of-Envelope Estimation lesson teaches this idea.
13. How do you estimate storage and bandwidth?
Estimating storage means multiplying the number of items by the size of one item. The size of one item is a stated assumption. The count comes from the requirements.
Estimating bandwidth means dividing the data moved in a day by the seconds in a day. The result is the average rate in bytes per second. The peak rate is higher, so the average is a floor, not a ceiling.
Ten million records at 1 KB each take 10 GB. Ten million photos at 1 MB each take 10 TB a day. Moving that much in a day needs 116 MB per second.
Both estimates use the same round-number method. The arithmetic stays visible at each step. A reader can then repeat the sum with different assumptions.
The Estimating Storage and Bandwidth lesson teaches this idea.
14. What is consistency, in plain words?
Consistency means every reader sees the same value for the same piece of data. A write changes the value once. After that change, every copy of the data should show the new value.
Consistency breaks when copies disagree. One copy holds the new value and another still holds the old one. A reader then gets a different answer depending on which copy answers.
Consistency is a promise about what readers see. A strong promise costs time, because every copy must agree before the write finishes. A weak promise is cheaper, because copies can catch up later.
The Consistency in Plain Words lesson teaches this idea.
15. What is availability, in plain words?
Availability means the system answers when it is asked. A system that answers every request is fully available. A system that is down answers nothing.
Availability is measured as a share of time. A system available 99% of the time is down 1% of the time. A year holds 8,760 hours, so that 1% is about 87.6 hours of downtime.
Higher availability costs more effort and more parts. A system at 99.9% is down about 8.76 hours a year. A system at 99.99% is down about 52.56 minutes a year.
The Availability in Plain Words lesson teaches this idea.
16. What is the CAP theorem?
The CAP theorem is a rule about distributed systems. A distributed system stores data on more than one machine. The theorem says the system cannot give all three of its named promises at once when the network splits.
The three promises are consistency, availability, and partition tolerance. Consistency means every reader sees the same value. Availability means the system answers every request.
Partition tolerance means the system keeps working when machines cannot reach each other. A split in the network is a partition. The theorem says a system must keep partition tolerance and then choose between consistency and availability during the split.
The The CAP Theorem lesson teaches this idea.
17. What is the difference between strong and eventual consistency?
Strong consistency means every reader sees a new value at once. A write finishes only when every copy holds the new value. A reader never sees the old value after the write has finished.
Eventual consistency means copies catch up over time. A write finishes before every copy holds the new value. A reader may briefly see the old value, and the copies agree later.
The choice is a trade-off between correctness and speed. Strong consistency suits data that must never be wrong, such as a bank balance. Eventual consistency suits data where a short delay is harmless, such as a like count.
The Strong and Eventual Consistency lesson and the Consistency in Plain Words lesson teach this idea.
18. What does a load balancer do?
A load balancer is a component that sits in front of a group of servers. It receives each incoming request. It forwards the request to one of the servers behind it.
The load balancer spreads work so no single server carries the whole load. It checks the health of each server. It stops sending traffic to a server that has failed.
Nine hundred requests across three healthy servers is 300 each. When one server fails, the same 900 requests share two servers, or 450 each.
Clients talk to one address only. The load balancer hides the number of servers behind that address. New servers can be added without changing the address clients use.
The Load Balancers lesson teaches this idea.
19. How do load balancer algorithms differ?
A load balancer algorithm is the rule that picks the next server. Different rules suit different kinds of traffic. The choice changes how evenly the work spreads.
Round robin sends requests in turn. Each server gets the next request in sequence. The rule is simple and it needs no state.
Round robin shares 12 requests across three servers, or 4 each. Server A holds 10 connections. Server B holds 2. The next request goes to B, which holds 8 fewer.
Least connections sends the next request to the server with the fewest active connections. A busy server is skipped until it catches up. Hashing sends the same key to the same server every time.
The Load Balancer Algorithms lesson teaches this idea.
20. What are sticky sessions, and when do they help?
A sticky session is a rule that sends one user to the same server every time. The load balancer remembers the pairing. Every later request from that user goes to the same machine.
Sticky sessions help when session data lives in server memory. The server already holds the user's state. No lookup is needed on each request.
With stickiness, all 5 of one user's requests reach the same server. Without it, round robin might split them 2, 2 and 1 across three servers.
Sticky sessions have a cost. Traffic can pile up on one server. A server failure still loses the sessions it held.
The Sticky Sessions lesson teaches this idea.
21. Where should caching sit, and why does it help?
A cache keeps copies of slow data close at hand. It sits between the reader and the source of truth. A request checks the cache first.
A cache helps when readers ask for the same data again and again. The source is read once. Later reads are served from the copy.
Disk is 80 times slower than memory for 1 MB: 20 ms against 0.25 ms. A cache with 950 hits in 1,000 requests has a 95 percent hit rate.
Memory is far faster than disk. The track's Latency Numbers lesson gives the numbers. Reading 1 MB from memory takes 0.25 ms, and reading 1 MB from disk takes 20 ms.
The Caching: Where and Why lesson teaches this idea.
22. How do cache read strategies work?
A read strategy is the rule for finding data in a cache. Cache-aside and read-through are the two common rules. They differ in who talks to the database.
With cache-aside, the application looks in the cache first. A miss means the application reads the database itself. The application then stores the result in the cache.
Ninety of 100 reads hit the cache, so 10 reach the database. Nine hundred hits in 1,000 reads is a 90 percent hit rate.
In read-through, the application asks the cache only. The cache fetches from the database on a miss. The application never touches the database directly.
The Cache-Aside and Read-Through lesson teaches this idea.
23. How do cache write strategies work?
A write strategy is the rule for updating the cache and the database together. Write-through and write-back are the two common rules. They trade speed against safety.
In write-through, every update writes to the cache and to the database at once. The two stores stay in step. Each update pays the cost of two writes.
One hundred updates under write-through write 200 times: once to the cache and once to the store. Ten updates to one key under write-back write once to the database.
In write-back, the update writes to the cache only. The database is updated later, in the background. Writes are fast, but a crash can lose data that has not yet been written through.
The Write-Through and Write-Back lesson teaches this idea.
24. How do eviction and invalidation work?
Eviction is the removal of an item to make room for another. A cache has a fixed size. A new item can only enter when an old item leaves.
Least recently used is a common eviction rule. The item untouched for the longest time is removed first. Items in frequent use stay in the cache.
A fourth item in a three-item cache evicts 1 item. When 20 of 100 items change, 20 percent of the cache is invalidated.
Invalidation is the removal of an item because it is out of date. A changed record is removed or replaced. Later reads fetch the fresh value from the source.
The Eviction and Invalidation lesson teaches this idea.
25. How do push and pull CDNs differ?
A CDN is a network of servers spread across many places. Each server holds copies of static files. A reader is served by the nearest server.
In a pull CDN, the edge server fetches a file from the origin on first request. The copy is then kept for later requests. The origin is read once per file, not once per reader.
One thousand requests for one file reach the origin 100 times when 900 are served from the cache. A pull CDN fetches the file once and serves 500 requests, saving 499 origin reads.
In a push CDN, files are uploaded to the edge servers before anyone asks. Every server holds the file from the start. Push suits files that change rarely and are read by many.
The Push and Pull CDNs lesson and the What a CDN Does lesson teach this idea.
26. When should blob and object storage be used?
Blob storage holds large unstructured objects. Photos, videos and backups are typical objects. Each object is stored under a key.
Object storage scales by adding more objects. There is no fixed table shape. Each object carries its own metadata.
Five hundred photos at 2 MB each take 1,000 MB. One thousand MB is 1 GB.
Object storage suits files that are written once and read many times. It is a poor fit for data that changes in small pieces. A database handles small frequent updates better.
The Blob and Object Storage lesson teaches this idea.
27. SQL or NoSQL: how do you choose?
SQL databases store data in tables with fixed shapes. Relationships between tables are explicit. Queries join tables together.
NoSQL databases store data in looser shapes. Documents, key-value pairs and wide rows are common shapes. The shape can vary from one record to the next.
One thousand customers with 5 orders each is 5,000 rows in a SQL table. One NoSQL document holding 5 orders returns 5 orders per read.
The choice follows the shape of the data and the shape of the queries. Fixed shapes with strong relationships suit SQL. Varied shapes with simple lookups suit NoSQL.
The SQL or NoSQL lesson teaches this idea.
28. How do database indexes work?
An index is a separate structure that maps a value to its rows. The database consults the index first. It then reads only the matching rows.
An index speeds up lookups on the indexed field. A search by email finds the row without scanning the table. The gain grows as the table grows.
One insert into a table with 3 indexes writes 4 times: the row plus one write per index. One thousand inserts write 4,000 times.
An index has a cost on writes. Each insert updates the table and each of its indexes. Too many indexes slow writes down.
The Database Indexes lesson teaches this idea.
29. How does replication work, and how does it scale reads?
Replication is the copying of data to more than one machine. One machine takes the writes. The copies serve the reads.
The primary accepts every write. Each replica applies the same writes in order. A replica is a copy that lags slightly behind.
Nine hundred reads across 2 replicas is 450 each. One primary with 2 replicas holds 3 copies of the data.
Replicas scale reads. Read traffic spreads across the copies. The primary is freed to handle writes alone.
The Replication and Replicas lesson and the Scaling Database Reads lesson teach this idea.
30. Why partition data, and how do you choose a shard key?
Partitioning is the splitting of one large table across many machines. Each machine holds one part. The parts are called shards.
A shard key is the field that decides which shard holds a row. Rows with the same key land on the same shard. A good key spreads rows evenly.
A 900 GB table across 3 shards is 300 GB per shard. One million users across 10 shards is 100,000 per shard.
User ID is a common shard key. One user's rows stay together on one shard. Queries for one user touch one machine only.
The Why Partition Data lesson and the Choosing a Shard Key lesson teach this idea.
31. What causes hot spots, and how does rebalancing fix them?
A hot spot is a shard that receives far more traffic than the rest. One popular key causes the imbalance. The hot shard slows down while the others sit idle.
Rebalancing moves data from a busy shard to a quiet one. A hot key can be split across two shards. The move happens while the system keeps serving.
Eight hundred of 1,000 requests hitting one shard is 80 percent. Splitting the hot key across 2 shards leaves 400 requests per shard.
The fix starts with the shard key. A key with one huge value cannot balance. Splitting the hot key spreads its load.
The Hot Spots and Rebalancing lesson teaches this idea.
32. What is a message queue for?
A message queue is a buffer between a producer and a consumer. The producer adds a message. The consumer takes it later.
Queues decouple the two sides in time. The producer never waits for the consumer. A slow consumer does not block the producer.
Three workers at 100 messages a minute handle 300 per minute. Nine hundred queued messages drain in 3 minutes at that rate.
Queues also absorb bursts. Messages wait safely in the queue. Workers drain them at their own pace.
The Message Queues lesson teaches this idea.
33. How does rate limiting work?
Rate limiting caps how many requests one client can make. The cap is set per window of time. Requests above the cap are refused.
A limit protects the system from overload. One greedy client cannot starve the rest. The limit also blunts simple abuse.
A client sending 150 requests against a limit of 100 is refused 50. A limit of 100 per minute allows 6,000 per hour.
The limit is usually counted per client, not per system. Each client gets its own allowance. A fair client is unaffected by a greedy one.
The Design a Rate Limiter lesson teaches this idea.
34. What is idempotency, and why do retries need it?
Idempotency means a repeated operation changes nothing new. The second attempt leaves everything as the first one left it. The outcome stays the same either way.
Retries make idempotency necessary. A network can drop a reply after the work is done. The client retries, unsure whether the first attempt landed.
One payment sent 3 times has 2 duplicate attempts ignored. One request retried 4 times still has 1 effect under an idempotency key.
An idempotency key marks each request. The server keeps the key beside the result. A repeat with the same key gets the kept result instead of doing the work again.
The Idempotency lesson teaches this idea.
35. How do you design a URL shortener?
A URL shortener turns a long web address into a short link. The short link redirects to the long address. The service stores the mapping between the two.
The design starts with two operations. Shortening takes a long URL and returns a short code. Redirecting takes a short code and returns the long URL.
A short code of seven characters gives far more codes than five years of growth need. The mapping store is the heart of the design. A cache in front of the store serves the common redirects.
Take 100,000,000 new short URLs a day as the working assumption. Dividing by 86,400 seconds gives about 1,157 writes per second. Five years of that rate stores 182.5 billion mappings. At 500 bytes per mapping, the store reaches 91.25 TB. Seven characters from 62 give about 3.5 trillion codes. Ten reads per short URL a day means about 11,600 redirect reads per second.
A counter plus base-62 encoding gives unique codes without a lookup. A random code needs a check for collisions. Either method works, and the counter method is simpler to reason about.
The Design a URL Shortener lesson and the Estimating Storage and Bandwidth lesson teach this idea.
36. How do you design a news feed?
A news feed shows each reader a list of posts from accounts they follow. The list is ordered newest first. The feed is the most-read page of the service.
Fan-out on write copies each post into the feeds of all followers. The copy happens once, at posting time. Reading a feed then needs no gathering step.
Fan-out on write costs storage. Twenty billion feed entries a day is the price of instant reads. A cache holds the newest entries for the most active readers.
Take 100,000,000 new posts a day and 200 followers per account. Each post is written 200 times, so 20 billion feed entries are written a day. At 100 bytes each, that is 2 TB a day. Fifty million readers open the feed 4 times a day. Each sees 20 posts. That is 4 billion posts a day.
Celebrity accounts break simple fan-out. One account with millions of followers turns one post into millions of copies. The fix is a hybrid: fan out to ordinary followers, and fetch celebrity posts at read time.
The Design a News Feed lesson and the Publish and Subscribe lesson teach this idea.
37. How do you design a chat system?
A chat system delivers messages between people in near real time. Each message is small. The hard part is scale, not size.
A connection server holds one long-lived connection per online user. Messages travel from sender to connection server to receiver. A message store keeps history for later reads.
Presence is a separate problem from messages. A presence service tracks which users are online. A message to an offline user waits in the store until the user returns.
Take 1,000,000,000 messages a day as the working assumption. Dividing by 86,400 gives about 11,600 messages per second, and three times that at peak is about 34,700. At 200 bytes each, a day of messages is 200 GB, and a year is 73 TB. Ten million users online at once, at 100,000 connections per server, need 100 connection servers.
Ordering matters inside one conversation. A sequence number per conversation keeps messages in order. The number also makes retries safe, because a duplicate number is ignored.
The Design a Chat System lesson and the Message Queues lesson teach this idea.
38. How do you design a key-value store?
A key-value store maps each key to one value. The operations are get, put and delete. Nothing else is required.
The store splits keys across shards by hashing the key. Each shard holds its own range of keys. Adding shards adds capacity.
Memory is fast and disk is slow. The track's latency lesson puts reading 1 MB from memory at 0.25 ms and from disk at 20 ms. Disk is 80 times slower, so hot keys live in memory.
Take 10,000,000,000 keys at 1,000 bytes per value. That is 10 TB of data, or 30 TB with three replicas. One million reads a second across 100 shards is 10,000 reads per second per shard.
Three replicas of each shard protect against a lost machine. A write goes to all three replicas. A read can use any replica, and a failed replica is rebuilt from the others.
The Design a Key-Value Store lesson and the Why Partition Data lesson teach this idea.
39. How do you design a rate limiter?
A rate limiter caps how many requests one user can make. The cap is stated per minute. Requests above the cap are refused.
The token bucket is the standard shape. The bucket holds tokens up to the cap. Each request spends one token, and tokens refill at a steady rate.
The counter needs one entry per user. A million users need only 16 MB of counter storage. The limiter sits in front of the service it protects.
Take a cap of 100 requests per minute per user. One million users at the cap together send 100,000,000 requests a minute, or 1,666,667 per second. Tokens refill at 100 divided by 60, or 1.67 per second.
A single limiter is a single point of failure. Two limiters need shared state, or one user can spend the full allowance twice. A central counter store keeps the count honest.
The Design a Rate Limiter lesson and the Design Sharded Counters lesson teach this idea.
40. How do distributed transactions and sagas work?
A distributed transaction spans more than one service. No single database can commit it. The saga pattern manages it as a sequence of local steps.
Each step has a compensating action that undoes it. A failure runs the compensations in reverse order. The system ends in a consistent state, not a half-finished one.
Two-phase commit is the stricter alternative. Every participant votes, then all commit together. A stuck participant blocks the rest, so sagas suit long business flows better.
Take an order with four steps. One million orders a day with 1% failing means 10,000 failed orders a day. Each failed order undoes two earlier steps, so 20,000 compensation actions run a day. Two-phase commit sends 8 messages per transaction: four participants times two rounds.
Idempotency makes retries safe. Each step carries a unique request key. A repeated key returns the first result instead of running twice.
The Sagas and Distributed Transactions lesson and the Idempotency lesson teach this idea.
41. How do consensus, leader election and the replicated log work together?
Consensus is agreement among nodes that cannot all talk at once. Leader election picks one node to decide. The replicated log records the decisions in order.
A majority is the rule. Five nodes need three votes to elect a leader. Two nodes can fail and the other three still form a majority.
The leader appends entries to the log. Followers copy the entries in the same order. Every node ends with the same log, so every node agrees on history.
One million log entries a day at 1,000 bytes each is 1 GB per node. Across all five nodes, that is 5 GB.
A new leader starts by collecting the longest log. An entry is committed once a majority holds it. The log is the source of truth, and the leader is only its writer.
The Consensus and Leader Election lesson and the The Replicated Log lesson teach this idea.
42. How do failure detection and gossip work?
Failure detection asks one question: is this node still alive. Gossip answers it without a central watcher. Each node shares what it knows with a few random peers.
Gossip spreads news fast. A node that stops answering is suspected after a few missed rounds. Suspicion is not proof, so a suspected node can rejoin.
A full mesh would need every node to check every other node. Gossip needs only a few messages per node per second. The saving grows as the cluster grows.
Take 100 nodes. Each node gossips with 3 peers, so 300 gossip messages fly per second. A full mesh would need 100 times 99, or 9,900 messages per second. Gossip sends 33 times fewer messages. A silent node is suspected after 3 missed one-second rounds, or 3 seconds.
Anti-entropy repairs drift after a failure. Nodes compare summaries of their data and copy the missing parts. The comparison uses a compact digest, not the full data.
The Failure Detection and Gossip lesson and the Anti-Entropy and Merkle Trees lesson teach this idea.
43. How do vector clocks and versioning work?
A vector clock tracks the history of a value. Each replica keeps one counter per node. The counters together describe which writes happened before which.
Two versions conflict when neither clock contains the other. The system keeps both versions. The conflict is resolved later, by a rule or by a person.
A version needs one counter per replica. Five replicas mean five counters per version. The metadata is small beside the value it describes.
Five counters at 8 bytes each is 40 bytes per key. One million keys carry 40 MB of version metadata.
Versioning beats last-writer-wins for shopping carts and profiles. A lost update is worse than a visible conflict. The reader sees both versions and picks.
The Vector Clocks and Versioning lesson and the Hinted Handoff and Read Repair lesson teach this idea.
44. How do you design for failure?
Designing for failure starts from a blunt fact. Machines fail, networks split, and disks die. The design must keep working through all three.
A network partition splits the cluster into sides. Only the side with a majority keeps writing. The smaller side stops, because two writers would diverge.
A lease gives one node the right to act for a fixed time. A fencing token only ever rises. A writer with an old token is refused, even if it still thinks it holds the lease.
Availability is measured in downtime per year. Three nines allow 8.76 hours a year. Four nines allow 52.6 minutes a year.
The Split-Brain and Partitions lesson and the Fencing and Leases lesson teach this idea.
45. How do you design a pastebin in five minutes?
Pastebin stores text and returns a link. The text is the whole product. Reads outnumber writes by a wide margin.
Five minutes allows one sketch. A short key identifies each paste. The paste body goes to object storage, and the key goes to a database row.
Ten million pastes a day at 10 KB each is 100 GB a day. A year of pastes is 36.5 TB. Old pastes expire, or the store grows without end.
Ten reads per paste means about 1,157 reads per second.
The read path is a cache lookup by key. A miss reads the database, then the object store. The write path is one insert plus one object upload.
The Design Pastebin lesson and the Blob and Object Storage lesson teach this idea.
46. How do you design a trending-topics feed in five minutes?
A trending-topics feed lists the subjects rising fastest right now. The list refreshes every few minutes. The count is the whole problem.
Five minutes allows one sketch. Each post adds one to the counter of each hashtag it carries. The counters live in memory, keyed by hashtag and time window.
Thirty million counter writes a day is about 347 per second. One machine handles that easily. The top ten per window comes from sorting a million counters.
Take 10,000,000 posts a day. Five-minute windows give 288 windows a day. One million distinct hashtags at 8 bytes per counter is 8 MB per window.
Old windows expire and free their memory. A topic trends when its count rises fast, not when its total is large. The rate of change is the signal.
The Design Trending Topics lesson and the Design a Top-K Leaderboard lesson teach this idea.
47. How do you design a unique ID generator in five minutes?
A unique ID generator hands out numbers that never repeat. The numbers sort by time. No two machines may hand out the same number.
Five minutes allows one sketch. A 64-bit ID splits into time, machine and sequence. Forty-one bits hold the time, ten bits hold the machine, and twelve bits hold the sequence.
Twelve sequence bits give 4,096 IDs per machine per millisecond. Ten machine bits allow 1,024 machines. The whole fleet issues about 4.2 billion IDs per second.
Forty-one time bits cover about 69.7 years. The clock is the risk: a machine with a clock set backwards must wait. A machine with no clock must not issue IDs.
The Design a Unique ID Generator lesson teaches this idea.
48. How do you design a distributed cache in five minutes?
A distributed cache holds hot data in memory across many machines. A hit avoids the database. A miss reads the database and fills the cache.
Five minutes allows one sketch. Keys hash to cache nodes, so each key has one home. A billion keys at 1 KB each is 1 TB, or 10 GB on each of 100 nodes.
A 90 percent hit rate cuts database reads by a factor of ten. The database sees one request in ten. Memory serves a megabyte in 0.25 ms, against 20 ms from disk.
One billion requests a day at a 90 percent hit rate leaves 100,000,000 for the database. Disk is 80 times slower than memory.
A dead node loses its keys. The keys rehash to the surviving nodes. The database absorbs the extra reads until the cache refills.
The Design a Distributed Cache lesson and the Eviction and Invalidation lesson teach this idea.
49. How do you design a notification system in five minutes?
A notification system tells users something happened. The message is short. The fan-out is the whole problem.
Five minutes allows one sketch. Each event writes one row per recipient. A queue carries the rows to the sender, which delivers by push, email or text.
One hundred million users receive 5 notifications each a day. That is five hundred million notifications a day, or about 5,787 per second. A busy hour runs five times hotter, at about 28,900 notifications per second. One popular account can create a million rows from a single event.
A million rows at 5,787 writes per second takes about 173 seconds. Slow fan-out is acceptable for a notification. It is not acceptable for a payment.
The Design a Notification System lesson and the Publish and Subscribe lesson teach this idea.
50. How do you design a ride-hailing dispatch in five minutes?
Ride-hailing dispatch matches riders with nearby drivers. The match must be fast. The map is the whole problem.
Five minutes allows one sketch. The city divides into square cells. Each driver reports position every five seconds, and each cell holds the drivers inside it.
Ten thousand drivers across 100 cells is 100 drivers per cell. Two thousand position updates arrive per second. A rider's request searches the rider's own cell first.
One hundred thousand rides a day is 10 rides per driver per day. That is about 1.2 requests per second on average, and about 5.8 at peak.
The nearest driver is not always the best match. A driver finishing a trip nearby may beat a free driver further away. The score weighs distance, direction and wait time.
The Design Uber lesson and the Design a Proximity Service (Yelp) lesson teach this idea.
Questions readers ask
How do I plan a week with this sheet?
Cover one group a day, in order. Speak your own answer first, then read the one here. Draw each design on paper. Keep the last day for the five-minute walkthroughs and any questions left over. A little each day beats one long night before interview day.
Must I memorise the numbers?
No. Interviewers check the method, not the memory. What matters is dividing a daily total by 86,400, multiplying items by size, and stating each assumption in the open. The numbers on this page show the method. Recompute them yourself and the method sticks.
What if I have never designed a system before?
Start with the Beginner course, then come back. The framework questions and the estimation questions teach the method the rest of the sheet uses. The classic designs in the Intermediate and Classics courses show the method applied end to end.
Why are all the numbers round?
Round numbers keep the arithmetic visible. Real systems use messier figures. The method stays the same. State the assumption, show the arithmetic, and check the result. Change an assumption and the answer moves in the open.