Learning path
Work through system design in order. Each step has an explanation with a picture. Most have a lab to try, and many have an interview problem to practise on.
No interview level is chosen, so every concept is shown the same way. Preparing for an interview? Choose a level to see which concepts matter most at it.
Find your starting point
Answer 12 questions taken from the lessons, two from each stage. It takes about 10 minutes. You then see which stages to skim and where to start.
Read down the line: each dot is one concept, in order. Start here A concept
You tap a friend's profile in an app. The app sends a request, GET /profile/42, to a computer in a data centre. That computer reads the profile from its database and sends it back. The app is the client: the side that asks. The computer in the data centre is the server: the side that waits for requests and answers them.
You type shop.example.com into a browser. The network cannot route to a name: it needs a number, such as 203.0.113.7. That number is an IP address. The Domain Name System (DNS) is the lookup service that turns the name into the address. The browser gets the address first, then connects to the server.
A protocol is an agreed set of rules for how two computers talk. When you open a web page, three of them work in layers. TCP carries the bytes and resends any that get lost, so they arrive in order with no gaps. TLS encrypts them. HTTP gives them meaning: a request such as GET /users/42, and a response with a status code. UDP is a lighter choice than TCP. It sends each packet once and does not wait to hear that it arrived. A packet may be lost, arrive out of order or arrive twice, so an app that needs more must add it itself.
A shopping app loads a product page: it asks once and gets one answer. A chat app is different: new messages must reach you without your app asking each time. An API style is the pattern an app and a server use to exchange messages. REST is ask-and-answer over HTTP. A WebSocket is one open connection where both sides can send. Server-sent events (SSE) let the server push updates one way. gRPC sends small binary messages, mostly between a company's own services.
Say one server handles 1,000 requests a second, and 1,500 arrive. You have two ways out. Vertical scaling, also called scaling up, moves the app to one larger machine, with a faster CPU and more memory. Horizontal scaling, also called scaling out, runs the app on 3 machines. A load balancer in front shares the requests between them.
The interviewer says one line: "Design a chat app like WhatsApp." You have about 45 minutes to work out, out loud, what to build and how its parts fit together. That is a system design interview. System design is the boxes and arrows: which services, databases, caches and queues you need, and how data moves between them. The classes and code inside one service are a different topic, called low-level design.
The interviewer says: "Design a chat app like WhatsApp." That one line hides two kinds of requirement. A functional requirement says what users can do: send a message, see who is online. A non-functional requirement says how well the system must do it. Each message arrives within 1 second, the service stays available 99.99% of the time, and nothing that was sent goes missing.
Say a shop's site finishes 200 requests each second. Most are answered in about 100 ms, a few take over half a second, and the site was down for one hour last month. Those are the three basic measures. Latency is how long one request takes. Throughput is how many requests the system finishes each second. Availability is the share of time it is up and answering.
Say 10 million people use an app each day, and each makes 10 requests. That is 100 million requests a day, or a little over 1,000 a second. Capacity estimation is this kind of quick sum. It turns a guess about users into requests per second, storage and bandwidth, so you can size the design.
Say a site runs on three servers, A, B and C, and 300 requests arrive each second. A load balancer is the part in front that receives every request and passes it to one of the three. Spread evenly, each server gets about 100 a second. If server B stops, the load balancer notices and shares the traffic between A and C.
Say an orders service must call a payments service, which runs as 3 copies at 10.0.0.1, 10.0.0.2 and 10.0.0.3. You could type those 3 addresses into the orders service. But tomorrow a copy is replaced and gets a new address, and the typed list is wrong. Service discovery fixes this with a registry: one place that keeps the list of live copies. Each copy tells the registry its address when it starts. The orders service asks the registry "where is payments?" and gets the current list. Each copy also sends a heartbeat, a short "I am alive" message every few seconds. When the heartbeats stop, the registry takes that copy off the list.
Say an app has a users service, an orders service and a search service. A phone should not need three addresses, and no service should face the internet directly. A reverse proxy is a server that takes each request from outside and passes it to a server inside. An API gateway is a reverse proxy that also does shared checks first. Is the login token valid? Is this client over its limit?
Asha logs in to a shop with her password. The server must remember her on the next click, without asking again. One way is a session: the server saves a record and gives her browser a random id, such as 7f3a. Another way is a signed token: a short note that says "this is Asha, until 10:15", with a signature only the server can make. Checking who someone is is called authentication. Deciding what they may do, such as view an order but not refund it, is called authorization.
A reader in Pune asks for cat.jpg, and the only copy is on a server in Virginia, about 12,900 km away. Every request crosses the world and back. A content delivery network (CDN) is a set of servers in many cities that keep copies of your files. The reader's request goes to a nearby one, here in Mumbai about 120 km away, and is answered from its copy.
Say your API allows each customer 100 requests a minute. One customer's script goes wrong and sends 5,000. A rate limiter counts the requests from each caller. It lets the first 100 through and rejects the rest with HTTP 429, which means "too many requests". The reply can say when to try again, so a well-behaved client waits.
Say the shop page for one popular item is opened 10,000 times. Each time, the app asks the database the same question and gets the same answer. A cache is a small, fast store that keeps a copy of that answer in memory, under a key such as item:1. While the copy is there, readers get it and the database is not asked.
Say item:1 is the most-read key in a shop's cache. Its TTL runs out, and the cache drops it. The next 100 requests for item:1 all miss, and all 100 read the database at the same moment. That burst is a cache stampede. Eviction is the other half of this lesson. When the cache is full, it must remove a key to make room, and the rule it uses decides which one.
Say you are building a shop. An order links to a customer, to products and to a payment, and all of them must agree. A relational (SQL) database fits this. It keeps data in tables, links rows by id, and can change several rows together or not at all. Now say you also store 50 million chat messages a day, and each read uses one key. A NoSQL store fits that. NoSQL is a loose name for stores that are not relational: key-value, document and wide-column. Most give up joins, and in return they spread data across many servers more easily.
A users table holds 1,000,000 rows, and the app wants the row for user 42. With no index, the database checks all 1,000,000 rows, one page after another. An index is a sorted structure, kept beside the table, that points to where each row is. With it, the database finds user 42 in a few reads. The storage engine is the part of the database that keeps tables and indexes on disk.
Say you move 100 from account A to account B. That is two writes: take 100 from A, then add 100 to B. If the app crashes between them, the money is gone. A transaction groups the two writes, so both happen or neither does. Other transactions run at the same time. The isolation level decides what each one sees of the others. Weaker levels are faster but let some mistakes through. Stronger levels stop more mistakes, and cost more waiting or retries.
A user uploads a 1,000 MB video. The bytes go to object storage: a large, cheap store that keeps each file whole under a key, such as videos/abc123.mp4. The facts about the file go in a database row: owner, name, size and that key. Amazon S3 is a well-known object store. Viewers later download the video through a CDN near them.
Say a shop's orders app must send an email after each order, and sending takes 2 seconds. With a queue, the orders app writes a short message, "order 81 paid", and answers the customer at once. A worker reads the message later and sends the email. Once the worker confirms it, a plain queue deletes the message. Kafka works another way. It adds each message to the end of a log and keeps it for a set time, read or not. Each reader remembers its own position in the log, called its offset. So several readers can each read every message, and a reader can go back and read old ones again.
Say a search box has seen seven queries, and card is the most typed, at 90 times. A user types c, then a. The box should offer card, car and care right away, without checking all seven. A trie makes that possible. It is a tree that adds one letter at each level, so everything beginning with ca hangs under a single node. Searching for whole words inside documents uses another structure, the inverted index. For each word it keeps the list of documents that contain it: cache is in documents 3, 17 and 42.
Say one database takes every read and write for an app, and it cannot keep up. Replication keeps full copies of the data on other servers, called replicas, and sends reads to them. Sharding splits the data instead: four servers, called shards, each store a quarter of the users. Each shard then handles only its own share of the load.
Say a cache runs on 10 servers, and you add an 11th. With hash(key) % 10, switching to % 11 sends about 10 keys in 11 to a different server. Consistent hashing puts both the servers and the keys on a ring of numbers instead. Every key is stored on the first server found going clockwise from it. Adding the 11th server then moves only about 1 key in 11: the ones that now meet the new server first.
A rider opens a ride app and asks for drivers within 1 km. The app could measure the distance to all 200,000 drivers in the city, but that is far too slow to do for every rider. A normal index sorts by one value, and a place has two: how far east and how far north. A geospatial index solves this by cutting the map into cells. Each cell keeps a list of what is inside it, so a search reads a few cells near the rider and skips the rest. A geohash is a short code for one cell of a fixed grid. A quadtree uses big squares in empty places and small squares in crowded ones.
Say the value x is stored on three replicas, and each one holds x = 1. The network splits, and replica 3 is cut off. Then a write sets x = 2, but only replicas 1 and 2 receive it. Now a reader asks replica 3. It can reply x = 1, which is out of date, or refuse until the link is back. If it replies, the system stays available. If it refuses, the system stays consistent. The CAP theorem says no system can do both while the network is split. PACELC adds the normal case: with no split, waiting for more replicas gives fresher answers but slower ones.
Every machine has its own clock, and no two agree exactly. Node B's clock might run 100 ms behind A's. If the newest timestamp wins, an edit made on B after seeing A's edit can still look older, and it is thrown away. Lamport clocks and vector clocks count events instead of reading the time, so an edit made after seeing another always sorts after it.
Say five servers each keep a copy of one log of writes. Server 1 is the leader: it takes every write, and it sends heartbeats to the other four to show it is alive. Then server 1 stops. Each of the others has a timer set to a random time between 150 and 300 ms. The server whose timer ends first asks the rest for votes. With 3 votes out of 5, a majority, it becomes the new leader. Getting a group of servers to agree like this is called consensus. Raft is one widely used set of rules for it.
Say two workers, client A and client B, both want to change the same record. A asks a lock service for the lock and gets it for 10 seconds. With the lock comes a number, 33. Then A's program freezes for 15 seconds. The lock runs out, so B takes it, gets the number 34 and writes. When A wakes up it knows none of this, and it sends its write with 33. The storage took a write with 34 a moment ago, so it turns 33 away. A lock with a time limit is called a lease. The rising number is called a fencing token.
Say an app calls a service and gets no answer. With a timeout, the app stops waiting after a set time and treats the call as failed. It then tries again, but not at once. It waits 250 ms before the first retry, 500 ms before the second and 1,000 ms before the third. This doubling is called exponential backoff. It stops after 3 retries and returns the error to its caller. Now say 100 apps failed at the same moment. They would all retry at the same moment too, so each picks a random wait up to the backoff time. That random part is called jitter.
Say an app calls a service through a circuit breaker. The breaker remembers the last 10 results. While most calls work, it is closed and passes every call through. Then the service starts to fail. Once half or more of the recent calls have failed, the breaker opens. For the next 5 seconds it does not call the service at all. Each call fails at once, and the app shows a fallback, such as a default list. After the 5 seconds it lets 3 trial calls through. If all 3 work, it closes again.
Say a web server calls an orders service, and the orders service calls a stock service. Then the stock service gets slow: an answer that took 50 ms now takes 5 seconds. The orders service has 20 workers, and each is now stuck for 5 seconds, so it finishes only 4 orders a second. If 6 orders arrive each second, 2 more join the line every second: 120 are waiting after a minute. The web server is waiting on the orders service, so its own pages start to time out. One slow service has become three. That spread is a cascading failure.
Say checkout gets slow at 9 p.m. Metrics tell you something is wrong: the error rate jumped. Traces tell you where: the payment service is slow. Logs tell you why: calls to the bank are timing out. A service level objective (SLO) says what "good enough" means, such as 99.9% of requests succeeding within 300 ms over 30 days. That leaves 0.1% that may fail, called the error budget. Over 30 days it comes to about 43 minutes of total failure.
Say a developer fixes the checkout button and saves the change. That saved change is called a commit. A pipeline is a fixed list of automatic steps that every commit goes through. It builds the code into one package, tests it, and tries it on a practice copy of the live system. Then it releases it to production, the servers that real users reach. Running these steps for every commit is called CI/CD: continuous integration and continuous delivery. A release can reach all six servers at once, or one server at a time. It can also go to a second set of servers, or to one server with 10% of the traffic first. If the new version fails, a rollback puts the old version back.
Say a table called users has a column called name, and the team wants to call it full_name. The app is live, and its code reads and writes name all day. If you rename the column in one step, the running code asks for a column that is gone, and its requests fail. The safe way is to add before you remove. Add full_name beside name. Change the code in small releases until nothing uses name. Then remove name. For a while the table holds both columns, so old code and new code can both work. This method is often called expand and contract.
An app needs more than its own code: the right version of Python, some libraries, some settings. A container image is one package that holds the app with all of that. So it runs the same on a laptop and on a server. A running image is called a container, and many containers can share one machine. Say you want 6 copies of your app on 3 machines. An orchestrator is the program that places them, starts a new copy when one dies, and keeps the number at 6. An autoscaler changes that number when traffic rises or falls.
Say a shop's app server needs the database password. If the password sits in the source code, everyone who can read the code can read the database. So can anyone with an old copy of the code. Security in a design is a set of choices like this one, made for each part. Where does each secret live? What is encrypted on the network and on disk? Who may reach each part? What stops abuse before it reaches the servers?
Say an account with 3 followers shares a photo. With push, the system writes the post into all 3 followers' feeds straight away: 3 small writes. When a follower opens the app, their feed is one ready list. Now a star with 10,000,000 followers posts. Push means 10,000,000 writes for that one post, and the last followers see it minutes late. With pull, nothing is copied at post time. A feed is put together only when its owner opens the app, by asking every account they follow. That makes opening slower. Copying one post out to many followers is called fan-out.
Say an ad system counts clicks in windows of 10 seconds. A user taps an ad at 8 s while their phone is in a tunnel, so the click reaches the counter at 14 s. It belongs in the 0–10 s window, and that window may already be closed. This is the hard part of stream processing: handling each event as it arrives, when events can arrive late or twice. Each event carries the time it happened, called its event time. Batch processing avoids the problem by running later, over stored data such as last night's logs.
Say a shop keeps 1,000,000 orders, and each order has 10 fields: the user, the amount, the country and so on. A row store keeps the 10 fields of one order side by side. Opening order 7 is one small read. A column store keeps each field in its own file, so all 1,000,000 amounts sit together. Adding up the amounts then reads one file and skips the other 9. Apps fetch and change single records, so they use row stores. Reports add up a few fields over many records, so they use column stores. A column store built for reports is often called a data warehouse.
Say a bank account starts empty, and the app asks to deposit 100. This request is called a command. The write side checks the rules and adds an event to a log: Deposited 100. Taking out 30 later adds another event, Withdrew 30. Nothing is overwritten. To get the balance, add up the log: 100 − 30 = 70. Storing changes this way is called event sourcing. Adding up a long log on every read would be slow. So a worker keeps a separate read view up to date from the events. Splitting writes from reads like this is called CQRS.
Say the orders service saves a new order and must tell other services about it. Those are two writes. If it crashes after the first and before the second, the message is never sent. With an outbox, the service saves the order and a row holding the message in one database transaction. A relay reads that row later and publishes it. The rest of the order is a saga of three steps, each in its own service. The card is charged, stock is reserved, and delivery is booked. If booking delivery fails, nothing rolls back on its own. The saga then undoes the finished steps, newest first: it releases the stock and refunds the card.
Say all writes go to a region called US East, and a second region, EU West, keeps a copy that runs 500 ms behind. US East fails while 1,000 writes arrive each second. The last 500 writes were confirmed to users but not yet copied, so they are lost. Health checks notice the failure after 3 seconds. Users' devices keep the old address for 5 more seconds, so users are down for about 8 seconds. Two targets describe a plan like this. The recovery point objective (RPO) is the amount of recent data you accept losing, measured in time. The recovery time objective (RTO) is how long the system may be down. This setup meets an RPO of half a second and an RTO of 8 seconds. Those times come from a sped-up lab, and a real failover often takes minutes.
Say a shop starts as one app with one database. The app holds orders, payments and search. Five developers can change, test and release it in one go. Later the team has grown, and everyone waits on the same release. Search now uses 10 times as many servers as everything else, and a crash in search takes orders and payments down too. The team then gives search a service of its own, which holds its own data. Architecture evolution is this habit: start with the simplest design, and change it only when a clear need appears. One app that holds everything is called a monolith. A system split into many small services is called microservices.
Say a photo app gets 300 million requests a month, and every one returns a photo of 200 KB. That is 60,000 GB sent out. At an example price of $0.08 a GB, the photos alone cost $4,800 a month, far more than its two servers. Cost and ownership is the habit of putting numbers like these on a design. You find the biggest line, and you decide who builds and runs each part.
Say a help app for a home router gets the question "How do I reset my router?". The app first searches the router's help pages, which are stored as six short chunks. It picks the two closest chunks. Then it sends the question and those chunks to a large language model (LLM), a program that writes text one small piece at a time. The model answers from chunk c1, which says to hold the reset button, and it names c1 as its source. This pattern is called retrieval-augmented generation (RAG): retrieve the text first, then generate the answer from it. The parts around it are ordinary system design: search, caching, streaming and limits.
Want to learn how AI features are built? The AI engineering track starts from the basics.