System Design Handbook · llms.txt

Reference

Practice questions

Reading about system design teaches you the parts. Answering questions out loud teaches you to use them. This chapter is a bank of questions to practise on, with pointers to the chapters that help and to articles that show how real companies solved the same problem.

Here is one way to practise a question, say "Design a chat app like WhatsApp":

  1. Set a timer for 45 minutes. That's about how long a real interview gives you.
  2. Follow the four steps from The system design interview, step by step: outline use cases and constraints, sketch a high-level design, design the core components, then scale it.
  3. Say your estimates out loud. How many messages a day, how many people online at once, how much storage a year. Write the arithmetic down as you go, the way you would on a whiteboard. The estimation chapter and numbers to know help here.
  4. Compare. When the timer stops, read the worked design if the handbook has one, or the references listed with the question. Note what you missed and what you'd do differently.

The chapter has four parts:

  • Worked designs in this handbook lists every question the handbook answers in full, with what each one teaches. Start there: you can check your answer against a complete design laid out in the same four steps.
  • More system design questions groups further questions by theme. For each one you'll find what makes it hard, which chapters help, and references that are still online.
  • More object-oriented design questions covers class-design questions, where you write the classes and methods for one program instead of drawing a distributed system.
  • How to practise with these gives a simple plan, a checklist for reviewing your own answers, and tips for practising with a partner.

Worked designs in this handbook

These chapters each take one question from requirements to a scaled design. The system design chapters follow the same four steps you'll use in an interview, so you can compare your answer with one laid out the same way.

System design questions

QuestionWhat it teaches
Design a text-sharing service like PastebinKeeping small records (code, expiry) apart from the larger text they point to, cleaning up expired data, and serving a read-heavy service. Also asked as "Design Bit.ly", which is closer to the URL shortener below.
Design the Twitter timeline and searchWhere to do the work for a feed: when a post is written (fan-out on write) or when a timeline is read, and what to do about accounts with millions of followers. Also asked as "Design the Facebook feed and search".
Design a web crawlerManaging a to-do list of billions of links, skipping duplicate pages, and crawling politely without overloading any one site.
Design a personal finance tracker like MintPulling data from outside systems in background workers, categorising it, and splitting a write-heavy workload from the reads users see.
Design the data structures for a social networkFinding the shortest path between two people when friend lists are spread across many servers, while keeping the number of network calls small.
Design a key-value cache for a search engine's query resultsAn in-memory cache with least-recently-used eviction, spread over many machines, with a plan for hot keys and stale results.
Design Amazon's sales rank by categorySeparating a large, slow batch job that computes an answer from a small, fast path that serves it.
Design a system that scales to millions of users on AWSGrowing one site from a single server to many, one bottleneck at a time, and knowing when each fix is worth its cost.
Design a URL shortener (like TinyURL or Bitly)Generating short codes that never collide, choosing a redirect status code, sharding a table with billions of rows, and counting clicks cheaply.
Design a social media news feedPush versus pull feeds, caching feeds for hundreds of millions of users, paging through a list that keeps changing, and ranking.
Design a real-time gaming leaderboardAnswering "what's my rank?" among millions of players quickly, with sorted sets built on skip lists, and breaking ties fairly.
Design a payment system and gatewayMaking retries safe with idempotency keys, tracking each payment in a state machine, keeping a double-entry ledger, and reconciling with outside providers.
Design a collaborative document editorMerging edits that two people make at the same moment, with operational transformation or CRDTs, so every screen ends up showing the same text.
Design a web search engineBuilding an inverted index, splitting it across machines, and ranking results within a couple of hundred milliseconds.
Design a personalized recommendation systemNarrowing a catalog of millions of items to twenty in stages, so the expensive model only scores a few hundred candidates.
Design a distributed key-value storePartitioning, replication, quorums, conflict resolution and failure detection, all in one design.
Design a notification systemQueues, retries, deduplication and rate limits across several outside providers, without letting a marketing blast delay a login code.
Design a chat systemLong-lived connections, message ordering, delivery and read receipts, and keeping several devices per user in sync.
Design search autocomplete (typeahead)Separating an offline pipeline that builds suggestions from an online lookup that answers in milliseconds, and caching almost everything.
Design a video streaming platformUploading very large files reliably, transcoding in parallel, adaptive bitrate streaming, and why bandwidth cost shapes the design.
Design a file sync service (like Dropbox or Google Drive)Keeping strongly consistent file metadata apart from file content, splitting files into blocks, and handling conflicts from offline edits.

