The ideas behind
every system you'll design.
Uber, Twitter, a key-value store — strip away the product and the same four questions remain. What happens during a network partition? How do simultaneous writes stay correct? How is data split and copied? How do independent machines agree? Master these and every design becomes a recombination of things you already understand.
CAP & Consistency
What a system can promise when the network splits — and the spectrum of consistency between "always latest" and "eventually right".
Concurrency & Locking
How overlapping operations stay correct — locks, isolation levels, optimistic vs pessimistic, MVCC, and the races they prevent.
Partitioning & Replication
How one dataset becomes many — sharding, consistent hashing, leader/follower replication, and quorum reads and writes.
Consensus & Coordination
How nodes that can crash still agree on one truth — Raft and Paxos, leader election, distributed transactions, and idempotency.
CAP & consistency models
When the network is healthy you can have it all. CAP is about the moment it isn't.
The CAP theorem states that during a network partition — when some nodes can't reach others — a distributed store must choose between Consistency (every read returns the latest write) and Availability (every request still gets a non-error response). Partition tolerance isn't optional in a real network, so the real choice is CP or AP.
But CAP is binary and only speaks about partitions. PACELC extends it: else, when the system is running normally, you still trade Latency against Consistency. And "consistency" itself is a spectrum — from linearizable (behaves like a single copy) down through causal to eventual (replicas converge, given time).
Consistency
Reject or block requests that can't be made consistent. The system may go unavailable, but never returns stale data. e.g. a payment ledger.
Availability
Always answer, even if some replicas are behind. Reconcile later. e.g. a shopping cart, social feed.
| Model | Guarantee | Cost | Typical use |
|---|---|---|---|
| Linearizable | Reads see the most recent write, globally ordered | Highest latency, needs consensus | Locks, leader election, balances |
| Causal | Operations that depend on each other are seen in order | Moderate | Comments, messaging threads |
| Read-your-writes | You always see your own latest change | Low (session pinning) | Profile edits, settings |
| Eventual | Replicas converge if writes stop | Lowest latency, can read stale | Caches, view counts, DNS |
"Consistency vs availability" is not a property you set once — it's a decision you make per operation. The same system can require linearizable writes for an account balance and serve eventually-consistent reads for that account's activity feed.
CAP Theorem & Consistency Models, explained →
Concurrency & locking
Two users, one last concert ticket, the same millisecond. Correctness under concurrency is the whole game.
When operations overlap, you risk race conditions: lost updates, dirty reads, and double-spends. Locking serializes access so only safe interleavings happen. The strategy you pick depends on how often operations actually collide.
Pessimistic locking assumes conflict is likely and takes the lock before touching data — others wait. Optimistic locking assumes conflict is rare: read a version number, do the work, and only at commit check whether the version changed, retrying if so. Modern databases also use MVCC to give readers a consistent snapshot without blocking writers.
Pessimistic
- Lock → read → write → unlock
- Others block and wait
- No wasted work
- Risk: deadlocks, contention
- Best for high-conflict writes
Optimistic
- Read version → work → CAS commit
- No blocking
- Retry on conflict
- Risk: wasted work if hot
- Best for read-heavy, low-conflict
| Isolation level | Prevents | Still allows |
|---|---|---|
| Read Uncommitted | — | Dirty reads |
| Read Committed | Dirty reads | Non-repeatable reads |
| Repeatable Read | Non-repeatable reads | Phantoms (in classic SQL) |
| Serializable | Everything — behaves as if serial | Nothing (highest cost) |
When asked "how do you stop two people booking the same seat?", name the trade-off out loud: a pessimistic row lock or SELECT … FOR UPDATE is simplest at low scale; an optimistic version check or a short-lived distributed lock scales better but needs a retry path. The wrong answer is to not mention the race at all.
Concurrency, Locks & Isolation Levels →
Partitioning & replication
One machine can't hold the internet. So you split the data — then copy it so a dead disk doesn't take it with you.
Partitioning (sharding) splits one dataset across many machines so each holds a slice — this scales capacity and throughput. The hard part is the key: hash the key for even spread, or range-partition it for efficient scans. Naïve hashing breaks when you add a node, so production systems use consistent hashing, which moves only a small fraction of keys when the cluster changes.
Replication copies the same data onto several machines — this gives fault tolerance and read scaling. A common pattern is one leader taking writes and streaming them to followers. Quorum systems generalize this: with N replicas, require W writes and R reads such that W + R > N to guarantee overlap. Real systems do both — shard for scale, replicate each shard for durability.
A key hashes to a point on the ring and is owned by the next node clockwise. Add a node and only its neighbour's keys move.
Synchronous replication = durable but slower. Asynchronous = fast but risks losing the tail on leader failure.
Partitioning and replication answer different questions. Sharding asks "where does this key live?"; replication asks "how many copies survive a failure?" You almost always need both, and a good shard key (high cardinality, even access) is the single decision that makes or breaks the design.
Partitioning, Sharding & Replication →
Consensus & coordination
Machines crash and messages get lost — yet the cluster must still agree on exactly one answer. That's the hardest problem in distributed systems, and it has a name.
Many problems reduce to consensus: who is the leader, what's the next entry in the replicated log, did this transaction commit? Raft and Paxos let a majority quorum agree safely even when a minority of nodes fail. Raft makes this approachable with an explicit leader election plus log replication — it's what powers etcd, Consul, and CockroachDB.
Above the cluster, distributed transactions coordinate work across services. Two-phase commit (2PC) gives atomicity but blocks if the coordinator dies; the saga pattern trades atomicity for availability using compensating actions. And because networks retry, every operation that mutates state should be idempotent — applying it twice has the same effect as once.
Two-Phase Commit
- Prepare → all vote → commit
- Strong atomicity
- Coordinator is a bottleneck
- Blocks on failure
Saga
- Local commits + compensations
- No global lock
- Eventually consistent
- You write the rollbacks
A node needs votes from a strict majority to lead — so two leaders can never co-exist, even during a partition.
You rarely implement consensus yourself — you reach for a system that already did (ZooKeeper, etcd, a managed database). The senior move is knowing where you need it (one source of truth, leader election) versus where you can avoid it entirely with idempotency and eventual consistency.
Consensus, Transactions & Coordination →
worked system designs.
Fundamentals stick when you watch them assemble into something real. Every design on Vibe Engines builds step by step through an interactive diagram — spot the CAP trade-off, the shard key, the lock, the quorum, as each one appears.
Quick answers
What are the fundamentals of system design?
The load-bearing fundamentals are CAP & consistency, concurrency & locking, partitioning & replication, and consensus & coordination. Almost every design decision in a distributed system reduces to a trade-off among these four areas.
What is the CAP theorem in simple terms?
During a network partition, a distributed system must choose between Consistency (every read sees the latest write) and Availability (every request still gets an answer) — it cannot have both. Systems are classified CP or AP accordingly.
Optimistic vs pessimistic locking — what's the difference?
Pessimistic locking takes a lock before touching data (best for high contention). Optimistic locking takes no lock, then checks a version at commit time and retries on conflict (best for read-heavy, low-contention workloads).
Partitioning vs replication?
Partitioning (sharding) splits one dataset across machines to scale capacity. Replication copies the same data onto several machines for fault tolerance and read scaling. Real systems use both: shard for scale, replicate each shard for durability.
Why do distributed systems need Raft or Paxos?
Independent nodes that can crash or be partitioned still need to agree on one value — the leader, the next log entry, whether a transaction committed. Consensus algorithms let a majority quorum agree safely even when some nodes fail.
More Handbooks
- The Prompting HandbookA friendly, hands-on field guide for everyday humans — learn the CRISP framework, spot bad prompts, practice with real recipes, play a drag-and-drop game, and test yourself with a quiz. No code required.Read →
- The Agentic AI Interview HandbookTwenty topics every senior AI engineer should be able to reason about live — from eval pipelines to reliability patterns for generative systems.Read →
- The Senior AI Engineer Interview Handbook60 questions across architecture, production incidents, agentic systems, RAG, evals, cost, safety, and leadership — what staff-level AI interviewers actually probe for.Read →
- 50 Angular Interview QuestionsA visual handbook covering components, change detection, RxJS, signals, routing, forms, performance, and testing — what interviewers actually probe for in senior Angular roles.Read →
- 50 Python Interview QuestionsFundamentals to advanced: data structures, OOP, iterators & generators, the GIL, asyncio, memory, testing, and the standard library — a visual walk through everything a Python interview touches.Read →
- 51 LLM Evals Interview QuestionsGolden sets, LLM-as-judge, regression testing, offline vs online evals, RAG evals, agent evals, red-teaming, and observability — demystified for interviews and production.Read →