Learn system design in 40 animated lessons. Explore load balancing, caching, databases, and queues, then design a URL shortener, news feed, and chat app.
For a first visit over TCP and TLS, the browser resolves the domain, opens a secure connection, and sends an HTTP request. The server returns the response, and the browser renders the page.
Networks route by numeric IP address, not by name. So the browser first asks a DNS resolver: where is shop.example?
The answer — 203.0.113.7 — comes back in about 20 ms.
Now the browser opens a connection to 203.0.113.7. A TCP handshake agrees to talk; a TLS handshake sets up encryption. Each needs a round trip — there and back.
Here a round trip takes 30 ms, so connecting costs 60 ms before a single byte of the page is requested.
Over the open connection the browser sends GET /products. The server parses it, checks the session and runs your code.
That costs one more round trip plus ~10 ms of server work.
The products don’t live in the web server — they live in a database. The server sends a query and waits for the rows to come back.
Watch a request travel all the way in and the response all the way out.
The server turns rows into HTML and sends it back; downloading it takes another 20 ms. The browser renders the page — 155 ms after you pressed Enter.
Then it notices images and stylesheets in the page and fires off more requests. Reusing the open connection saves them the handshake.
Follow one page load hop by hop — and find out where the time really goes.
Two questions about speed — and why busy servers slow down before they’re full.
Turn a product idea into servers and terabytes with math that fits on a napkin.
Your one server is melting. Do you buy a bigger one, or more of them?
One front door for many servers — and the rules for who gets which request.
Why the next request must work on any server — and where the state goes instead.
Keep the answers people ask for most somewhere much faster than the database.
Copy what everyone downloads to servers near your users — and stop fighting the speed of light.
Tables, documents or plain keys — what each kind of database is good at, and what it gives up.
Why the same query can take two seconds or two milliseconds.
What a database actually does with your write — and why some are built for reads and others for writes.
Keep copies of the database on several machines — for more reads and for survival.
When the data or the writes outgrow one machine, split them across many.
Add or remove servers and move only a sliver of the data.
Giving every row a name nobody else will ever use — without one counter everyone has to queue for.
When the network splits, copies of your data must choose between being right and being reachable.
How a group of servers agrees on one leader and one history — even when some of them can’t be reached.
Two people, one seat, the same millisecond. How databases keep concurrent changes correct.
Photos and videos don’t belong in your database — where they go instead, and how they get there and back.
Three ways for programs to ask each other for things — and what each costs a phone on 4G.
Answer right away, do the slow work later — and never lose a job along the way.
Announce that something happened, and let whoever cares react — without anyone waiting.
How the server tells you something happened — chat, live scores, notifications.
Everything fails eventually. Design so that no single failure takes you down.
Give every client a fair budget, so one runaway script can’t take everyone down.
Calling a struggling service safely: give up in time, retry carefully, and know when to stop.
Metrics, logs and traces: how to find out what’s wrong, where, and why — fast.
One codebase or many services? What each buys you, what each costs, and how to move between them.
How services find each other when instances come and go — and one front door for everyone outside.
One action, several services, several databases: how to keep it all-or-nothing without one big transaction.
Crunching billions of events: overnight in big batches, or continuously as they arrive.
Proving who someone is — without becoming the reason their password leaks.
Knowing who someone is doesn’t tell you what they may see or do. Checking that, everywhere.
Protecting data on the wire, on disk, and the keys and passwords your services use.
Knowing a change is safe before your users find out — fast tests for the logic, a few slow ones for everything else.
Getting every change to production quickly and safely — and back out again just as quickly.
The same system at two zoom levels: the map of services, and the inside of one of them.
A first end-to-end design: from a one-line brief to a system that serves billions of redirects.
Posts from everyone you follow, in 200 ms — and the question of when to do the work.
Twenty million open connections, and a promise: every message arrives, in order, exactly once.