System Design in 40 Animated Lessons

Learn system design in 40 animated lessons. Explore load balancing, caching, databases, and queues, then design a URL shortener, news feed, and chat app.

What happens when a browser loads a page?

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.

Find the address (DNS)

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.

RFC 1034 — Domain Names: Concepts and Facilities

Open a connection

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.

Send the request

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 server asks the database

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 response comes home

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.

Course

Foundations

  • How a Request Travels

    Follow one page load hop by hop — and find out where the time really goes.

  • Latency & Throughput

    Two questions about speed — and why busy servers slow down before they’re full.

  • Napkin Math

    Turn a product idea into servers and terabytes with math that fits on a napkin.

Scaling

  • Vertical vs Horizontal

    Your one server is melting. Do you buy a bigger one, or more of them?

  • Load Balancing

    One front door for many servers — and the rules for who gets which request.

  • Stateless Services

    Why the next request must work on any server — and where the state goes instead.

  • Caching

    Keep the answers people ask for most somewhere much faster than the database.

  • Content Delivery

    Copy what everyone downloads to servers near your users — and stop fighting the speed of light.

Data & Storage

  • SQL vs NoSQL

    Tables, documents or plain keys — what each kind of database is good at, and what it gives up.

  • Indexes

    Why the same query can take two seconds or two milliseconds.

  • Storage Engines

    What a database actually does with your write — and why some are built for reads and others for writes.

  • Replication

    Keep copies of the database on several machines — for more reads and for survival.

  • Sharding

    When the data or the writes outgrow one machine, split them across many.

  • Consistent Hashing

    Add or remove servers and move only a sliver of the data.

  • Unique IDs at Scale

    Giving every row a name nobody else will ever use — without one counter everyone has to queue for.

  • CAP & Consistency

    When the network splits, copies of your data must choose between being right and being reachable.

  • Consensus & Leaders

    How a group of servers agrees on one leader and one history — even when some of them can’t be reached.

  • Transactions & Isolation

    Two people, one seat, the same millisecond. How databases keep concurrent changes correct.

  • Files & Media

    Photos and videos don’t belong in your database — where they go instead, and how they get there and back.

Communication

  • REST, RPC & GraphQL

    Three ways for programs to ask each other for things — and what each costs a phone on 4G.

  • Message Queues

    Answer right away, do the slow work later — and never lose a job along the way.

  • Pub/Sub & Events

    Announce that something happened, and let whoever cares react — without anyone waiting.

  • Real-time Updates

    How the server tells you something happened — chat, live scores, notifications.

Reliability

  • Redundancy & Failover

    Everything fails eventually. Design so that no single failure takes you down.

  • Rate Limiting

    Give every client a fair budget, so one runaway script can’t take everyone down.

  • Timeouts & Retries

    Calling a struggling service safely: give up in time, retry carefully, and know when to stop.

  • Observability

    Metrics, logs and traces: how to find out what’s wrong, where, and why — fast.

Architecture

  • Monolith vs Microservices

    One codebase or many services? What each buys you, what each costs, and how to move between them.

  • Service Discovery

    How services find each other when instances come and go — and one front door for everyone outside.

  • Sagas & Distributed Tx

    One action, several services, several databases: how to keep it all-or-nothing without one big transaction.

  • Batch & Stream Processing

    Crunching billions of events: overnight in big batches, or continuously as they arrive.

Security

  • Authentication

    Proving who someone is — without becoming the reason their password leaks.

  • Authorization

    Knowing who someone is doesn’t tell you what they may see or do. Checking that, everywhere.

  • Encryption & Secrets

    Protecting data on the wire, on disk, and the keys and passwords your services use.

Shipping

  • Testing

    Knowing a change is safe before your users find out — fast tests for the logic, a few slow ones for everything else.

  • CI/CD & Deployments

    Getting every change to production quickly and safely — and back out again just as quickly.

Whole Systems

  • HLD & LLD

    The same system at two zoom levels: the map of services, and the inside of one of them.

  • Design a URL Shortener

    A first end-to-end design: from a one-line brief to a system that serves billions of redirects.

  • Design a News Feed

    Posts from everyone you follow, in 200 ms — and the question of when to do the work.

  • Design a Chat System

    Twenty million open connections, and a promise: every message arrives, in order, exactly once.

Technical references