The system design interview: a repeatable approach

How system design interviews are run, and a five-step approach to repeat: requirements, rough numbers, API, data and scaling, with two worked examples.

Updated About 8 minutes to read

On this page

The video

Design Uber

Open the video page

Chapters

  1. Play from 0:00Most traffic is driver locations
  2. Play from 0:09How much traffic to expect
  3. Play from 0:20Load balancer and gateway
  4. Play from 0:32Keeping live locations in memory
  5. Play from 0:48Finding nearby drivers with cells
  6. Play from 1:05Matching and sending the offer
  7. Play from 1:21Growing by region
  8. Play from 1:34Recap: three ideas

Transcript

Show the whole transcriptHide the transcript
  1. Play from 0:00

    How would you build a ride app like Uber that handles millions of requests per minute?

  2. Play from 0:05

    Most of that traffic comes from drivers sending their location.

  3. Play from 0:09

    Say one million drivers are online.

  4. Play from 0:12

    Each phone sends its position every four seconds.

  5. Play from 0:15

    That is two hundred fifty thousand writes per second, or fifteen million per minute.

  6. Play from 0:20

    First, every request reaches a load balancer.

  7. Play from 0:23

    It spreads the traffic over many copies of an API gateway.

  8. Play from 0:28

    The gateway sends each request to a small service with one job.

  9. Play from 0:32

    The location service keeps only the latest position of each driver.

  10. Play from 0:36

    It holds that in memory, in a fast store like Redis.

  11. Play from 0:40

    Matching does not need old positions, so we skip the disk.

  12. Play from 0:43

    A copy goes to an event log like Kafka, for maps and billing later.

  13. Play from 0:48

    Now a rider asks for a car.

  14. Play from 0:50

    Checking every driver in the world would be far too slow.

  15. Play from 0:54

    So we split the map into cells.

  16. Play from 0:56

    Uber uses hexagon cells from its open source library, H3.

  17. Play from 1:00

    To find nearby drivers, we look only at the rider's cell and its neighbors.

  18. Play from 1:06

    The matching service ranks those drivers by arrival time.

  19. Play from 1:09

    It offers the trip to the best one.

  20. Play from 1:11

    The offer goes out over an open WebSocket connection, so the phone gets it right away.

  21. Play from 1:16

    When the driver accepts, the trip service saves the trip in a database.

  22. Play from 1:21

    To grow, we split the system by region.

  23. Play from 1:23

    Drivers in one city rarely matter to another city, so each region gets its own servers.

  24. Play from 1:29

    More traffic means more copies of each service behind the load balancer.

  25. Play from 1:34

    So the design rests on three ideas.

  26. Play from 1:37

    Keep live locations in memory.

  27. Play from 1:39

    Search by map cells.

  28. Play from 1:40

    Push offers over open connections.

In a system design interview, you're asked to sketch how a large service could work. "Design a URL shortener." "Design a ride app like Uber." There is no single right answer. The interviewer wants to see how you think: what you ask, what you estimate, which parts you pick, and how you explain the trade-offs. A fixed set of steps helps you cover what they look for.

How the interview is run

The details differ by company, but the shape is usually the same.

  • One open question. You get a short prompt, often only a product name. Filling in the details is part of the test.
  • You lead. The interviewer acts like a teammate or a client. They answer questions and push on parts of your design.
  • You draw. You sketch boxes for the parts of the system and arrows for the requests between them, on a whiteboard or a shared screen.
  • Time is short. Sessions are often 45 to 60 minutes, including introductions. Plan your time.
  • Talk out loud. The interviewer can only judge what they hear, so explain each choice as you make it.

They judge whether you pin down the problem, sketch a sound design, go deep on one or two parts, and know what each choice costs.

The approach in five steps

Use the same five steps every time. The times in brackets suit a 45-minute session.

1. Requirements (about 5 minutes)

Ask questions and write the answers down where the interviewer can see them.

  • What it must do. Pick the 2 to 4 core features. Say out loud what you leave out.
  • How well it must do it. How many users? How fast must a response be? Is it fine if some data is a few seconds old? What happens if a part fails?

