Skip to content
Blockchain Association of Cameroon
BAC-L0-FOUND-1073 h

Distributed systems: latency, partitions, consistency

Why a distributed system cannot guarantee everything at once, and how that constraint shapes every consensus protocol.

  • Describe the effect of a network partition on a replicated system
  • Place a given system on the consistency/availability trade-off
  • Explain why no reliable global clock exists

A shared ledger lives on distant machines that talk only through slow, sometimes lost messages. In this workshop you measure what distance costs, see what a network cut does to copies of the same data, learn exactly what the CAP theorem says (and what it does not), and understand why no clock can serve as a universal judge. These constraints are not implementation flaws: they explain the shape of every consensus protocol you will study next.

Lessons 1/4 · 20 min

Latency and bandwidth: what distance costs

The starting question

You send a 5 MB file to a distant server. Your connection advertises 40 Mbit/s. How long will it take? Many answer: "5 MB = 40 megabits, so one second". That is wrong as soon as the server is far away. The latency is missing.

Two different quantities

  • Bandwidth: how many bits pass per second, in Mbit/s. It is the width of the pipe.
  • Latency: the time for a message to go from one point to another. Often we speak of the round-trip time (RTT). It is the length of the pipe.

A truck can carry an enormous amount of data (high bandwidth) but take a day (high latency). An SMS is small but arrives quickly.

A physical limit

Light in an optical fibre travels at about 200,000 km/s, roughly two thirds of its speed in vacuum. This is not an operator's flaw: this limit holds for conventional fibre; only the speed of light in vacuum is an absolute bound (microwave or hollow-core links get closer to it, without exceeding it). Take two hypothetical data centres 6,000 km apart:

  • one way: at least 6,000 ÷ 200,000 = 0.03 s = 30 ms;
  • round trip: at least 60 ms, in reality more, because fibre does not follow the straight line and routers add delays.

A worked example: the workshop's simplified model

Total time = (number of setup round trips) × RTT + size × 8 ÷ bandwidth. For 5 MB, 40 Mbit/s, RTT = 120 ms and 2 setup round trips:

  • transmission: 5 × 8 ÷ 40 = 1 s = 1,000 ms;
  • setup: 2 × 120 = 240 ms;
  • total: 1,240 ms.

Divide the size by 10 (500 KB): transmission falls to 100 ms but setup stays at 240 ms. For small messages latency dominates; for big files, bandwidth. A consensus message is small: the whole life of a consensus protocol is therefore paced by round trips.

Explore the request-path tool: DNS, TCP, TLS then HTTP chain several exchanges before the first useful byte flows. The model is deliberately simplified (for example it ignores reused connections).

The key point: slow or dead?

Node A sends a request to B and waits. After 2 seconds without an answer, what does A know? Nothing certain. B may have crashed, the network may have lost the message, or the reply may arrive in 3 seconds. From A's side these three cases are indistinguishable. The only weapon is the timeout, which is an assumption, not a proof: set too short, it declares a merely slow node "dead"; too long, it delays every reaction.

What this does NOT guarantee

A low RTT measured this morning does not guarantee tomorrow's. Latency varies (congestion, changed route); a serious protocol assumes no bound, or states one explicitly as an assumption.

Recap

  • Bandwidth = width of the pipe, latency = its length; small messages are dominated by latency.
  • Light in fibre sets a minimum of roughly 1 ms of round trip per 100 km (an order of magnitude).
  • A slow node cannot be told from a dead one; a timeout is a bet.

Interactive tool

Journey of a web request

Four steps between typing an address and seeing the page, and what someone listening on the network (public Wi-Fi, ISP) sees at each step.

Step 1 of 4

DNS lookup

The browser asks a resolver for the IP address of example.org (A/AAAA query).

What an on-path observer sees

HTTP (unencrypted)
  • The name asked for (example.org) and the IP returned, in the clear on port 53, unless encrypted DNS is used.
  • Who queries which resolver, and when.
HTTPS (TLS)
  • Same: HTTPS does not protect the DNS query. The name is visible unless encrypted DNS (DoH, DoT, DoQ) is enabled.
  • With encrypted DNS: the observer only sees that you talk to your resolver, not the name or the answer. The resolver itself still sees the name.

