Track 1: Foundations
Before diving into consensus protocols and complex architectures, you must understand the fundamental challenges that make distributed systems hard. This chapter is the foundation everything else rests on — if your mental model of networks, time, and failure is wrong, every design decision you make downstream will be subtly broken.Modules: 5
Key Topics: Network fundamentals, Time & Ordering, Failure Models, CAP/PACELC
Module 1: Why Distributed Systems?
The Need for Distribution
Every successful system eventually outgrows a single machine:Types of Distributed Systems
Compute Clusters
- Hadoop/Spark clusters
- Kubernetes pods
- AWS Lambda fleet
Storage Systems
- Distributed databases (Cassandra, DynamoDB)
- Object stores (S3, GCS)
- File systems (HDFS, Ceph)
Message Systems
- Message queues (Kafka, RabbitMQ)
- Pub/sub systems (SNS, Pub/Sub)
- Event streams (Kinesis, Event Hubs)
The Eight Fallacies of Distributed Computing
Every distributed systems engineer must internalize these. Peter Deutsch (with additions by James Gosling) identified these assumptions that developers new to distributed systems unconsciously make. Each one is a trap — code that works perfectly on your laptop will fail in production because of one or more of these false beliefs:1. The Network is Reliable
1. The Network is Reliable
2. Latency is Zero
2. Latency is Zero
3. Bandwidth is Infinite
3. Bandwidth is Infinite
4. The Network is Secure
4. The Network is Secure
- Man-in-the-middle attacks
- DNS spoofing
- BGP hijacking (internet routing attacks)
- Insider threats
5. Topology Doesn't Change
5. Topology Doesn't Change
6. There is One Administrator
6. There is One Administrator
- Platform team manages Kubernetes
- Each service team manages their services
- Security team manages policies
- Network team manages infrastructure
7. Transport Cost is Zero
7. Transport Cost is Zero
8. The Network is Homogeneous
8. The Network is Homogeneous
Module 2: Network Fundamentals
TCP Guarantees and Failures
TCP provides order and reliability, but not much else:Network Partitions
A network partition occurs when nodes can’t communicate with each other:- Availability: Both partitions continue serving requests (might diverge)
- Consistency: Reject requests from the minority partition
Message Delivery Semantics
- At-Most-Once
- At-Least-Once
- Exactly-Once
Failure Detection
How do you know if a node is dead?Vector Clocks
Vector clocks track causality - they tell you if two events are related:Advanced: Vector Clocks vs. Version Vectors
In many textbooks, “Vector Clocks” and “Version Vectors” are used interchangeably. However, at the Staff level, you must distinguish between them:- Vector Clocks (Causality): Track the relationship between events in a distributed system. Every interaction (send/receive) increments the clock. They are used to build a partial order of all operations.
- Version Vectors (Conflict Tracking): Track the relationship between versions of data. They only increment when data is updated. They are used in systems like DynamoDB and Riak to detect if two versions of a document are in conflict (siblings).
Implementation:
Hybrid Logical Clocks (HLC)
Combines physical and logical clocks:TrueTime (Google Spanner)
Google’s hardware-based approach:Module 4: Failure Models
Understanding what can go wrong is crucial for building resilient systems.Types of Failures
- Fail-Stop
- Fail-Recover
- Byzantine
- Clean failure, detectable
- Node doesn’t recover with corrupted state
- Easiest to handle
Partial Failures
The defining challenge of distributed systems:Gray Failures
Gray failures are the distributed systems equivalent of a slow gas leak — everything seems fine until suddenly it is not. They are far more common and insidious than clean crash failures, and they are the cause of most prolonged production outages:Byzantine Fault Tolerance (BFT)
Byzantine failures are the most challenging to handle:- Blockchain and cryptocurrency systems
- Multi-party financial transactions
- High-security government systems
- Any system with mutually distrustful participants
Network Partition Simulation
Understanding how to test partition tolerance:Chaos Engineering for Failure Testing
Module 5: CAP and PACELC Theorems
CAP Theorem
CP vs AP Deep Dive
CP Systems
- Minority partition stops accepting writes
- May reject reads too (for linearizability)
- Majority partition continues
- Financial systems
- Inventory management
- Any system where stale data is dangerous
AP Systems
- Both partitions continue serving
- May return stale/conflicting data
- Resolve conflicts after partition heals
- Social media feeds
- Shopping carts
- DNS
PACELC: The Better Framework
CAP only describes behavior during partitions. PACELC adds normal operation:Consistency Spectrum
Consistency is not binary - it’s a spectrum:External Consistency vs. Linearizability
For Staff/Principal level engineering, you must distinguish between system-local and global-time guarantees.Linearizability (Atomic Consistency)
Linearizability is a guarantee for a single object (or key). It ensures that:- Every operation appears to take effect atomically at some point between its invocation and response.
- All operations are seen in the same order by all participants.
- If a write completes before a read starts (according to the system’s observer), must see the result of .
External Consistency (Strict Serializability)
External Consistency is a stronger, global guarantee, famously used by Google Spanner. It combines Linearizability with Serializability across multiple shards/objects and respects global wall-clock time.Module 6: Modern Infrastructure & Serverless Internals
To achieve the “Principal” level of understanding, one must look beyond the logical protocols and into the physical isolation models that power modern clouds. The shift from monolithic VMs to Micro-VMs has fundamentally changed how we scale distributed systems.The Serverless Paradox
Serverless (AWS Lambda, Google Cloud Functions) promises “no servers,” but in reality, it requires the most complex server management in existence. The challenge is The Cold Start Problem vs. Isolation Security.- Traditional VMs (EC2): Strong isolation, but slow to boot (30s+). Too slow for “on-demand” execution.
- Containers (Docker/K8s): Fast to start, but weak isolation (shared kernel). Dangerous for multi-tenant code execution.
Micro-VM Internals: AWS Firecracker
AWS Firecracker is the technology behind Lambda and Fargate. It uses KVM (Kernel-based Virtual Machine) but stripped down to the bare essentials.- Minimal Device Model: Firecracker drops legacy hardware support (no USB, no video). It only provides:
- Net (Network)
- Block (Storage)
- Serial (Console)
- Balloon (Memory management)
- Snapshot-and-Restore: Instead of booting a kernel, Firecracker can restore from a Memory Snapshot. This reduces “boot” time from seconds to ~10ms.
- Jailer: A secondary security layer that uses
cgroups,namespaces, andseccompto ensure that even if a Micro-VM is compromised, it cannot touch the host or other VMs.
Implications for Distributed Design
When designing systems for serverless:- Statelessness is Mandatory: Because the Micro-VM can be killed or recycled at any moment.
- Sidecar Overhead: Traditional sidecars (Service Mesh) add too much latency for 50ms functions. We move towards Proxyless Mesh or Library-based approaches.
- Connection Pooling: Traditional database connection pools fail at serverless scale. We use RDS Proxy or HTTP-based database protocols (Data API).
Key Interview Questions
Q: Can you achieve consensus in an asynchronous system?
Q: Can you achieve consensus in an asynchronous system?
- Using timeouts (introduces synchrony assumption)
- Randomization
- Failure detectors
Q: How do you detect if a node is dead vs slow?
Q: How do you detect if a node is dead vs slow?
- Timeouts: Simple but prone to false positives
- Heartbeats: Regular health checks
- Phi accrual detector: Probabilistic suspicion level
- Lease-based: Node must renew lease to be considered alive
Q: Explain vector clocks vs Lamport timestamps
Q: Explain vector clocks vs Lamport timestamps
- Lamport: Single counter, preserves “happens-before” one direction only
- Vector clocks: One counter per node, can detect concurrent events
Q: Is your system CP or AP?
Q: Is your system CP or AP?
- First, acknowledge CAP only applies during partitions
- Discuss what consistency level you actually need
- Explain PACELC for normal operation
- Give examples: “For our payment system, we’re CP because incorrect balance is unacceptable. For user preferences, we’re AP because eventual consistency is fine.”
Next Steps
Continue to Track 2: Consensus Protocols
Interview Deep-Dive
The FLP impossibility result says consensus is impossible in an asynchronous system. Yet we use Raft and Paxos every day. How do you reconcile this?
The FLP impossibility result says consensus is impossible in an asynchronous system. Yet we use Raft and Paxos every day. How do you reconcile this?
- FLP proves that no deterministic algorithm can guarantee consensus in a fully asynchronous system where even one process may crash. The key word is “guarantee” — it is an impossibility of absolute liveness, not of safety.
- Practical systems like Raft and Paxos work around FLP by introducing partial synchrony assumptions. Specifically, they use timeouts to detect suspected failures. Once you add a timeout, you are no longer in a purely asynchronous model — you are assuming that messages will eventually be delivered within some bound. FLP does not apply to partially synchronous systems.
- The trade-off is that during periods of true asynchrony (extreme network delays, GC pauses that exceed the timeout), these protocols may fail to make progress (liveness violation) but they never violate safety (they never agree on two different values). This is exactly the right trade-off for production systems: it is acceptable to be temporarily unavailable, but it is never acceptable to corrupt data.
- Another approach is randomized consensus (like Ben-Or’s protocol), which circumvents FLP by using randomization rather than determinism. The expected number of rounds is finite, but no single execution is guaranteed to terminate.
Explain the difference between a network partition, a partial partition, and an asymmetric partition. Why does the distinction matter for system design?
Explain the difference between a network partition, a partial partition, and an asymmetric partition. Why does the distinction matter for system design?
- A full partition splits the cluster into two groups that cannot communicate at all. This is the classic CAP scenario: each side must independently decide whether to keep serving (AP) or stop (CP). Raft handles this cleanly — the majority side elects a leader, the minority side stops accepting writes.
- A partial partition is when some nodes can communicate with some but not all other nodes. For example, in a 5-node cluster, node A can talk to B and C, node D can talk to C and E, but A cannot talk to D or E. Node C acts as a bridge. This is more insidious because quorum-based systems may still form quorums that do not overlap correctly, and different nodes have different views of who is reachable.
- An asymmetric partition is when A can send to B but B cannot send to A. TCP will eventually detect this (via ACK timeouts), but UDP-based gossip or heartbeat systems may not. Node A thinks B is alive (because A’s sends succeed), while B thinks A is dead (because B never receives anything).
- The distinction matters because most distributed systems are designed for full partitions, but partial and asymmetric partitions are more common in practice (misconfigured firewalls, flaky switches, half-duplex network failures). If your failure detector assumes symmetric communication, an asymmetric partition can cause split-brain.
iptables-based nemesis or Toxiproxy) that can selectively drop traffic between specific pairs of nodes. The test scenario would create a partition where nodes A-B-C can communicate, D-E can communicate, but C is the only bridge between the two groups. Then I would verify: can the system still make progress? Does it correctly detect the partial partition? Does it degrade gracefully? I would also test the asymmetric case by dropping packets in one direction only using iptables INPUT/OUTPUT rules. The key metrics to watch are: leader election stability, write latency, and most importantly, whether any safety invariants (like linearizability) are violated during the partition.A colleague says your system should be designed for Byzantine fault tolerance because 'you never know what could go wrong.' How do you respond?
A colleague says your system should be designed for Byzantine fault tolerance because 'you never know what could go wrong.' How do you respond?
- I would respectfully push back. BFT is the right tool for a very specific threat model: mutually distrustful participants who may actively lie (blockchains, multi-party financial systems). For the vast majority of internal distributed systems, crash-fault tolerance (CFT) is sufficient and dramatically cheaper.
- The cost difference is significant. CFT protocols like Raft need 2f+1 nodes to tolerate f failures, with O(n) message complexity per consensus round. BFT protocols like PBFT need 3f+1 nodes with O(n-squared) message complexity. For a 5-node Raft cluster tolerating 2 failures, you need 5 nodes. For BFT tolerating 2 failures, you need 7 nodes, each exchanging quadratically more messages.
- In practice, the failures that cause production outages are crashes, network partitions, disk failures, and software bugs — not malicious nodes. If you are worried about buggy nodes sending corrupt data, you can add checksums and input validation at the application layer for a fraction of the cost of full BFT.
- The exception: if you are building a system where different organizations contribute nodes and have economic incentives to cheat, BFT is necessary. This is why blockchain consensus uses BFT variants.
Explain the PACELC theorem and give me an example of a real system for each of the four PACELC categories: PA/EL, PA/EC, PC/EL, and PC/EC.
Explain the PACELC theorem and give me an example of a real system for each of the four PACELC categories: PA/EL, PA/EC, PC/EL, and PC/EC.
- PACELC extends CAP by asking: even when there is no partition, what trade-off does the system make between latency and consistency? The framework is: if Partition, choose Availability or Consistency; Else, choose Latency or Consistency.
- PA/EL (Available during partitions, Low latency normally): DynamoDB and Cassandra. During a partition, they keep serving from whichever replicas are reachable. During normal operation, they return responses from the nearest replica without waiting for quorum, giving low latency but eventual consistency.
- PA/EC (Available during partitions, Consistent normally): MongoDB with default read concern. During normal operation, reads go to the primary, which is consistent. During a partition, secondaries can still serve reads (with possible staleness), maintaining availability.
- PC/EL (Consistent during partitions, Low latency normally): Yahoo’s PNUTS (now largely historical). It blocks writes during partitions to maintain per-record consistency, but during normal operation it routes reads to the nearest replica for low latency using “timeline consistency.”
- PC/EC (Consistent during partitions, Consistent normally): Google Spanner. It blocks during partitions (choosing consistency), and during normal operation it uses TrueTime and commit-wait to provide external consistency, accepting higher latency (1-7ms commit wait) for global ordering guarantees.
QUORUM and a read with QUORUM gives you PC/EC behavior for that specific operation. A write with ONE and a read with ONE gives you PA/EL behavior. The same cluster, the same data, but different consistency-latency trade-offs per request. Spanner does something similar with its read-only transactions: a “strong read” gives you external consistency (PC/EC), while a “stale read” with a bounded staleness of 10 seconds gives you lower latency (closer to PC/EL). The design insight is that consistency should be a dial, not a switch — and different use cases within the same application should be able to turn that dial independently.