SystemExpertsSystemExperts
Pricing

Patterns

35 items

Horizontal Scaling Pattern

15mbeginner

Retry with Backoff Pattern

15mbeginner

Replication Pattern

25mintermediate

Caching Strategies Pattern

25mintermediate

Persistent Connections Pattern

20mintermediate

Load Balancing Pattern

20mintermediate

Fan-out Pattern

20mintermediate

Fan-in Pattern

20mintermediate

Circuit Breaker Pattern

20mintermediate

Eventual Consistency Pattern

25mintermediate

Queue-based Load Leveling Pattern

20mintermediate

Bloom Filters Pattern

20mintermediate

Time-Series Storage Pattern

20mintermediate

Bulkhead Pattern

20mintermediate

Batch Processing Pattern

20mintermediate

Write-Ahead Log Pattern

20mintermediate

API Gateway Pattern

20mintermediate

Backend for Frontend Pattern

20mintermediate

Sidecar Pattern

20mintermediate

Idempotency Pattern

20mintermediate

Rate Limiting Pattern

20mintermediate

Backpressure Pattern

20mintermediate

Pub/Sub Pattern

25mintermediate

Strong Consistency Pattern

30madvanced

Conflict Resolution Pattern

25madvanced

Leader Election Pattern

25madvanced

Consensus Protocols Pattern

30madvanced

CQRS Pattern

28madvanced

LSM Trees Pattern

25madvanced

Sharding Pattern

25madvanced

Event Sourcing Pattern

30madvanced

Stream Processing Pattern

25madvanced

Change Data Capture Pattern

25madvanced

Distributed Locking Pattern

25madvanced

Two-Phase Commit Pattern

25madvanced
System Design Pattern
Coordinationconsensuspaxosraftagreementdistributed-systemsadvanced

Consensus Protocols Pattern

Agreement among distributed nodes

Used in: etcd, CockroachDB, TiKV|30 min read

Summary

Consensus protocols enable distributed nodes to agree on a single value or sequence of values despite failures. They solve the fundamental problem of achieving agreement when nodes can crash, messages can be lost, and timing is uncertain. Paxos (theoretical foundation) and Raft (practical implementation) are the dominant protocols. Consensus underlies leader election, distributed locks, and replicated state machines. Understanding consensus is essential for building or operating any strongly consistent distributed system.

Key Takeaways

Majority Quorum is Key

Consensus requires majority (N/2 + 1) agreement. With 5 nodes, need 3 to agree. Any two majorities overlap, ensuring agreement. This is why clusters have odd numbers of nodes.

Safety vs Liveness Trade-off

Safety: Never agree on conflicting values. Liveness: Eventually make progress. FLP impossibility: Cannot guarantee both with async network. Practical systems sacrifice liveness under partition.

Raft is Practical Paxos

Raft designed for understandability. Strong leader, log replication, safety proofs. Used by etcd, CockroachDB, TiKV. Easier to implement correctly than Paxos.

Leader-Based for Efficiency

Single leader coordinates. Followers replicate. Avoids conflicts. Leader election when leader fails. Most practical consensus systems are leader-based.

Log Replication Pattern

Leader appends to log, replicates to followers. Commit when majority acknowledges. Apply committed entries in order. This is replicated state machine pattern.

Performance Costs

Consensus requires multiple round trips. Minimum 2 RTT for commit. Geographic distribution adds latency. Use consensus only when strong consistency required.

Pattern Details

The Two Generals Problem: Two generals must agree on attack time. Messages might be lost. No finite number of messages can guarantee agreement.

FLP Impossibility: In asynchronous system where one process can crash, no protocol can guarantee consensus will be reached.

Practical implication: Consensus systems use timeouts to detect failures. May block during partitions. Trade liveness for safety.

Raft Consensus

Trade-offs

AspectAdvantageDisadvantage