"On-path observer": a third party who reads traffic without being one of the two endpoints (Wi-Fi network, ISP, intermediate router). They do not see what the server itself sees.

Lessons 2/4 · 25 min

Replicas and partitions: when the network splits

The starting question

For a ledger to survive a machine failing, we replicate it: three copies, A, B and C, on three sites. One day, the cable between A and the other two is cut. A, B and C all run, but A no longer receives anything from B and C, and vice versa. What should the system do?

The concept: the partition

A network partition is a situation where nodes are split into groups that can no longer exchange messages, while every node is running. It can come from a cut cable, a saturated router, a misconfigured firewall, or an attacker. From A's side, it looks like B and C failing (lesson 1).

A worked example: a replicated balance

An account with balance 100 is replicated on A, B, C. Partition: A is alone on one side; B and C together on the other.

  • At 10:00, Aminata withdraws 80 through A.
  • At 10:01, Bello, who shares the account, withdraws 80 through B.

Option 1: everyone answers (availability). A accepts (local balance 20), B accepts (local balance 20 on B and C). The network recovers: both withdrawals are in the log, the balance "should" be 100 − 160 = −60. The invariant "no negative balance" is broken; you must reconcile (cancel a withdrawal? overdraft?).

Option 2: only the majority answers (consistency). A quorum rule requires 2 replicas out of 3 to confirm every operation. B and C (2 of 3) have the quorum and accept Bello's withdrawal. A (1 of 3) does not: it refuses to answer Aminata ("try again later"). No negative balance, but Aminata is blocked.

Why quorums work: overlapping

With N replicas, if a write must be confirmed by W replicas and a read queries R replicas, with R + W > N, every read meets at least one up-to-date replica. Here N = 3, W = 2, R = 2: 2 + 2 > 3. Two sets of 2 out of 3 always overlap (in at least one node). Careful: R + W > N only guarantees overlap between a read and a write. To also forbid two concurrent writes on disjoint sets, you additionally need 2W > N (here 2 × 2 > 3, which holds). With N = 5, W = 2 and R = 4, R + W > N holds, yet two writes of 2 replicas each can be disjoint. In our example, two groups each holding a write quorum therefore cannot exist side by side.

What each option sacrifices

Option 1 (answer everywhere)Option 2 (majority only)
Aminata (side A)servedblocked
Bello (side B, C)servedserved
After repairdiverging states to reconcileone single state, no conflict
Riskcontradictory writes, negative balanceunavailability for part of the clients

No option gives both "everyone is served" and "a single state".

Your turn

Reproduce the table with another scenario: 5 replicas, a 2 | 3 partition. Which half holds the quorum (3 of 5)? How many replicas can fail before the quorum is lost?

What this does NOT guarantee

A read and write quorum with R + W > N guarantees a read sees the latest confirmed write under simple assumptions (no faulty node, correct read protocol). It does not by itself settle concurrent writes, or failures that strike mid-write: that is the job of consensus protocols.

Recap

  • A partition cuts the network without stopping the machines; each side believes the other has failed.
  • Either answer everywhere (and reconcile later), or demand a majority (and block the minority).
  • With R + W > N, every read quorum meets a write quorum; with 2W > N, two write quorums also meet.

Lessons 3/4 · 25 min

Consistency or availability: reading CAP correctly

The starting question

CAP is often summed up as "pick two out of three: Consistency, Availability, Partition tolerance". The slogan is misleading. What does the theorem actually say?

The precise statement

