Distributed systems and security · Part 31 of 36
Distributed systems fundamentals
Expert 20 min
Partial failure, timeouts and retries, replication, consistency models, CAP and consensus with Raft.
What you will learn
- You can explain partial failure and design safe retries with idempotency.
- You can compare strong and eventual consistency and state the CAP theorem correctly.
- You can describe how Raft elects a leader and replicates a log.
Before this: Patterns for safe concurrency
Partial failure
On one computer, things mostly work or crash completely. In a distributed system — services talking over a network — some parts fail while others keep going, and you often can't tell which. You send a request and hear nothing back. Did the request get lost? Did the server crash before or after doing the work? Is the reply just slow?
The famous "fallacies of distributed computing" list the wrong assumptions: the network is reliable, latency is zero, bandwidth is infinite, the network is secure, topology doesn't change, there is one administrator, transport cost is zero, the network is homogeneous.

Timeouts, retries and idempotency
Every remote call needs a timeout. After a timeout you may retry — but only safely if the operation is idempotent (lesson "HTTP"). "Set balance to 50" can be repeated; "add 10 to balance" cannot. The standard trick is an idempotency key: the client sends a unique id with the request, and the server remembers which ids it already processed.
Retry with exponential backoff and jitter (wait 0.1 s, 0.2 s, 0.4 s … plus a random part), and cap the number of attempts. Otherwise thousands of clients retrying in lockstep turn a short hiccup into an overload ("retry storm").
Replication and consistency
Data is copied to several machines (replicas) for availability and speed. The question is what readers see while updates propagate:
- Strong consistency (linearisability): the system behaves as if there were a single copy; every read sees the latest completed write.
- Eventual consistency: replicas converge if writes stop, but a read may return stale data in the meantime.
- In between: read-your-writes, monotonic reads, causal consistency.
CAP, stated correctly
The CAP theorem (Brewer's conjecture, proved by Gilbert and Lynch in 2002): when a network partition separates replicas, a system must choose between consistency (refuse some requests) and availability (answer, possibly with stale data). It is not "pick two of three" in normal operation — partitions are not optional. The PACELC extension adds: even without a partition, you trade latency against consistency.
Consensus with Raft
To agree on one sequence of updates despite crashes, replicas run a consensus algorithm. Raft (Ongaro and Ousterhout, 2014) was designed to be understandable:
- Servers are followers, candidates or a leader. If a follower hears no heartbeat within a randomised timeout, it becomes a candidate and asks for votes.
- A candidate that gets votes from a majority becomes leader for that term.
- Clients send writes to the leader, which appends them to its log and replicates them; an entry is committed once a majority has stored it.
- A new leader must have every committed entry — voters refuse candidates with less up-to-date logs.
Majorities mean a cluster of 2f + 1 servers tolerates f failures: 3 servers survive 1 failure, 5 survive 2. etcd (Kubernetes' store), Consul and many databases use Raft; Paxos is the older, equivalent family.
Clocks lie
Clocks on different machines drift, and NTP corrections can make time jump. Never order events across machines by wall-clock time alone; use logical clocks (Lamport timestamps, vector clocks) or the consensus log's order.
Key points
- Distributed systems fail partially; a missing reply doesn't tell you what happened.
- Use timeouts, retries with exponential backoff and jitter, and idempotency keys.
- Strong consistency acts like one copy; eventual consistency converges later.
- CAP: during a partition, choose consistency or availability; PACELC adds latency vs consistency.
- Raft elects a leader by majority and commits log entries once a majority stores them; 2f + 1 nodes tolerate f failures.
Flashcards
- Question: Why are retries dangerous without idempotency?
- Answer: The first attempt may have succeeded, so a retry could apply the change twice.
- Question: What does CAP say?
- Answer: During a network partition you must choose between consistency and availability.
- Question: How many failures does a 5-node Raft cluster tolerate?
- Answer: Two (it needs a majority of 3).
- Question: Why add jitter to backoff?
- Answer: So clients don’t retry in lockstep and overload the server again.
Check yourself
Think about your answer, then open it. In the app the quiz is interactive, earns points and brings back what you missed.
How many servers does a Raft cluster need to tolerate 3 failures?
Show the answer
7 servers
2f + 1 = 7, so a majority of 4 remains.
Source: Raft paper, 2014
During a network partition, a database refuses writes on the minority side. It chose…
- Consistency over availability
- Availability over consistency
- Neither
- Low latency
Show the answer
Consistency over availability
Refusing requests keeps a single consistent history.
Source: Kleppmann, ch. 9
Which operations are idempotent?
- Set the bed area to 4.2 m²
- Add 1 kg to the harvest total
- Delete order 1234
- Append a line to a log
Show the answer
Set the bed area to 4.2 m²; Delete order 1234
Setting a value and deleting a specific item have the same effect when repeated.
Source: MIT 6.5840
What does a Raft follower do when it hears no heartbeat before its election timeout?
- Becomes a candidate and requests votes
- Shuts down
- Accepts writes from clients itself
- Deletes its log
Show the answer
Becomes a candidate and requests votes
Randomised timeouts trigger elections when the leader seems gone.
Source: Raft paper, section 5.2
Sources
- MIT 6.5840 Distributed Systems (formerly 6.824), Robert Morris et al., MIT, 2025
- In Search of an Understandable Consensus Algorithm (Raft), Ongaro & Ousterhout, USENIX ATC, 2014
- Designing Data-Intensive Applications, Martin Kleppmann, O’Reilly, 2017
Facts checked on 2026-11-30. Skillgrove lessons are free learning material — no certificate and no accreditation.