System Design Fundamentals
Learn how big software systems are planned, step by step. Each topic has an easy example, a real-world example, colourful diagrams and, where it helps, a visualizer you can play with.
Part 1: Foundations
The big ideas, the network basics and the first building block (load balancers). Start here.
Introduction
9 topicsPlanning how the parts of a software system fit together, so it works for millions of people.
The big picture: the main parts of a system, what each one does, and how data flows between them.
The inside of one part: classes, responsibilities, interfaces and the patterns that keep code easy to change.
What the system must do, and how well it must do it. The first thing to ask in any design.
Quick maths for requests per second, storage and bandwidth, before you design anything.
How fast memory, disk and network really are, and why those gaps shape every design.
Three words for promises about reliability: what you measure, what you aim for, and what you promise.
What a running program really is: processes, threads and the memory they use.
A fast map of the 30 ideas that appear again and again in every system design talk.
Core Concepts
13 topicsHandling more users and more data by adding resources, without breaking.
How much of the time your system is up and working. Measured in nines.
Giving the right answer, every time, even when parts fail.
One part that, if it breaks, stops the whole system.
Three different ways to talk about 'fast'. Do not mix them up.
Spread data over servers so adding or removing a server moves very little data.
When the network breaks, a distributed system must choose: stay consistent or stay available.
Keep working when parts break, by having spare copies of everything important.
Switch to a backup when the main system fails: active-passive and active-active.
Does the server remember you between requests? This choice decides how easily you can scale.
Juggling many tasks versus doing many at once, and the bugs it brings: race conditions and deadlock.
Work out how much hardware you will need before the traffic arrives.
When a consumer is too slow, push back on the producer instead of letting everything pile up.
Networking
12 topicsSeven layers that explain how a message travels from your app to another computer.
The street address of a device on a network. IPv4, IPv6, public, private and subnets.
Safe and ordered, or fast and light? Two ways to send data.
The language browsers and servers use to talk, and how HTTPS keeps it secret.
The phone book of the internet: turns names like google.com into IP addresses.
A middle-man for clients, versus a middle-man for servers.
A small number that helps you check if data was changed or damaged.
How HTTP got faster: reusing connections, multiplexing, and QUIC over UDP.
How browsers remember you, and the rules that decide which websites may call which servers.
Carve a network into pieces, write address ranges the short way, and share one public IP.
Rules that block unwanted traffic, and a private tunnel across the public internet.
The door numbers on a machine, and the connections that pass through them.
Load Balancing
9 topicsThe traffic police that shares requests between many servers.
Round robin, least connections, hashing: how a load balancer picks a server.
Share traffic by giving different IP addresses to different users.
Many servers share one IP address, and the network sends you to the nearest.
Balance by connection, or read the request and balance by what it asks for.
How a load balancer finds out that a server is sick, and stops sending it traffic.
Send the same user to the same server every time, and why that is a trade-off.
Send users to the best region of the world, and move away from one that fails.
Two popular load balancers and reverse proxies, and how you configure them.
Part 2: APIs and Communication
How programs talk to each other: API design, keeping APIs safe, real-time updates and background messaging.
API Design
10 topicsA menu and a waiter: a clear way for one program to ask another for something.
Request-response, streaming and event-driven: the main ways APIs talk.
Doing the same request twice should not charge the customer twice.
JSON, XML, Protobuf and more: how data is written down to travel over a network.
Three popular API styles, and how to choose between them.
Return big lists a page at a time, and let clients narrow and order them.
Change an API without breaking the apps that already use it.
Tell the caller clearly what went wrong, and whether to try again.
A written contract for your API that people, docs and tools can all read.
Handle many items in one call, and send big files without tying up your servers.
API Security
11 topicsLimit how many requests one user can make, so nobody can overload the system.
Who are you? And what are you allowed to do?
Does the server remember you, or do you carry a pass?
A signed pass with your details inside, which a server can check without a database.
Let an app use your account safely, without ever giving it your password.
Log in once, and use many apps.
A simple secret that tells an API which app is calling, and how to handle it safely.
The login layer on top of OAuth2: it tells an app who the user is.
A trick that makes your browser send a request you never meant to send, and how to stop it.
Never trust what arrives: check and clean every input, to stop injection and bad data.
Prove who is calling and that the message was not changed, using certificates or signatures.
Real-Time Communication
8 topicsAsk the server, and it waits to answer until it has news.
The server keeps one door open and pushes updates to you.
A two-way phone call between browser and server.
Instead of you asking again and again, the other system calls you when something happens.
Video, voice and data sent straight between two browsers.
Ask again and again on a timer. Simple, but wasteful. The baseline to compare the others with.
Reach a phone even when the app is closed, through the phone maker's push service.
A tiny publish-subscribe protocol for IoT devices with weak batteries and weak networks.
Asynchronous Communication
11 topicsA line of tasks waiting for a worker, so users do not have to wait.
Publish once and every subscriber gets a copy.
The post office that stores, routes and delivers messages (Kafka, RabbitMQ, SQS).
At most once, at least once or exactly once: what a message promise really means.
A safe place for messages that keep failing, so they do not block everyone else.
Topics, partitions, offsets and consumer groups: how Kafka stores and delivers a huge stream of events.
Try again after a growing wait, with a little randomness, so retries help instead of hurt.
Two popular queues: a flexible broker you run, and a managed queue in the cloud.
A log you can replay, or a queue that hands out each task once? How to choose.
When order matters, how to keep it, and what it costs in speed.
Hand slow work to background workers, and run jobs on a timetable.
Part 3: Caching
Keep popular data close and ready, so systems answer faster and databases stay calm.
Caching Basics
7 topicsKeep a copy of popular data in a fast place, so you do not fetch it from the slow place every time.
Cache-aside, read-through, write-through, write-back: who fills the cache, and when?
The cache is full. Which item do we throw out? LRU, LFU, FIFO and more.
How to remove or refresh old data so users do not see stale answers.
Let browsers and proxies reuse a response, and ask cheaply whether it is still fresh.
Two popular in-memory caches: a simple fast one, and a richer one with data structures.
A cache inside each server, or one shared cache for all of them? Speed against consistency.
Distributed Caching
7 topicsCopies of your files kept in many cities, so users get them from a nearby server.
Spread a cache over many machines (like Redis or Memcached) so it can grow and survive failures.
A popular item expires and thousands of requests hit the database at the same moment.
Fill the cache before users arrive, so the first visitors are not slow.
One key gets far more traffic than the rest, and the one cache node holding it melts.
Requests for data that does not exist, and many keys expiring together: two ways a cache fails to protect you.
Upload files to the CDN yourself, or let it fetch them from your server on the first request?
Part 4: Data and Storage
Where data lives: the main kinds of databases, how they are built inside, how to scale them, and where big files are stored.
Database Basics
11 topicsA quick map of the main kinds of databases and what each one is good at.
Tables with strict rules, or flexible shapes that scale out? How to choose.
All-or-nothing changes that keep your data correct, even when things crash.
The tree that lets a database find one row among millions in a few steps.
Write fast to memory, flush to sorted files, and merge them later.
How much can two transactions see of each other? Dirty reads, repeatable reads and the levels that stop them.
Pessimistic and optimistic locking, and how MVCC lets readers and writers work without blocking each other.
Store each fact once, by splitting data into tables, so it cannot disagree with itself.
Many small updates for live apps, or a few huge questions for analysts: two very different workloads.
The relaxed cousin of ACID, and a fuller rule than CAP that also counts latency.
Write the change to a log first, so a crash never loses it. The trick behind durability and replication.
Database Types (Deep Dive)
11 topicsTables, rows, keys and joins: the classic way to store connected data (PostgreSQL, MySQL).
Store each record as a flexible JSON-like document (MongoDB, DynamoDB).
A giant dictionary: give a key, get a value, very fast (Redis, DynamoDB).
Search words inside text, with ranking, using an inverted index (Elasticsearch).
Rows with flexible columns, spread over many machines, built for huge writes (Cassandra, Bigtable).
Built for data stamped with time: metrics, sensors and logs (InfluxDB, TimescaleDB).
Store things and the links between them, and walk those links quickly (Neo4j).
Find items that are similar in meaning, using numbers called embeddings.
SQL and transactions like a classic database, with scale-out like NoSQL (Spanner, CockroachDB).
Store data column by column, so analytics reads only what it needs and compresses well.
Keep the data in RAM for microsecond answers, and decide how to survive a restart.
Database Scaling
16 topicsA shortcut so the database does not read every row to find the one you want.
Cut one big table into smaller pieces that are easier to manage.
Keep copies of your data on several machines for safety and read speed.
Split the data across many databases, so no single one holds everything.
Make slow queries fast: read the plan, add the right index, fetch less.
Copy data on purpose to avoid slow joins, and pay for it with extra writes.
Save the answer of a heavy query as a table, and refresh it when needed.
Reuse a small set of database connections instead of opening a new one every time.
Leader-follower, multi-leader and leaderless: who is allowed to accept a write?
Followers are always a little behind. What users see because of it, and how to cope.
Ask enough replicas on reads and writes that they must overlap, so you always see the latest write.
Pick the key that decides where data lives, avoid one overloaded shard, and grow without downtime.
When the data you need lives on different shards: scatter-gather, and ways to avoid it.
How much data can you lose, how long can you be down, and how to plan for a whole region failing.
Rewind a database to the minute before the mistake, using a backup plus the log.
Move old data to cheaper storage, or let it expire automatically, so the main database stays small.
Storage Systems
8 topicsA raw disk in the cloud, split into fixed blocks (EBS, SAN).
One big file system spread over many machines (HDFS, GFS).
Store files as objects with a key, in near-endless space (Amazon S3).
Survive lost disks using clever maths, with less extra space than full copies.
Keep busy data on fast, costly storage and old data on slow, cheap storage.
Combine several disks to be faster, safer or both: striping, mirroring and parity.
Store the same data in less space, by squeezing it or by keeping only one copy of repeats.
A shared folder that many machines can mount, with the files and folders you already know.
Part 5: Architecture
How whole systems are shaped: the big architecture styles, and the patterns that keep many small services working together.
Architectural Patterns
16 topicsOne side asks, the other side answers: the oldest and most common shape of a networked app.
Build the whole app as one piece that is built, deployed and run together.
Split an app into small services that each do one job and can be deployed on their own.
Write functions, let the cloud run them on demand, and pay only while they run.
Parts of the system react to events instead of calling each other directly.
No central server: every machine is both a client and a server (BitTorrent, blockchains).
Keep business rules in the middle and plug the outside world in through ports and adapters.
Use one model to write data and a different one to read it.
Store every change as an event, and rebuild the current state by replaying them.
Model the software around the business: shared language, bounded contexts, aggregates and events.
Stack the app in layers (presentation, business, data) where each layer only talks to the one below.
Pack an app with everything it needs into one light, portable box that runs the same everywhere.
A system that runs, scales, heals and updates your containers across many machines.
Keep rules independent of frameworks, and split one deployable app into clear modules before you split it into services.
Serve many customers from one system while keeping their data apart, and their noisy neighbours in check.
Where cloud machines live (regions and availability zones), and why some work runs near the user at the edge.
Microservices Patterns
14 topicsHow services find each other when machines and addresses keep changing.
One front door for all clients that routes, secures and limits requests to the services behind it.
A separate backend shaped for each kind of client, such as web and mobile.
Run a helper next to your service to handle logging, security or networking for it.
Stop calling a failing service for a while, so one failure does not spread.
Split resources into separate compartments so one overload cannot sink the whole ship.
Replace an old system piece by piece, until nothing of the old one remains.
A layer of sidecar proxies that handles service-to-service traffic, security and metrics.
Each service owns its data and nobody else touches it, so services can change and scale on their own.
Never wait forever: set a limit on every call, and pass the remaining time down the chain.
Build one answer by calling several services and combining the results in one place.
A translator at the border that keeps an old or foreign model from leaking into your clean design.
A helper next to your service that makes the outside calls for it: retries, routing, monitoring.
Handle the same message twice without doing the work twice, by remembering what you already processed.
Part 6: Distributed Systems
What changes when many machines work together: failures, clocks, agreement, and keeping data correct across services.
Distributed System Fundamentals
8 topicsWhy many machines are harder than one: slow networks, partial failures and no shared clock.
Machines can fail by stopping, by going silent, or by lying. Which kind you expect decides the whole design.
When the network splits the machines into groups that cannot talk to each other.
Two parts of a system both think they are in charge, and both accept writes.
Small regular 'I am alive' signals that let others notice when a machine stops.
The part that guesses which machines are dead, and why every guess can be wrong.
Timeouts, retries, backoff and fallbacks: living with parts that break.
The rules for what a reader may see after a write: strong, eventual and the ones in between.
Time and Ordering
7 topicsEvery machine has its own clock, and they never agree exactly.
How machines ask a time server for the time, and why the answer is only good to a few milliseconds.
Order events by counting them instead of trusting the wall clock.
A simple counter rule that gives every event an order that respects cause and effect.
One counter per machine, so you can tell if two events were related or happened at the same time.
A clock that looks like real time but keeps cause and effect in order, by mixing wall time with a counter.
A clock that says "the time is between here and here", and a database that waits out the doubt.
Coordination and Consensus
13 topicsHow a group of machines agrees on one value, even when some of them fail.
The classic consensus algorithm: propose, promise, accept.
Consensus made easier to understand: one leader, a replicated log, and elections.
How a group picks one machine to lead, and picks a new one when it fails.
Small, highly reliable stores that other systems use for locks, leaders, config and who-is-alive.
Let only one machine do a job at a time, across many machines (and why that is hard).
A number that grows with every lock, so storage can reject a client that woke up too late.
Spread news like a rumour: each machine tells a few random others.
Data types that can be changed on many machines and always merge to the same result.
How collaborative editors like Google Docs merge edits made at the same time.
Make unique IDs on many machines at once without asking a central counter every time.
Why two machines can never be fully sure the other got the last message.
Reaching agreement even when some machines lie. The idea behind PBFT and blockchains.
Distributed Transactions
8 topicsWhy 'all or nothing' across several databases or services is so hard to get.
A coordinator asks everyone to prepare, then tells everyone to commit or abort.
2PC with an extra step so a crashed coordinator does not leave everyone stuck.
A chain of local transactions, with a 'compensating' step to undo each one if something fails.
Reserve first, then confirm or cancel. A distributed transaction built from three business-level steps.
You cannot roll back something that already committed, so you undo it with a new action.
Save the change and the event in one local transaction, then publish the event safely.
What it really takes for an effect to happen once: idempotence, transactions and dedupe working together.
Part 7: Advanced Data Topics
Clever data structures that make huge systems fast and small, and the ways big data is collected, stored and processed.
Data Structures for Scale
6 topicsThe word-to-documents list behind every search box: how it is built, stored, compressed and queried.
A tree where each step is one letter, so finding every word that starts with 'ca' is instant. The heart of autocomplete.
Build an LRU cache with a hash map and a doubly linked list, so get and put both take O(1).
Always get the biggest (or smallest) item fast. Used for schedulers, top-K and merging sorted streams.
One bit per item to store and combine huge sets of IDs, and the Roaring trick that keeps them small.
A fixed-size queue that wraps around and overwrites the oldest data. Fast, simple and never grows.
Geospatial Structures
4 topicsTurn a place on the map into a short text code, so nearby places share the same start.
Split the map into four squares again and again, only where there are many points.
Group nearby shapes inside boxes, and boxes inside bigger boxes, to search maps fast.
Cut the whole Earth into cells (squares or hexagons) used by Google, Uber and others.
Probabilistic and Other Structures
7 topicsSay 'definitely not here' or 'maybe here' using very little memory.
Like a Bloom filter, but you can also delete items.
A sorted list with express lanes, so search is fast without a tree (used in Redis).
Count how often things appear in a huge stream, using a tiny fixed amount of memory.
Count the number of different items in a huge set with just a few kilobytes.
A tree of hashes that lets two machines find exactly which data differs, fast.
Estimate how similar two big sets are by comparing tiny fingerprints.
Big Data Processing
14 topicsProcess data in big chunks later, or one event at a time as it arrives.
Read every change made in a database and send it on to other systems.
Split a huge job into small map tasks and then combine the results with reduce tasks.
Extract data from sources, transform it, and load it where it can be analysed.
One big, cheap place to keep raw data of every kind, to decide what to do with it later.
A database built for analysis: clean, organised data for reports and dashboards.
A data lake with warehouse features on top: tables, transactions and fast queries.
Run a batch path and a speed path side by side, then merge their answers.
Use only a stream path, and replay the log when you need to recompute.
The engines that process endless streams of events (Kafka Streams, Flink, Spark Streaming).
The big data toolbox: HDFS to store, YARN to schedule, MapReduce and Spark to compute.
Describe a pipeline as tasks and dependencies, and let a scheduler run, retry and monitor it.
Store data column by column in files, so analytics read less and compress better.
Who owns the data, who may use it, and one shared place for the inputs of machine learning models.
Part 8: Operations and Security
How software is shipped safely, how you see what it is doing in production, and how you protect it and its data.
Deployment Patterns
15 topicsA map of the ways to put new code into production, and the risk each one carries.
An automatic line that builds, tests and ships every code change.
Replace old servers with new ones a few at a time, so the service never stops.
Run two full copies of production, then switch the traffic from one to the other.
Send the new version to a small slice of users first, and grow it only if it looks healthy.
Turn features on or off with a switch, without deploying new code.
Show different versions to different users and measure which one wins.
Change the shape of a live database safely, without breaking the running app.
Go back fast when a release fails, and never patch servers in place.
Run the system in several regions at once, so users stay served when a whole region goes dark.
Describe servers, networks and databases in files, and let a tool build and change them for you.
Add and remove servers by rules (target, step, schedule, prediction) so capacity follows the load.
Ship new code with no failed requests: draining, health gates and changes that old and new can share.
Break things on purpose, in a controlled way, to find weak spots before real failures do.
Try new code with real traffic and no user impact, by copying requests or hiding the feature.
Observability
11 topicsLogs, metrics and traces: three views that together explain what a system is doing.
What to log, how to structure it, and what to never write down.
Collect logs from every machine into one place that you can search.
Add counters, gauges and histograms to your code, so you can measure how it behaves.
Follow one request through many services and see where the time went.
Watch the system, and wake a human only when something really needs them.
One screen to see health at a glance, and a step-by-step guide for when it goes wrong.
Turn reliability into a budget you can spend, and use burn-rate alerts to know when you are overspending.
How a team handles an outage: roles, on-call, communication, and learning without blame.
Find out which code uses the time and memory: CPU profiles, flame graphs and continuous profiling.
A tamper-resistant record of who did what and when, for security, compliance and investigations.
Advanced Security
14 topicsThe handshake and encryption that keep a connection private and prove who you are talking to.
Scramble stored data, so a stolen disk or backup is useless without the key.
Keep passwords, API keys and certificates out of code, and hand them out safely.
Store user passwords safely with salting and slow hashes, and handle resets well.
Give permissions to roles, then give roles to people.
An XML-based way for a company login to sign users in to other apps.
A tour of the most common web attacks (injection, XSS, broken access control) and how each is stopped.
Floods of fake traffic that try to knock a service over, and the layers that absorb them.
A filter in front of your app that reads HTTP requests and blocks known attack patterns.
How a chain of trusted authorities lets you believe a public key really belongs to who it says.
Prove who you are with two or more different things: know, have, are. Codes, apps, keys and passkeys.
Never trust a request because of where it comes from. Verify every user, device and call, every time.
Create, store, use, rotate and retire encryption keys safely, with a service that never shows the key.
Collect less, protect it, let people see and erase their data: the engineering side of privacy law.
Part 9: Estimation and Interview Method
How to turn everything above into a clear answer: ask the right questions, do the maths out loud, follow a steady method, and explain your choices.
Requirements and Estimation
2 topicsThe questions to ask first, how to set the scope, and how to turn a vague prompt into a short list you can design for.
Worked estimates for real designs (a chat app, a video site, a URL shortener) and the shortcuts that keep them quick.
Interview Method
2 topicsA steady path through any design question: clarify, estimate, sketch, detail, scale, check failures, and sum up.
How to find what will break first, compare options out loud, and justify a choice without sounding unsure.
Part 10: Case Studies
Full interview walk-throughs, easiest first. Each one follows the order of a real interview: clarify, estimate, design, go deep, scale, and wrap up, with the cross-questions you will be asked and model answers.
Easy
6 topicsTurn long links into short ones (like bit.ly) and redirect fast. The classic first design question.
Let people paste text, get a link, and share it. Like the URL shortener, but with big content to store.
Stop any one user from sending too many requests, across many servers, without slowing everyone down.
Make billions of unique, roughly time-ordered IDs on many machines with no central bottleneck.
Build a simple, fast, always-on store like Dynamo or Redis: partitioning, replication and consistency.
Track free spaces in many lots, guide drivers to a spot, and never sell the same space twice.
Medium
11 topicsOne-to-one and group messaging that feels instant: connections, delivery, ordering and offline users.
Show each user a ranked stream of posts from people they follow, fast, even for celebrities.
Send push, SMS and email to millions of users: queues, retries, preferences and no duplicates.
Visit billions of pages politely: a frontier of URLs, duplicate detection and traps.
Suggest the best completions after every keystroke, in a few milliseconds.
Store and sync files across devices: chunks, deduplication, sync and sharing.
Upload, transcode and play video smoothly for millions, on any device and network.
A cache across many machines: partitioning, eviction, replication and hot keys.
Rank millions of players in real time: top-K, a player's own rank and time windows.
Run jobs at the right time, exactly when needed, even when machines fail.
Profiles, friends, posts, likes, comments and privacy for billions of people, stitched into one platform.
Hard
10 topicsMatch riders with nearby drivers in real time: location tracking, dispatch, pricing and trip state.
Move money correctly: idempotency, a double-entry ledger, reconciliation and no lost or double charges.
Sell a limited inventory fairly: holds, double-booking, flash-sale traffic and payments.
Crawl, index and rank billions of pages, and answer a query in milliseconds.
Show a map, find the fastest route and estimate arrival time for a whole planet of roads.
Let many people edit one document at the same time and always end up with the same text.
Collect millions of data points a second, store them cheaply, query them fast and alert on them.
A durable, ordered log that millions of messages a second flow through, with replication and consumer groups.
Catalog, search, cart, stock, checkout and orders for millions of shoppers, with no overselling and no lost orders.
Pick the few items worth showing out of millions: candidates, ranking, fresh feedback and cold start.