08. Network & Distributed Storage: Replication, Quorums, Raft & Erasure Coding
Prerequisites: Module 01 (Storage Metrics), Module 04 (Network Protocols), Module 06 (RAID & Parity).
Target Audience: Distributed Systems Engineers, Storage Architects, SREs, and Cloud Infrastructure Engineers.
When persistent data volumes, throughput demands, or availability SLAs exceed the physical boundaries of a single server or storage array, storage must be distributed across an untrusted, partitioned physical network.
Designing distributed storage requires balancing the CAP theorem, consensus protocols (Raft, Paxos), quorum consistency (), and the fundamental mathematical trade-off between replication and erasure coding.
1. Why Distributed Storage? Failure Domains & CAP/PACELCβ
Distributed storage replaces expensive, proprietary scale-up SAN hardware with scale-out clusters of commodity servers.
+-----------------------------------------------------------------------------------+
| Region: us-east-1 |
| +-------------------------------------+---------------------------------------+ |
| | Availability Zone A (AZ-1) | Availability Zone B (AZ-2) | |
| | +-------------------------------+ | +---------------------------------+ | |
| | | Rack 1 (PDU-1, ToR Switch 1) | | | Rack 2 (PDU-2, ToR Switch 2) | | |
| | | [Node 1] [Node 2] | | | [Node 3] [Node 4] | | |
| | +-------------------------------+ | +---------------------------------+ | |
| +-------------------------------------+---------------------------------------+ |
+-----------------------------------------------------------------------------------+
1. Failure Domainsβ
To achieve true high availability, redundant copies of data must reside in independent failure domains:
- Disk Failure Domain: Tolerates bad sectors or disk crashes.
- Node Failure Domain: Tolerates kernel panics, CPU hangs, or motherboard power supply burnouts.
- Rack Failure Domain: Tolerates Top-of-Rack (ToR) network switch failures or Power Distribution Unit (PDU) trips.
- Availability Zone (AZ) Failure Domain: Tolerates municipal power grid failure, datacenter floods, or fiber cuts.
2. The CAP & PACELC Theorems in Storageβ
- CAP Theorem: In the presence of a network partition (P), a distributed storage system must choose between Consistency (C, all nodes see the same data at the same time) or Availability (A, every non-failing node returns a response).
- PACELC Theorem: Extends CAP: If there is a Partition, trade off Availability vs. Consistency; Else, trade off Latency vs. Consistency.
- CP Systems (Ceph, CockroachDB, Google Spanner): Prioritize strict serializability; reject writes if quorum cannot be reached.
- AP / PA/EL Systems (Amazon DynamoDB, Apache Cassandra): Prioritize low write latency; accept writes locally and resolve conflicts later via vector clocks or Last-Write-Wins (LWW).
2. Replication Models: Synchronous vs. Asynchronous vs. Semi-Synchronousβ
Synchronous Replication (RPO = 0, High Latency):
Client ββwrite()ββ> Primary ββwrite()ββ> Replica 1
β β
β βββackββββββ
βββwrite()ββ> Replica 2 β
β β
βββackβββββββ΄ββ> Primary commits ββackββ> Client
Asynchronous Replication (Low Latency, RPO > 0):
Client ββwrite()ββ> Primary commits ββackββ> Client
β
βββ(Background Queue)ββ> Replica 1 & Replica 2
1. Synchronous Replicationβ
- Mechanism: The primary node writes to local storage and concurrently transmits data to replica nodes. The client request does not return success until all (or a quorum of) replicas acknowledge persistent storage.
- RPO (Recovery Point Objective): 0 (Zero data loss upon primary crash).
- Latency Penalty: Bounded by the slowest replica's network round-trip and disk write time (tail latency problem).
2. Asynchronous Replicationβ
- Mechanism: The primary writes locally and immediately returns success to the client. Replication streams to secondary nodes in background queues.
- RPO: . If the primary server crashes or experiences a sudden ungraceful power loss, any data buffered in memory or in-flight across the network that was not acknowledged by replicas is permanently lost.
- Latency Benefit: Client write latency equals local disk write speed.
3. Semi-Synchronous Replicationβ
- Used in enterprise databases (e.g., MySQL semi-sync). The primary blocks until at least one remote replica in an independent rack or AZ acknowledges receipt of the transaction log into its relay buffer before returning success.
3. Quorum Mathematics & Consistency Modelsβ
To guarantee strong read-your-writes consistency in leaderless distributed storage (e.g., Dynamo-style architectures), read and write operations use Quorums:
Total Replicas: N = 5
Write Quorum: W = 3
Read Quorum: R = 3
R + W = 3 + 3 = 6 > 5 (N) ==> Strict Quorum!
βββββββββββββββββββ¬ββββββββββββββββββ¬ββββββββββββββββββ¬ββββββββββββββββββ¬ββββββββββββββββββ
β Node 1 β Node 2 β Node 3 β Node 4 β Node 5 β
β [Version 2 (W)] β [Version 2 (W)] β [Version 2 (W)] β Version 1 (R) β Version 1 (R) β
βββββββββββββββββββ΄ββββββββββββββββββ΄ββββββββββββββββββ΄ββββββββββββββββββ΄ββββββββββββββββββ
<ββββββ Write Quorum (W=3) ββββββ> <ββββββ Read Quorum (R=3) βββββββ>
^^^^^^^^^^^^^^^
Overlapping Node (Node 3)
Guarantees latest Version 2 is read!
The Strict Quorum Ruleβ
When , the Pigeonhole Principle guarantees that any set of nodes read from and any set of nodes written to must share at least one overlapping node.
- That overlapping node holds the highest version timestamp or generation ID.
- The client selects the highest version and can optionally trigger an asynchronous Read Repair to update stale nodes.
4. Consensus Protocols: Paxos vs. Raftβ
When distributed storage requires a single linearizable order of updates (e.g., metadata catalogs, distributed lock managers, etcd, Ceph Mons), leaderless quorums are insufficient. Systems employ Distributed Consensus.
Raft Consensus Protocol States:
Times out, starts election
βββββββββββ ββββββββββββββββββββββββ> βββββββββββββ
βFollower β β Candidate β
βββββββββββ <ββββββββββββββββββββββββ βββββββββββββ
β² Discovers current leader β
β or new term β Receives votes from
β β majority of cluster
β Steps down βΌ
ββββββββββββββββββββββββββββββββ βββββββββββββ
β Leader β
βββββββββββββ
Raft Core Invariantsβ
- Leader Election: Time is divided into arbitrary Terms. If a Follower receives no heartbeats within its randomized election timeout (), it transitions to Candidate, increments the term, and requests votes.
- Majority Rule: A Candidate becomes Leader only if it secures votes from a strict majority () of nodes.
- Log Matching Invariant: If two entries in different logs have the same index and term, they store identical commands, and their logs are identical up to that index.
- Split-Brain Prevention: Because an odd number of voting nodes () is required, a network split can only leave one partition with a strict majority. The minority partition cannot elect a leader and rejects client writes.
5. Erasure Coding (EC) vs. Multi-Copy Replicationβ
Replication achieves fault tolerance by storing complete copies of an object. Erasure Coding (EC) achieves equal or superior fault tolerance at a fraction of the raw capacity overhead.
Replication (3x Multi-Copy):
Payload (10 MB) ββ> [ Copy 1: 10 MB ] [ Copy 2: 10 MB ] [ Copy 3: 10 MB ]
Total Storage: 30 MB (Storage Efficiency = 33.3%, Overhead = 200%)
Tolerates: 2 node failures
Reed-Solomon Erasure Coding (k=4, m=2):
Payload (10 MB) ββ> Sliced into 4 Data Chunks (2.5 MB each)
ββ> Math Engine computes 2 Parity Chunks (2.5 MB each)
[ Data 1 ] [ Data 2 ] [ Data 3 ] [ Data 4 ] [ Parity 1 ] [ Parity 2 ]
2.5 MB 2.5 MB 2.5 MB 2.5 MB 2.5 MB 2.5 MB
Total Storage: 15 MB (Storage Efficiency = 66.7%, Overhead = 50%)
Tolerates: Any 2 node failures!
Reed-Solomon Erasure Coding Mechanicsβ
- Slices an object into equal data chunks.
- Computes redundant parity chunks using linear algebra over Galois Fields ( or ) via Vandermonde or Cauchy distribution matrices:
- The Core Property: Any chunks out of the total chunks are mathematically sufficient to reconstruct the entire original object!
The Engineering Trade-off: Storage Cost vs. Rebuild Network Penaltyβ
| Architectural Property | 3x Replication | Erasure Coding () |
|---|---|---|
| Storage Overhead | () | () |
| Capacity Efficiency | ||
| Fault Tolerance | 2 failures | 4 failures |
| Normal Read Latency | Low (Single node read) | Low (Read chunks in parallel) |
| Degraded Read Penalty | Zero (Read surviving replica) | Severe (Must read chunks to decode) |
| Network Traffic on Rebuild | object size | () object size over network |
| CPU Overhead | Minimal (Memory copy) | Moderate to High (SIMD matrix math) |
6. Hands-on Linux Lab: Simulating Network Latency & Partitionsβ
Use Linux Kernel Traffic Control (tc) and Network Emulation (netem) to test how distributed storage systems react to network degradation.
Step 1: Inject Artificial Latency and Jitterβ
# Add 25 ms delay (+/- 5 ms jitter) to network interface eth0
sudo tc qdisc add dev eth0 root netem delay 25ms 5ms
# Test ping latency to peer storage node
ping -c 5 10.0.0.2
# Remove network emulation
sudo tc qdisc del dev eth0 root
Step 2: Simulate Packet Loss and Reorderingβ
# Inject 3% packet loss and 2% packet corruption
sudo tc qdisc add dev eth0 root netem loss 3% corrupt 2%
Step 3: Simulate an Asymmetric Network Split with iptablesβ
# Drop all incoming packets from Node 3 (10.0.0.3) to simulate a network partition
sudo iptables -A INPUT -s 10.0.0.3 -j DROP
# Observe Raft leader election / quorum response in storage daemon logs
# Flush iptables rule to heal the network partition
sudo iptables -D INPUT -s 10.0.0.3 -j DROP
7. Real-World Production Failure Scenariosβ
Failure Scenario 1: The 2-Node "High Availability" Split-Brain Disasterβ
Incidentβ
An engineering team deployed a 2-node MySQL active-passive cluster with automatic heartbeat failover. A transient top-of-rack network glitch severed communication between Node 1 and Node 2 for 45 seconds.
- Node 2 assumed Node 1 had died and promoted itself to Primary.
- Node 1 was still alive and continued accepting customer orders.
- Both nodes accepted conflicting transactions for 3 hours before discovery. Reconciling split database histories took 4 days of manual database surgery.
Root Causeβ
A 2-node cluster cannot establish quorum! When network partitions occur, neither isolated node can achieve a majority of 2.
Prevention Ruleβ
- Always deploy an odd number of consensus voting nodes (minimum 3 nodes, where quorum = 2).
- Deploy hardware fencing / STONITH ("Shoot The Other Node In The Head") via IPMI or network power switches to physically reboot a non-communicative primary before promoting a replica.
Failure Scenario 2: The Erasure Coding Rebuild Network Meltdownβ
Incidentβ
A 100-node object storage cluster configured with Reed-Solomon Erasure Coding experienced a rack failure taking down 4 nodes simultaneously. The cluster began automatic background data recovery:
- Rebuilding each lost chunk required reading 16 surviving chunks across the network.
- The internal datacenter spine network saturated at 100% capacity ().
- Client application traffic timed out with connection resets; the storage cluster became completely unresponsive for 6 hours until network rate-limiting was applied.
Preventionβ
Configure QoS (Quality of Service) and strict bandwidth throttling on background storage recovery traffic:
- In Ceph:
osd_max_backfills = 1,osd_recovery_max_active = 2. - In MinIO: Limit parallel heal routines via
minio server --heal-threads.
8. Practical Engineering Exercises (With Solutions)β
Exercise: Sizing Quorum for a Multi-Datacenter Clusterβ
Problem: You are architecting a distributed storage cluster spanning three geographic datacenters: DC-East (5 nodes), DC-West (4 nodes), and DC-Central (2 nodes). Total nodes .
- What is the minimum number of nodes required to form a strict consensus quorum?
- If DC-East suffers a catastrophic power outage, can the surviving datacenters continue servicing writes?
- If DC-West suffers a network partition, can DC-East and DC-Central continue servicing writes?
Solution:β
- Consensus Quorum Majority:
- DC-East power outage:
- Remaining nodes: .
- Can they form quorum? Yes! . The cluster continues operating.
- DC-West network partition:
- Remaining nodes: .
- Can they form quorum? Yes! . The cluster continues operating.
- Engineering Conclusion: Sizing with an odd number ensures that losing any single datacenter (which holds at most 5 nodes) allows the remaining 6 nodes to safely maintain consistency and uptime without split-brain risk.
9. Summary Checklist & Key Takeawaysβ
- Always Use Odd Node Counts for Consensus: 3, 5, or 7 nodes. An even number of nodes cannot break ties during network partitions.
- Strict Quorum Formula: ensures read and write quorums overlap on at least one latest-version node.
- Erasure Coding Halves Storage Costs: Slashes storage overhead from 200% (3x replication) to 50% ( EC) while improving fault tolerance.
- Beware EC Rebuild Storms: Rebuilding 1 missing erasure-coded block requires reading surviving blocks over the network. Always rate-limit recovery traffic.
- Synchronous Means High Latency: Synchronous replication guarantees zero data loss (), but client latency is tied to the slowest network link.