The three words have a strict meaning:

  • Consistency (in CAP's sense): linearizability. The system behaves as if there were a single copy, and every read returns the latest completed write.
  • Availability: every request received by a non-failing node gets a response (not an error, not silence).
  • Partition: the network may lose or arbitrarily delay messages between nodes.

The theorem (Brewer's conjecture, proved by Gilbert and Lynch in 2002 in an asynchronous network model) says: during a partition, a system cannot be both consistent and available. The two options of lesson 2 are exactly these two branches.

The classic misreadings

  1. "Partition" is not a choice. In a real network, partitions happen. You do not choose whether to "tolerate" them: you choose, when they happen, between consistency and availability.
  2. Without a partition, you can have both. CAP says nothing about normal operation.
  3. It is not binary. Between "linearizable" and "everything diverges" lies a spectrum of guarantees.
  4. Even without a partition, there is a cost: guaranteeing consistency requires communicating, hence paying round trips (lesson 1). This latency/consistency trade-off is formalised in later work building on CAP (Abadi names it PACELC).

Two families of guarantees

Strong consistency (linearizable)Eventual consistency
Guaranteea single history visible, immediatelycopies eventually converge if writes stop
During a partitionthe minority refuses to answereveryone answers, possibly with stale values
Costlatency, partial unavailabilityconflicts to resolve, stale reads
Example usebank balance, ownership registrynews feed, "like" counter

A worked example: reconciling by "last write wins"

Two replicas each accept a change to the same field during a partition: replica A writes "address = Douala" at local time 10:00:05, replica B writes "address = Yaoundé" at 10:00:03. Rule "last write wins" (LWW): keep 10:00:05, so Douala. But if A's clock ran 4 seconds fast, A's write actually happened at 10:00:01, before B's: the wrong one was kept. The rule depends on clocks that are not reliable (lesson 4). It is simple but loses writes.

Where do blockchains fit?

  • Proof-of-work networks such as Bitcoin behave, during a partition, rather like available systems: each side keeps producing blocks, then, on repair, the chain with the greatest cumulative work wins and the other side is abandoned. This is eventual consistency with probabilistic finality. This characterisation is common but simplifying.
  • BFT-type protocols with deterministic finality require more than two thirds of the votes: without them, they halt rather than contradict themselves (you will see this in detail in workshop 108).

What this does NOT guarantee

Filing a system under a "CP" or "AP" label is a simplification: the same database may behave differently depending on its configuration, its operations and its failures. The label is for asking the right questions, not for concluding.

Recap

  • CAP: during a partition, linearizable consistency and availability of everyone cannot coexist.
  • The partition is not an option; what you choose is the reaction.
  • Strong consistency = no divergence but possible unavailability; eventual consistency = answers everywhere but reconciliation.

Lessons 4/4 · 25 min

No global clock: ordering without time

The starting question

Two machines claim: "I received the transaction at 10:00:05" and "I received the other at 10:00:04". Which arrived first? If clocks could be trusted, the answer would be immediate. They cannot.

Why no reliable global clock exists

  1. Drift. Each machine has its own quartz oscillator. An ordinary quartz can drift by a few tens of parts per million: 20 ppm gives 20 × 10⁻⁶ × 86,400 s ≈ 1.7 seconds per day. The gap grows until someone corrects it.
  2. Synchronisation is imperfect. Protocols such as NTP bring the gap down to a few milliseconds to a few tens of milliseconds over the public Internet, but the gap stays unknown and variable, since it depends on network delays, themselves asymmetric and uncertain (lesson 1).
  3. A remote clock cannot be read instantly. Even a perfect clock cannot be read from a distance without delay: the message carrying the time has an unknown, possibly asymmetric delay.

Practical consequence: if two events are closer together than the clocks' uncertainty, their order according to the clocks is meaningless.

Ordering without the time: the "happened-before" relation

A safe order exists all the same, through causality: event a happened before b if (1) a and b are on the same machine and a is earlier, or (2) a is the sending of a message of which b is the receipt, or (3) by transitivity. Two events with no such chain are concurrent.

Lamport logical clocks (Lamport, 1978) give each event a counter:

  1. before each local event or send, increment your counter by 1;
  2. attach the counter to messages sent;
  3. on receipt, set the counter to max(local counter, received counter) + 1.

A worked example

  • P1: local event a → 1; send m1 → 2 (m1 carries 2).
  • P2: local event → 1; receive m1 → max(1, 2) + 1 = 3; send m2 → 4.
  • P3: five local events → 5; receive m2 → max(5, 4) + 1 = 6.

Guaranteed property: if a happened before b, then L(a) < L(b). The converse is false: L(a) < L(b) does not imply a preceded b; they may be concurrent. Two concurrent events can even have the same counter (ties are broken by node id to obtain an arbitrary but consistent total order).

And blockchains?

A block carries a timestamp, but it is not a reliable clock: in Bitcoin, the consensus rule requires a block's time to exceed the median of the previous 11 blocks and not to be more than two hours ahead of the network time as the node computes it (how that time is computed depends on the client). A window of several hours shows the timestamp is a coarse bound, not a stopwatch. What really orders blocks is their chaining (each block cites the previous one) and the chain-selection rule.

What this does NOT guarantee

A logical clock says nothing about the real duration between two events, nor about civil time. For billing, compliance or a legal log, you need timestamps from a trusted source, with their margin of error.

Recap

  • Clocks drift and their synchronisation has a margin of error; no reliable global time exists.
  • Causality (send before receive) gives a safe partial order; Lamport turns it into a counter.
  • L(a) < L(b) does not imply "a before b"; only the converse is guaranteed.

Guided lab

The browser cannot launch Docker containers or cut a real network: this lab trains calculation and reasoning on scenarios, and the real experiment (three containerised replicas, a provoked partition) is the independent lab. Here you compute transfer times, predict what a replicated system answers during a partition, and compute Lamport clocks. The numbers of the generated exercise change at each attempt.

A browser is no substitute for a real terminal: this lab trains reading and reasoning; the real hands-on practice is in the independent lab.

A certified account is required

Graded activities record results in your name and are the basis for a credential. They therefore need a complete certified file and a current consent. Filling in the file does not verify your identity; the Secretariat can verify it afterwards ("Verified" badge).

  1. 1.Compute a transfer time

    The brief gives a file size, the bandwidth, the RTT and the number of setup round trips. Apply the simplified model from lesson 1: transmission time = size in MB × 8 ÷ bandwidth in Mbit/s (in ms), then total time = round trips × RTT + transmission. Round to the nearest integer.

  2. 2.Observe a request's exchanges

    In the request-path tool, step from DNS to HTTP. Count the exchanges that precede the sending of application data. Imagine each costs an RTT of 120 ms. This step has nothing to submit; note your count for the next step.

    Interactive tool

    Journey of a web request

    Four steps between typing an address and seeing the page, and what someone listening on the network (public Wi-Fi, ISP) sees at each step.

    Step 1 of 4

    DNS lookup

    The browser asks a resolver for the IP address of example.org (A/AAAA query).

    What an on-path observer sees

    HTTP (unencrypted)
    • The name asked for (example.org) and the IP returned, in the clear on port 53, unless encrypted DNS is used.
    • Who queries which resolver, and when.
    HTTPS (TLS)
    • Same: HTTPS does not protect the DNS query. The name is visible unless encrypted DNS (DoH, DoT, DoQ) is enabled.
    • With encrypted DNS: the observer only sees that you talk to your resolver, not the name or the answer. The resolver itself still sees the name.

    "On-path observer": a third party who reads traffic without being one of the two endpoints (Wi-Fi network, ISP, intermediate router). They do not see what the server itself sees.

  3. 3.Predict a read during a partition

    Three replicas A, B, C hold x = 5. A partition isolates A from B and C. The system is configured to always answer. One client writes x = 7 through B, then another client reads x through A. Reason with the definitions from lesson 3 (availability, consistency) and answer the check question.

  4. 4.Compute a Lamport clock

    Apply lesson 4's three rules to the scenario in the check question: three processes, local events, messages. Write the counters in pencil, event by event. The classic mistake is forgetting the "+ 1" on receipt, or not incrementing for the send.

Security exercise — Manufacturing a partition: eclipsing a node

A shopkeeper runs a full node of a public blockchain to confirm sales. The node opens 8 outbound connections to peers chosen from a list of addresses. An attacker controls hundreds of IP addresses and manages, over restarts, to make all 8 of the shopkeeper's peers theirs: this is an eclipse attack. The node is not stopped: it works, but its view of the network is entirely chosen by the attacker. Note that the eclipse removes the race against the honest network, not the work: the attacker must still produce the work matching the confirmations the merchant waits for, but without competition, which costs far less than a 51% attack.

The attacker then presents a private branch where their payment is confirmed, while the rest of the network has never seen it. The shopkeeper hands over the goods. Later, the node reconnects to honest peers, adopts the main chain, and the payment vanishes: this is a double spend. From the shopkeeper's side, it was just one more partition (lesson 2), but manufactured by an adversary, and against which no consistency is possible without information from elsewhere.

Which measures really reduce this risk? Tick all the right ones.

Workshop quiz

Eight questions drawn from a larger pool, 70% to pass. It opens once every lab checkpoint is passed. You can retake it: the draw changes.

A certified account is required

Graded activities record results in your name and are the basis for a credential. They therefore need a complete certified file and a current consent. Filling in the file does not verify your identity; the Secretariat can verify it afterwards ("Verified" badge).

Independent lab (outside the site)

Not graded online: do it on your own machine and publish it to your Git repository.

To do on your machine, outside the site. You need Docker, and the tc tool (with its netem module) if you want to simulate latency.

  1. Write a small Python service (standard library) that keeps an in-memory key-value dictionary and exposes GET /k and PUT /k; add a version counter to each value. Put it in a Docker image.
  2. Start three containers A, B, C on a Docker network you define. Clients write to any replica; each replica tries to relay writes to the other two.
  3. Cause a partition by disconnecting A from the network (docker network disconnect). Write different values for the same key on A's side and on the B-C side, record the states, then reconnect and observe the divergence.
  4. Add artificial latency on an interface (tc qdisc add dev eth0 root netem delay 100ms, only INSIDE the container started with --cap-add NET_ADMIN, never on your host's interface; undo with tc qdisc del dev eth0 root) and measure the effect on the time of a write that waits for confirmation from two replicas.
  5. Design and document a post-partition reconciliation strategy (for example: last write wins, or merging by counters, or refusing to write without a quorum). Test it. In NOTES.md write which invariant it preserves, and which write it may lose.

Use only fictitious data and publish no secret. Deliverable: the code, the experiment write-up (states before, during, after the partition) and NOTES.md.

Takeaways

  • For small messages, latency dominates bandwidth; a node cannot tell a slow peer from a dead one, a timeout is only a bet.
  • A partition cuts the network without stopping the machines: you must choose between answering everywhere (then reconciling) and demanding a quorum (and blocking the minority).
  • CAP says: during a partition, linearizable consistency and total availability cannot coexist. The partition is not a choice; the reaction is.
  • No reliable global clock exists; causality safely orders what is linked, and Lamport clocks turn that into a counter.
  • A partition manufactured by an attacker (eclipse) can show a fully valid but false view; only independent sources reveal it.

Common misconceptions

  • Misconception : "CAP means choosing two properties out of three, so I can choose not to have partitions."

    In fact : Partitions happen in any real network. The choice is about the reaction during a partition: consistency or availability.

  • Misconception : "If a node stops answering after the planned delay, it has crashed."

    In fact : It may be slow, cut off by a partition, or just late. A timeout is an assumption, not a proof.

  • Misconception : "With NTP-synchronised clocks, timestamps give the exact order of events."

    In fact : NTP leaves an unknown, variable margin of error. To order close events, rely on causality rather than on the time.

  • Misconception : "If everything my node receives is valid, my view of the network is necessarily correct."

    In fact : An attacker can show only valid data and hide the rest. A message's validity does not prove the view is complete.

Glossary

Latency (RTT)
Time for a message to go from one point to another; the round-trip time (RTT) is about twice that, plus processing.
Network partition
A situation in which running nodes are split into groups that can no longer exchange messages.
Quorum
The minimum number of replicas whose agreement is required to validate an operation; a majority guarantees that two quorums overlap.
Linearizability
A strong form of consistency: the system behaves like a single copy, and every read returns the latest completed write.
Eventual consistency
A weak guarantee: if writes stop, all replicas eventually converge to the same value.
Lamport clock
A logical counter such that if one event causally precedes another, its counter is smaller.
Eclipse attack
An attack where an adversary controls all of a node's peers to impose a falsified view of the network.