System Design
The building blocks, then real designs, the way interviews ask them. Free, step by step: every lesson is complete, with an animation, a worked example and exercises with answers.
Unit 0: How system design interviews work
Learn the step-by-step way to answer any design question before you learn the parts. Without a method, even good knowledge comes out messy under pressure.
- Meet the building blocks: a map of a typical web system: Most large web systems are built from the same dozen parts, connected in a familiar shape: clients, DNS, a CDN, load balancers, app servers, caches, databases, queues, workers and object storage.
- The high-level design interview: a step-by-step answer framework: A repeatable order of steps for answering any 'Design X' question in about 45 minutes.
- Back-of-the-envelope estimation: Quick, rough maths to estimate traffic, storage and bandwidth, so your design decisions are based on scale.
- The low-level design interview: a step-by-step approach: A repeatable way to answer 'Design the classes for X' (a parking lot, an elevator, Splitwise) and write the key code.
Unit 1: Networking and APIs
Understand how a request travels from a phone or browser to your servers and back, and how to design the API it calls.
- Client–server, DNS, and what happens when you type a URL: Clients (browsers, apps) send requests; servers process them and send responses. DNS turns a name like example.com into an IP address the client can connect to.
- HTTP and REST API design: HTTP is the request–response protocol of the web. REST is a style of API design built around resources (nouns) and standard methods (GET, POST, PUT, PATCH, DELETE).
- Real-time communication: polling, long polling, WebSockets, SSE: There are four ways for a server to get new data to a client quickly. The client keeps asking (polling), waits on an open request (long polling), keeps a two-way connection open (WebSockets), or receives a one-way stream (server-sent events, SSE).
- CDN (content delivery network): A network of servers around the world that caches static content (images, video, scripts) close to users.
- Proxies, reverse proxies and API gateways: A reverse proxy sits in front of your servers and receives requests on their behalf. An API gateway is a reverse proxy with API features: authentication, rate limiting and routing to the right service.
Unit 2: Core concepts: scale, reliability and speed
The ten ideas every high-level design uses: scalability, availability, fault tolerance, load balancing, caching, consistency and CAP, rate limiting, asynchronous processing, and observability.
- Scalability: vertical vs horizontal: Scalability is a system's ability to handle more load by adding resources.
- Availability: nines, SLAs and redundancy: Availability is the share of time a system works and responds correctly, usually written in 'nines', like 99.9%.
- Fault tolerance: timeouts, retries, circuit breakers: Fault tolerance means the system keeps working, perhaps in a reduced way, when parts of it fail.
- Load balancing: A load balancer spreads incoming requests across several servers and stops sending traffic to unhealthy ones.
- Caching: A cache keeps a copy of frequently used data in fast storage, usually memory, so it can be served without repeating slow work.
- Consistency, CAP and PACELC: Consistency (in distributed systems) means every read sees the latest write. The CAP theorem says that during a network partition, a system must choose between consistency and availability.
- Rate limiting and backpressure: Rate limiting caps how many requests a client can make in a time window. Backpressure is a system telling the senders upstream to slow down when it's overloaded.
- Asynchronous processing and message queues (Kafka, SQS): Asynchronous processing means doing slow work later, outside the user's request. A message queue holds the work, or events, between the service that produces them and the services that consume them.
- Observability: logs, metrics and traces: Observability is how well you can understand what a system is doing from the outside, using logs, metrics and traces.
Unit 3: Data: databases, storage and scaling data
Choose the right database, keep data correct with transactions, make queries fast with indexes, and scale data with replication and sharding.
- SQL vs NoSQL: choosing a database: SQL (relational) databases store data in tables with a fixed schema and support joins and transactions. NoSQL is a family of other models: key-value, document, wide-column and graph.
- ACID transactions and isolation levels: A transaction groups several operations so they succeed or fail together. ACID stands for Atomic, Consistent, Isolated, Durable.
- Database indexing: An index is an extra data structure that lets the database find rows without scanning the whole table.
- Replication: Replication keeps copies of the same data on several machines.
- Partitioning and sharding: Sharding splits a large dataset across several databases (shards), each holding part of the data.
- Consistent hashing: Consistent hashing assigns keys to servers so that adding or removing a server moves only a small share of the keys.
- Object storage (S3) for files and media: Object storage keeps files ('objects') such as images, videos and backups as a key pointing to bytes plus metadata, in a cheap, very durable, almost unlimited store like Amazon S3.
- Search: inverted indexes and Elasticsearch: Full-text search finds the documents that contain some words and ranks them by relevance. It's built on an inverted index: a map from each word to the documents containing it.
- Unique ID generation: Generating IDs that are unique across many servers, without one shared database counter.
Unit 4: Distributed systems and security
How services split up and stay correct across a network, how machines agree, and how to keep users and data secure.
- Monolith vs microservices: A monolith is one deployable application. Microservices split the system into small services, each owning one business capability and its own data, talking over the network.
- Distributed transactions: sagas and the outbox pattern: A saga runs a business process across several services as a series of local transactions, with a compensating action to undo each step if a later step fails.
- Consensus and leader election (Raft): Consensus is getting several machines to agree on a value — such as who the leader is, or the order of operations — even when some of them fail.
- Security basics: authentication, authorisation, OAuth and JWT: Authentication checks who you are. Authorisation checks what you're allowed to do.
Unit 5: Low-level design: OOP and SOLID
The building blocks of good class design: the four pillars of OOP, composition over inheritance, the five SOLID principles, class diagrams, and the concurrency basics LLD questions expect.
- OOP: the four pillars: Object-oriented programming organises code into objects that bundle data and behaviour. Its four pillars are encapsulation, abstraction, inheritance and polymorphism.
- Composition over inheritance, and interfaces: Composition means building a class out of other objects it has ('has-a'), instead of inheriting from a parent ('is-a').
- SOLID: S — Single Responsibility Principle: A class should have one reason to change: one job.
- SOLID: O — Open/Closed Principle: Code should be open for extension but closed for modification: add new behaviour by adding code, not by editing code that already works.
- SOLID: L — Liskov Substitution Principle: Objects of a subclass must work anywhere the parent class is expected, without breaking the program.
- SOLID: I — Interface Segregation Principle: Clients shouldn't be forced to depend on methods they don't use. Prefer several small, focused interfaces over one big one.
- SOLID: D — Dependency Inversion Principle: High-level code should depend on abstractions, not on concrete low-level details.
- UML class diagrams and relationships: A class diagram shows the classes, their fields and methods, and how they relate to each other.
- Concurrency basics: threads, locks and race conditions: Concurrency is several tasks making progress at the same time. A race condition is a bug where the result depends on the exact timing between them.
Unit 6: Design patterns
Ten patterns that come up again and again in LLD interviews and real code: three for creating objects, three for structuring them, and four for behaviour.
- Singleton: Makes sure a class has only one instance, and gives one global way to reach it.
- Factory: Factory Method and Abstract Factory: A factory creates objects for you, so the calling code asks for 'a notifier' without knowing which concrete class gets built.
- Builder: Builds a complex object step by step, instead of using a constructor with a dozen parameters.
- Adapter: Lets two incompatible interfaces work together, by wrapping one so it looks like the other.
- Decorator: Adds behaviour to an object by wrapping it in another object with the same interface, without changing the original class.
- Facade: Gives one simple interface to a complicated set of classes.
- Strategy: Puts a family of interchangeable algorithms behind one interface, so you can choose one at runtime.
- Observer: Lets objects subscribe to another object's events, and get notified automatically when something happens.
- Chain of Responsibility: Passes a request along a chain of handlers; each one either deals with it or passes it on to the next.
- State: Lets an object change its behaviour when its internal state changes, by putting each state's behaviour in its own class.
Unit 7: Low-level design questions
Practise the classic LLD questions end to end: requirements, classes, patterns, the key code and concurrency.
- Design a parking lot: Design the classes for a multi-floor car park that assigns spots, issues tickets and charges fees.
- Design an elevator system: Design the classes and scheduling logic for a building's lifts.
- Design Splitwise (expense sharing): Design an expense-sharing app where friends split bills and can see who owes whom.
- Design a vending machine: Design a vending machine that sells items, accepts coins and gives change.
- Design an LRU cache: Design a fixed-size cache that removes the least recently used item when full, with get and put in O(1).
- Design an order-matching engine (stock exchange): Design the core of a stock exchange: an order book that matches buy and sell orders.
Unit 8: High-level design questions
Practise the classic HLD questions with the full framework: requirements, estimates, API, data model, design, deep dives and trade-offs.
- Design a URL shortener (like bit.ly): Turn long URLs into short links, like bit.ly/x7Kp2a, that redirect to the original.
- Design a distributed rate limiter: A service that limits how many requests each client can make, enforced consistently across many API servers.
- Design a notification system: Send notifications (mobile push, SMS, email) to users reliably, at large scale.
- Design a chat app (like WhatsApp): One-to-one and group messaging, with delivery receipts and online status.
- Design a news feed (like Twitter or Instagram): Show each user a feed of recent posts from the people they follow.
- Design a video streaming platform (like YouTube or Netflix): Upload, process and stream videos to millions of viewers.
- Design a ride-hailing app (like Uber): Match riders with nearby drivers in real time, track trips and charge fares.
- Design a payment system: Process payments reliably: charge customers, record every money movement, and never lose money or charge twice.
- Design search autocomplete: Suggest the top completions as the user types into a search box.
- Design a real-time leaderboard: Show live rankings of players by score, including each player's own rank.
- Design a distributed cache: A shared in-memory key-value cache, like Redis or Memcached, spread across many machines.
Unit 9: AI and ML system design
The design questions AI and ML engineer interviews ask: RAG assistants, recommendations, fraud detection, LLM serving, and the pipeline that trains and ships models.
- Design a RAG assistant over company documents: A chat assistant that answers employees' questions from the company's own documents, with sources.
- Design a recommendation system: Recommend items (videos, products, posts) that each user is likely to engage with.
- Design a real-time fraud detection system: Score every card transaction for fraud within milliseconds, and block or flag the risky ones.
- Design an LLM serving platform: Serve large language models to many applications with low latency and cost.
- Design an ML training and feature pipeline: The platform that turns raw data into trained, deployed and monitored models, again and again.