Object-oriented design questions

QuestionWhat it teaches
Design a hash mapTurning a key into an array index, handling collisions, and growing the table as it fills.
Design an LRU cacheCombining a hash map with a linked list so that lookups and evictions both take constant time.
Design a call centerEscalating work through a chain of employees and queuing callers when everyone is busy.
Design a deck of cardsModelling a general structure once and letting each game (such as blackjack) give it its own rules through inheritance.
Design a parking lotMatching vehicles of different sizes to spots, including a vehicle that needs several spots side by side.
Design a chat serverUsers, friend requests, private chats and group chats as classes, with rules about who may post where.

More system design questions

The handbook doesn't work these questions through in full. Each one lists what makes it hard, the chapters that cover the parts you'll need, and references that show how others have answered it. Most of them overlap with a worked design, so do that one first and then try the variation.

The references were checked when this chapter was written. Some are old. Treat the numbers in them as a snapshot of that time, and read them for the reasoning.

Storage, caching and file systems

Design a file sync service like Dropbox.

  • What makes it hard: file metadata must stay consistent across every device, while the file contents are large and need to move with as little bandwidth as possible. Two devices that edit the same file offline will conflict when they reconnect.
  • Chapters: Design a file sync service, NoSQL databases, CAP and consistency.
  • References: How We've Scaled Dropbox, a talk on Dropbox's growth posted on Stanford's YouTube channel.

Design a key-value store like Redis.

Design a cache system like Memcached.

Design a garbage collection system.

  • What makes it hard: this question is about the memory of one running program. The collector has to find every object the program can still reach, free the rest, and do it without pausing the program for too long.
  • Chapters: Design a hash map for practice with low-level data structures, and Performance and latency for the cost of long pauses.
  • References: Baby's First Garbage Collector, Bob Nystrom's short walk through a mark-and-sweep collector in C. Garbage Collection Algorithms, Rick Byers's 2007 University of Washington survey of collection algorithms. The original link now asks for a university login, so this is an archived copy.

Design a system that serves data from multiple data centers.

Design a content delivery network like Cloudflare.

Social, messaging and collaboration

Design a chat app like WhatsApp.

Design the Facebook chat function.

  • What makes it hard: presence. Telling every friend each time someone comes online, goes idle or leaves costs more than delivering the messages, and the cost grows with the size of friend lists.
  • Chapters: Design a chat system, Real-time communication, Queues and async work.
  • References: Facebook Chat, Eugene Letuchy's 2008 post on why presence was the costly part, and on the long-polling server written in Erlang. Erlang at Facebook, his 2009 slides on the chat architecture and its rollout.

Design a picture sharing system like Instagram.

Design the Facebook news feed function.

Design the Facebook timeline function.

Design Google Docs.

  • What makes it hard: two people can type into the same sentence at the same moment, each against a version of the text that doesn't include the other's edit. The system must merge both without locking and without losing either.
  • Chapters: Design a collaborative document editor, Real-time communication.
  • References: Differential Synchronization, Neil Fraser's 2009 paper on keeping copies of a document in sync with repeated diff and patch. google-mobwrite, the archived code of MobWrite, a web editor built on that algorithm.

Search, ranking and recommendations

Design a search engine like Google.

Design a scalable web crawler like Google's.

Design a graph search function like Facebook's.

Design a trending topic system like Twitter's.

Return the top k requests during a time interval.

Design a recommendation system like Amazon's.

Commerce, trading and games

Design a stock exchange (like NASDAQ or Binance).

Design an online multiplayer card game.

Infrastructure and building blocks

Design a tinyurl system like Bitly.

Design a random ID generation system.

  • What makes it hard: many servers must hand out IDs without talking to each other on every request, the IDs must never repeat, and they often need to sort roughly by time.
  • Chapters: Unique IDs, Consensus.
  • References: Announcing Snowflake, Twitter's 2010 post on the service it built to generate tweet IDs. twitter-archive/snowflake, the archived code.

Design an API rate limiter.

Newer questions to try

These questions come up often in interviews today. They have no references here, but each is close to a worked design, so you can check most of your answer against it.