The second list shapes the design more than the first. A service that must never lose a payment is built very differently from one that shows a rough count of likes.

2. Rough numbers (about 5 minutes)

Work out a few numbers, rounded freely. They tell you which part of the system needs the most care.

  • Requests per second, split into reads and writes.
  • Storage per day and per year.
  • One handy fact: a day has 86,400 seconds. Round it to 100,000 when you only need a rough size.

Say each assumption out loud. The interviewer cares more about your method than the exact figure.

3. API (about 5 minutes)

List the few requests the outside world makes. An API (application programming interface) is the set of requests a service accepts, with what goes in and what comes back. Keep it to the core features.

4. Data (about 5 minutes)

Say what you store, how you look it up, and what kind of database fits. A key-value store is a database that finds one value by its key, very fast, like a giant map. A relational database stores tables you can join and query in many ways. Pick by how the data is read.

5. Draw it, then scale it (about 20 minutes)

First draw the simplest design that works: the phone or browser, a server, a database. Then use your numbers to find what breaks first, and fix that.

The usual tools:

  • A load balancer spreads requests over many copies of a server.
  • A cache keeps popular answers in memory, so most reads skip the database.
  • Sharding splits data across machines by a key, so each machine holds a part.
  • Replication keeps copies of data, for safety and for more reads.
  • A queue or event log lets slow work happen later, without making the user wait.

Spend most of this time going deep on one or two parts. Name the trade-off of each choice.

Wrap up (the last few minutes)

Sum up the design in a few sentences. Say what would fail first, and what you'd improve with more time.

Worked example 1: a URL shortener

This follows the URL shortener video.

Requirements. Turn a long link into a short one. When someone opens the short link, send them on to the long one. Our target is one million requests a second.

Rough numbers. Most traffic is people opening links. Assume 99% are reads. That leaves 1% writes:

What Number
Writes per second 1,000,000 × 1% = 10,000
New links per day 10,000 × 86,400 = 864 million
Storage per day, if a link takes about 500 bytes about 432 GB

The 500 bytes is a guess. Real links vary.

How long the codes need to be. With lowercase letters, uppercase letters and digits, each character has 62 choices. Seven characters give 62⁷, about 3.5 trillion codes. At 864 million a day, that lasts about 11 years. Six characters would run out in about 66 days.

API.

  • POST /links with the long link. It answers with the short code.
  • GET /{code}. It answers with a redirect, a reply that tells the browser to open the long link.

Data. Each code and its long link go into a key-value store. The data is sharded by code, so every lookup goes to one machine.

Making codes without clashes. A counter service hands each app server a block of numbers, say a million at a time. The server turns its next number into a base 62 code. Two servers never get the same number, so no database check is needed.

Scaling reads. A load balancer spreads requests over many app servers. They ask a cache first, because a small set of popular links gets most clicks. Only a cache miss reaches the database.

A trade-off to mention. A 301 redirect tells browsers the move is permanent, so they may remember it and skip the service on repeat clicks. A 302 sends every click back through the service, so you can count clicks, at the cost of more traffic.

One more: codes made from a counter are easy to guess. If links should be private, shuffle the numbers first or add random characters.

Worked example 2: a ride app like Uber

This follows the Uber video.

Requirements. Riders ask for a car. The app finds nearby drivers and offers the trip to one. Most traffic comes from drivers sending their location.

Rough numbers. Assume one million drivers are online, and each phone sends its position every 4 seconds. That is 250,000 writes a second, or 15 million a minute.

API.

  • Drivers send their position: POST /drivers/{id}/location.
  • Riders ask for a trip: POST /rides.
  • Offers go out to drivers over an open WebSocket connection. A WebSocket stays open, so the server can push a message to the phone the moment it has one.

Data. Matching only needs each driver's latest position. Keep it in memory, in a fast store such as Redis, and skip the disk. Send a copy to an event log such as Kafka for maps and billing later. Save trips in a database, because they must not be lost.

Finding nearby drivers. Checking every driver in the world is far too slow. Split the map into cells instead. To find drivers near a rider, look only at the rider's cell and its neighbors. Uber uses hexagon-shaped cells from its open source library, H3.

