A complete system-design track: storage fundamentals first, then distribution (replication, sharding, consensus), then the applied building blocks (caching, queues, rate limiting), ending in twelve full case studies. Read top to bottom — prev/next follows this order. Cases marked with a playground link have a steppable, animated simulator.
Each case follows the same skeleton: requirements → capacity estimation → API design → data model → high-level design → deep dives → bottlenecks. Three have interactive simulators.
Theory path
- Database Indexes
- Hash Indexes
A hash index is the simplest durable index you can build. The storage engine keeps an in-memory hash map from each key t
- B-Tree Indexes
A B-Tree keeps keys sorted in fixed-size pages (nodes), typically 4–16 KB to match disk blocks and SSD pages. Internal p
- LSM Trees and SSTables
A Log-Structured Merge-tree splits the index into a small mutable in-memory part and many immutable on-disk parts. Write
- Indexes Conclusion
btitle["B-TREE (in-place)<br/>InnoDB / Postgres"]
-
- Transactions
- ACID Transactions
Atomicity — all-or-nothing across multiple writes, even across retries and crashes. Transfer 100 from A to B = debit(A)
- Read Committed Isolation
Read committed provides exactly two promises:
- Snapshot Isolation
Every row version carries creator/deleter transaction IDs (xmin/xmax in Postgres). At BEGIN, the transaction records the
- Write Skew and Phantom Writes
Rota rule: at least one doctor on call at all times. Alice and Bob are both on call. Two concurrent transactions, one pe
- Serial Execution and Achieving ACID
Serializability is the strongest isolation level and the only one with a one-sentence definition: the effect of concurre
-
- Database Internals
- Two-Phase Locking
Two phases, strictly ordered per transaction:
- Serializable Snapshot Isolation
Snapshot Isolation fails exactly on predicate anomalies (Write Skew and Phantom Writes): disjoint writes, invisible phan
- Column-Oriented Storage
An orders table with 50 columns where the query needs 3 (SUM(amount) GROUP BY region): a row store reads all 50 columns'
- Data Serialization Frameworks
svc(["Service emits event<br/>10 fields"])
-
- Replication
- Intro to Replication - Need to knows
Q: Why replicate a database at all?
- Single Leader Replication
Last write: 80, was written to the replication log.
- MultiLeader Replication - chaos
As an alpha sigma Male myself, not a big fan of having multiple leaders. Clearly, such a setup is destined to fail and h
- Leaderless Replication
In leaderless replication, there is no single leader node that coordinates write operations. Instead, write operations c
- Quorums
If there are n replicas, every write must be confirmed by w nodes to be considered successful, and we must query at leas
- Dealing with Stale Reads
Monotonic reads are particularly relevant in distributed systems with data replication, where data is copied and maintai
- Write Conflicts
Concurrent writes: Conflicting writes that are unaware of each other at the time of writing.
- Conflict-Free Replicated Data Types - CRDTs
Conflict-Free Replicated Data Types (CRDTs) are designed to enable concurrent updates and ensure eventual consistency ac
- Conclude Replication
Replication is a key strategy in distributed systems to enhance availability, fault tolerance, and scalability. There ar
-
- Sharding and Partitioning
- Into to Partitioning or Sharding
For very large datasets, or very high query throughput, replication is not sufficient: we need to break the data into pa
- Rebalancing Partitions
Rebalancing is the process of redistributing data and requests across nodes in a cluster to handle changes such as incre
- Atomic Commit and Two-Phase Commit (2PC)
Atomicity prevents failed transactions from littering the database with half-finished results and half-updated state. Th
-
- Consistency and Consensus
- Linearizability
In a database with multiple nodes, inconsistencies occur because write requests arrive at different times on different n
- Distributed Consensus
Distributed consensus is how a group of unreliable machines agrees on a single value — one leader, one log order, one co
- The Raft Consensus Algorithm - Leader Election
https://web.stanford.edu/ouster/cgi-bin/cs190-winter20/lecture.php?topic=raft
- Raft Writes
Once a leader is elected, it is responsible for handling all client write requests. Here’s how a typical write operation
- Coordination Services
Coordination services are just thin layer that're built on distributed consensus algorithm like Raft (The Raft Consensus
- Lamport Clocks
Lamport clocks are a mechanism used in distributed systems to assign a logical timestamp to events in order to capture t
- Version Vector
Version vectors are a mechanism used in distributed systems to track the version history of replicated data across multi
-
- Databases Duel Arena
- Relational Vs Non-Relational DBs
SQL vs NoSQL (not preferred terms)
- MySQL vs PostgreSQL
SQL databases are particularly well-suited for handling normalized, relational data. They excel at managing data in a st
- MongoDB vs Cassandra
MongoDB is a NoSQL database that is document-oriented, meaning it stores data in flexible, JSON-like documents. Unlike t
-
- Streams
- Stream Processing
Stream processing is basically real-time processing of a continuous data streams as they're generated. Unlike, batch pro
- Kafka vs RabbitMQ
Here is a comparison table highlighting the key differences between Kafka (a log-based message broker) and RabbitMQ (an
-
- Scaling and Load Balancing
- Scaling Out and Load Balancing
Vertical scaling (scale-up) means a bigger machine: more cores, more RAM, faster NVMe. A single well-tuned box today can
-
- Caching
- Cache Patterns and Eviction
Two rules interviewers listen for. First, on write in cache-aside, delete the key — don't update it: updating risks orde
-
- CDN and Edge
- Content Delivery and Edge
A Point of Presence is a cluster of cache + compute + TLS-termination servers placed in carrier-neutral facilities and I
-
- API Design and Gateways
- API Design and Gateways
The FAANG-default topology: gRPC inside, REST (or GraphQL) outside, translated at the gateway/edge. Quote the numbers: p
-
- Rate Limiting
- Messaging and Queues
- Messaging and Event Queues
Synchronous RPC chains multiply failure: if service A calls B calls C, each with 99.9% availability, the chain is 99.7%
-
- Microservices Patterns
- Microservices Patterns
Single edge entrypoint (Kong, NGINX/Envoy, AWS API Gateway, Spring Cloud Gateway) owning all cross-cutting concerns: TLS
-
- CAP and Consistency Models
- CAP PACELC and Consistency Models
Gilbert–Lynch CAP: when a network partition occurs, a distributed read/write store chooses between consistency (every re
-
- Observability
- Observability and Operations
Counters (requests, errors), gauges (queue depth, connections), histograms/summaries (latency distributions — never aver
-
- Security and Auth
- Security and Auth for System Design
Every hop encrypted: client→edge, edge→service, service→service (mTLS in a service mesh like Istio/Linkerd, or at minimu
-
Case studies
-
-
-
- Twitter Timeline hld questions
dynamic celebrity thresholds, early-rank ingest, home vs user timelines.
-
-
-
-
-
-
-
-