QuestionWhat makes it hardChapters that help
Design a ride-hailing service's driver matchingFinding nearby drivers among millions of moving points, updated every few seconds.Real-time communication, NoSQL databases, Design a notification system
Design a ticket booking system for a big concertSelling each seat exactly once while a huge crowd arrives in the same minute.Distributed transactions, Rate limiting, Design a payment system
Design a distributed job schedulerRunning each job once and on time, even when the machine that was going to run it fails.Queues and async work, Consensus, Reliability patterns
Design a metrics and monitoring systemStoring a flood of small time-stamped numbers cheaply and answering queries over them quickly.Observability, Event streaming, NoSQL databases
Design a distributed message queueKeeping messages durable and in order while many producers and consumers come and go.Queues and async work, Event streaming, Consensus
Design an ad click counterCounting billions of clicks accurately enough to bill for them, without counting any click twice.Event streaming, Batch processing, Design Amazon's sales rank by category

More object-oriented design questions

In an object-oriented design question you design the classes, their fields and methods, and how they work together, for a program that runs on one machine. Start by listing the nouns in the problem (they become classes) and the verbs (they become methods). Then write the main methods in code.

Design a circular array.

A circular array is a fixed-size array whose end wraps around to its start. Picture a queue of the last 1,000 log lines: when line 1,001 arrives, it overwrites line 1 instead of growing the array.

  • Hint: store the items in a plain list plus a start offset. The item at logical position i lives at index (start + i) % capacity. Rotating the array by k then means only changing start, which takes constant time instead of moving every item. Decide what append does when the array is full (overwrite the oldest item, raise an error or grow), make the class iterable in logical order, and test the wrap-around at the end of the list.
  • Closest worked chapter: Design a hash map, which also maps positions into a fixed-size array with % and has to decide what to do when it fills up.

The questions below are common in interviews. They aren't worked through in the handbook, so use the hint and the closest chapter to check your approach.

QuestionHintClosest worked chapter
Design an elevator systemSeparate the elevator car (its floor, direction and stops) from the controller that decides which car answers each call.Design a call center, which also assigns incoming requests to whoever is free
Design a vending machineModel the machine as a set of states (idle, has money, dispensing) with the allowed moves between them.Design a parking lot
Design a library management systemBooks, copies of a book, members and loans are separate classes. A loan links one copy to one member with a due date.Design a parking lot, where spots, vehicles and levels play similar roles
Design a movie ticket booking systemTwo people must not book the same seat. Hold seats for a few minutes while someone pays, then release them.Design a parking lot
Design a chess gameA Piece base class with one subclass per piece type, each knowing its own legal moves. The board checks the rules that involve several pieces.Design a deck of cards, which uses the same base-class-and-subclass pattern
Design an in-memory file systemFiles and directories share a base class, and a directory holds children, which can be either. Paths are walked one name at a time.Design a hash map, for looking up children by name
Design a text editor with undo and redoStore each edit as an object that knows how to apply and reverse itself, and keep two stacks of them.Design an LRU cache, for another design built from two cooperating data structures

How to practise with these

A short plan you can keep up for a few weeks:

  1. One question a day. Pick a worked design first, answer it on your own with a 45-minute timer, then read the chapter. Once you've done a few, move on to the questions without worked answers.
  2. Then try the variation. After the URL shortener, try Pastebin. After the chat system, try Facebook chat. Most of the reasoning carries over, and the differences show you what matters in each.
  3. Revisit your weak spots. If your estimates were off, spend a day on estimation. If you couldn't scale the database, read relational databases and NoSQL databases again.

After each attempt, review your answer against this checklist:

  • Did I ask about use cases and scale before drawing anything?
  • Did I write down my estimates (requests per second, storage, read-to-write ratio) and use them later?
  • Did I give each component in my high-level design a reason to exist?
  • Did I go deep on the two or three parts that matter most for this question?
  • Did I name at least one bottleneck and fix it, and say what the fix costs?
  • Did I discuss what happens when a server, a database or a data center fails?
  • Did I compare at least two options for one important decision and say why I picked one?

Practising with a partner is closer to the real thing than practising alone. One person plays the interviewer and keeps the question vague at first, so the other has to ask. The interviewer answers questions about scale with numbers, pushes on one component ("what happens if this cache goes down?"), and keeps time. Afterwards, go through the checklist together, then swap roles. Playing the interviewer teaches you a lot too, because you see which answers are easy to follow.

Further reading

If you only read a few of the references above, start with these. Each one explains a decision you'll face again and again.

Previous: Numbers to know · Next: Real-world architectures