Scaling. Split the system by region. Drivers in one city rarely matter to another city, so each region gets its own servers. More traffic means more copies of each service behind the load balancer.

The code in JavaScript

Two small pieces of code make these ideas concrete.

Short codes from numbers

const ALPHABET = "0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

function toCode(id) {
  let code = "";
  do {
    code = ALPHABET[id % 62] + code;
    id = Math.floor(id / 62);
  } while (id > 0);
  return code;
}

function fromCode(code) {
  let id = 0;
  for (const ch of code) id = id * 62 + ALPHABET.indexOf(ch);
  return id;
}

toCode(125); // "21", because 125 = 2 × 62 + 1
fromCode("21"); // 125
toCode(62 ** 7 - 1); // "ZZZZZZZ", the last 7-character code

Drivers by map cell

This uses square cells to keep it short. Cells measured in degrees get narrower away from the equator, so real systems use cells of more even size, like H3's hexagons.

const SIZE = 0.01; // cell size in degrees, roughly 1 km north to south

const cellOf = (lat, lng) => `${Math.floor(lat / SIZE)}:${Math.floor(lng / SIZE)}`;

const cells = new Map(); // cell -> set of driver ids
const where = new Map(); // driver id -> cell

function updateDriver(id, lat, lng) {
  const cell = cellOf(lat, lng);
  if (where.get(id) === cell) return;
  cells.get(where.get(id))?.delete(id); // leave the old cell
  if (!cells.has(cell)) cells.set(cell, new Set());
  cells.get(cell).add(id);
  where.set(id, cell);
}

function driversNear(lat, lng) {
  const row = Math.floor(lat / SIZE);
  const col = Math.floor(lng / SIZE);
  const found = [];
  for (let dr = -1; dr <= 1; dr++) {
    for (let dc = -1; dc <= 1; dc++) {
      for (const id of cells.get(`${row + dr}:${col + dc}`) ?? []) found.push(id);
    }
  }
  return found.sort();
}

updateDriver("ana", 40.7128, -74.006);
updateDriver("ben", 40.7135, -74.0012);
updateDriver("cy", 40.7306, -73.9352); // a few km away
driversNear(40.713, -74.004); // ["ana", "ben"]

How to judge the cost

Programmers describe cost with Big-O notation. It says how the work grows as the input grows. O(1) means the work stays the same however big the input gets. O(n) means it grows in step with n.

  • A key-value lookup by code is about O(1), however many links there are.
  • Scanning every driver to find nearby ones is O(n) in the number of drivers. The cell lookup reads 9 cells, so its work depends only on the drivers near the rider.

Common mistakes

  • Drawing boxes before asking questions. Requirements decide the design. Start there.
  • Skipping the numbers. Without them, you can't say whether you need a cache, shards or ten regions.
  • Building for scale you don't have. If the numbers fit on one database, say so, and say when that would stop being true.
  • Ignoring the read and write split. The URL shortener is mostly reads, and the ride app is mostly writes. They need different tools.
  • Single points of failure. If one box going down stops everything, add a copy or explain the risk.
  • Naming tools without reasons. "Kafka" is not an answer. "An event log, so billing can read positions later without slowing matching" is.

Practice problems

LeetCode has a few coding problems that touch the same ideas. They're good warm-ups.

  1. LeetCode 535, Encode and Decode TinyURL. The URL shortener as code.
  2. LeetCode 146, LRU Cache. The kind of cache that keeps the most recently used items.
  3. LeetCode 355, Design Twitter. A small news feed.
  4. LeetCode 981, Time Based Key-Value Store. A key-value store that keeps old values with a time.

Then practice the five steps out loud on open prompts: a rate limiter, a chat app, a news feed, or a file storage service.

In short

Run every system design interview the same way: requirements, rough numbers, API, data, then draw it and scale it. Let the numbers tell you which part is hard, go deep there, and name the trade-off of each choice.

Want a video for a different problem?

Type a problem, a pattern or a system to design. You get a narrated video like the one above, usually ready in 5 to 9 minutes.

3 free videos with your own AI key. An AI key is a code from an AI company, such as Anthropic or OpenAI. Your own AI account pays for the writing. See pricing

Make a video