The FLP result and the CAP theorem
Precise statements, assumptions and consequences of the FLP impossibility result for consensus and the CAP trade-off for replicated data, with proofs sketched, examples and exam guidance.
Drafted with Aria, reviewed by the AiCanCode.org team · Updated . How we write and check our notes. Spotted an error? Use Give Feedback at the bottom of the page.
Why it matters
Two common engineering problems in distributed systems are (1) getting a set of processes to agree on a single value (consensus) and (2) designing replicated storage that behaves predictably under network faults. The FLP result explains a fundamental limit on deterministic consensus in fully asynchronous systems with even one crash failure; the CAP theorem explains the trade-off between strong consistency and availability when network partitions can happen. Engineers use these results to choose system models (synchrony, failure detectors, randomness) and to design replication protocols (Paxos/Raft, quorum systems, eventual consistency) accordingly.
Key ideas
Start from clear definitions and assumptions used by both results.
Asynchronous system: a model where there are no fixed upper bounds on message delivery time or on how fast processes run. (Definition used by FLP and by many CAP formalizations.)
Deterministic algorithm: an algorithm whose actions are fully determined by its current state and incoming events (no random choices).
Crash failure: a process may stop taking steps at some point and never recover; it does not behave arbitrarily (not Byzantine).
Consensus problem: Each process starts with an initial value (commonly 0 or 1). The system must satisfy three properties:
- Agreement: all non-faulty processes that decide, decide the same value.
- Validity: if every process starts with value v, then any decided value must be v (often: decided value must be one of the proposed values).
- Termination (also called liveness): every non-faulty process eventually decides. Bolded when first used: Agreement, Validity, Termination.
FLP theorem (exact statement, assumptions up front): In an asynchronous message-passing system with at least two processes, if processes run a deterministic algorithm and up to one process may crash (stop) (or more generally at least one crash is possible), then there is no algorithm that always satisfies Agreement, Validity and Termination in every execution. In other words, deterministic consensus is impossible in this model. Assumptions required: asynchronous timing, deterministic algorithms, crash failures, reliable channels (no loss, duplication, or corruption), processes may take steps arbitrarily slowly.
Proof idea (standard exam-style structure, to be drawn as a configuration graph):
- Define a configuration as the global state: states of all processes and messages in transit.
- Define valency of a configuration: it is 0-valent if every possible continuation leads to decision 0; 1-valent if every continuation leads to decision 1; bivalent if both decisions are possible depending on scheduling.
- Show there exists at least one bivalent initial configuration (by considering all-0 and all-1 initial states and using continuity argument: changing one process's input must at some point flip valency).
- Show there must exist a bivalent configuration C and a single event e (deliver of one message or a process step) such that applying e to C leads to a univalent configuration (call it critical event). Now use asynchrony: delay event e and let other processes proceed; if the process whose message e concerns crashes before e, some paths can still decide the other value — reach contradiction with univalence. This constructs a fair execution that never forces a decision (Termination fails).
- Conclude no deterministic algorithm can guarantee termination in all asynchronous executions with one possible crash.
Diagram to draw for an exam: Draw a directed graph where nodes are configurations and labeled edges are single events (deliver message m to process p or p takes a local step). Mark some nodes 0-valent, 1-valent, and a node bivalent. Show an edge from a bivalent node to a 0-valent node (critical event). Then show delaying that edge and letting another event cause a 1-decision — annotate contradiction.
Consequences of FLP: Deterministic consensus requires weakening assumptions: add partial synchrony (bounded but unknown message delays), add failure detectors (e.g., Omega), or use randomised algorithms (probabilistic termination). Practical consensus protocols (Paxos, Raft) assume some synchrony or rely on leader election and timeouts. Note: FLP only precludes guaranteed Termination (a liveness property); Agreement and Validity (safety properties) can still be satisfied in all executions.
CAP theorem (Brewer’s idea made formal by Gilbert and Lynch): Define the three properties precisely:
- Consistency (C): usually formalized as linearizability or atomicity — each operation appears to take effect instantaneously at some point between its invocation and response; informally, reads see the most recent write.
- Availability (A): every request made to a non-failed node receives a response (not an error) in a finite time.
- Partition tolerance (P): the system continues to meet its consistency and availability properties despite arbitrary network partitions (message loss between subsets of nodes).
Formal statement: In a network that can partition (messages may be lost between groups of nodes) and in an asynchronous model where partitions are possible, a replicated data system cannot guarantee both Availability and strong Consistency at the same time. In presence of a partition, you must choose either C or A.
Example proof sketch (two-replica illustration): Two replicas A and B, initially storing value x0. A network partition separates A and B. A client writes x1 to A and gets an acknowledgement (to keep Availability). Another client reads from B: if B is available it must respond under Availability, but if B has not learned x1 due to the partition, the read will return x0 — violating strong Consistency. If the system had blocked the read to preserve consistency, Availability would be violated. Thus both cannot hold.
Relation between FLP and CAP: both rely on asynchrony and show limits. FLP is an impossibility theorem about deterministic consensus termination with crash failures. CAP is an impossibility statement about replicated storage trade-offs under partitions. They are related but different results: FLP concerns agreement under crashes and unpredictable timing; CAP concerns data semantics under partitions and availability.
Formulas
Agreement: ∀ p_i, p_j (non-faulty), decision(p_i) = decision(p_j) — all non-faulty processes decide the same value.
Validity: if ∀ p_k initial = v then decided value = v — decided value must come from proposed values.
Termination: ∀ p_i (non-faulty), p_i eventually decides — liveness requirement.
Valency(config) ∈ {0-valent, 1-valent, bivalent} — classification of global states by possible decisions.
(Note: these are logical conditions, not SI-unit formulas.)
Worked examples
FLP-style proof sketch (exam model answer):
- System: three processes P1,P2,P3, binary inputs {0,1}, up to one crash, asynchronous.
- Step 1: Consider initial configurations where all inputs are 0 (call I0) and all inputs are 1 (I1). By Validity, I0 is 0-valent and I1 is 1-valent.
- Step 2: Change inputs one process at a time from 0 to 1: I0 -> I' -> ... -> I1. There must exist two consecutive initial configurations that differ only in one process's input where valency changes from 0 to 1. The earlier is bivalent.
- Step 3: Let C be that bivalent configuration. From the bivalency of C, there exist continuations that lead to decision 0 and to decision 1, but not necessarily in a single step. By the standard FLP critical-step lemma, there exists some single event e and some bivalent configuration (possibly C or a descendant) such that applying e yields a univalent configuration; e is called a critical event.
- Step 4: Using asynchrony, delay the event that would force a decision and let other events occur; simulate a run where the sender of the delayed message crashes before sending. Show both 0 and 1 decisions are still possible in continuations, so no single event can force a unique decision in all schedules; thus one can craft a fair infinite schedule that never reaches a decision — Termination violated.
- Final line (conclusion): Therefore no deterministic algorithm can guarantee consensus termination in this model.
CAP example (two replicas):
- Two replicas R1 and R2; network partition splits them. Initially value v0.
- Client C1 writes v1 to R1 and R1 acknowledges immediately (system favored Availability). R2 is isolated and still holds v0.
- Client C2 reads from R2 and gets v0. If strong Consistency (linearizability) is required, C2 must see v1 (contradiction). To preserve Consistency, system would have to block the write ack at R1 (violating Availability) or block the read at R2. Thus cannot have both A and C during the partition.
- Conclusion: choose CP (consistent but not available during partitions) or AP (available but not strongly consistent during partitions).
Common mistakes
- Interpreting CAP’s "Consistency" as SQL transaction consistency; CAP usually means strong consistency (linearizability). Always state which consistency model you mean.
- Claiming CAP says you can never have CA — CA is possible only when partitions never occur (unrealistic for wide-area systems).
- Mixing up Availability definition: availability in CAP means every request to a non-failed node returns a response, not necessarily the latest value.
For your exam
Kinds of questions:
- Definitions and short notes: define FLP assumptions, define CAP's C/A/P, describe valency.
- Derivation/proof: give the FLP impossibility proof sketch with a configuration graph and valency argument; give the two-replica CAP sketch showing contradiction.
- Diagrams: draw configuration graph for FLP with a bivalent node and critical event; draw partitioned replicas and client operations for CAP.
- Long answers: compare FLP and CAP, explain how Paxos/Raft relate to these results (they assume partial synchrony / leader election), describe failure detectors and randomized consensus.
What a full-marks answer includes:
- Clear statement of assumptions for the theorem (asynchrony, determinism, crash failures).
- Formal definitions of consensus properties and of CAP properties (state which consistency model you use — linearizability is standard).
- For FLP: existence of bivalent initial config, definition of valency, description of critical event and construction of an infinite non-deciding execution; diagram described and labelled.
- For CAP: precise partition example, show why both C and A cannot be satisfied during the partition.
Quick check
- What three properties define consensus?
- In FLP, what is a bivalent configuration?
- In CAP, which two properties are in conflict during a network partition?
Answers: 1) Agreement, Validity, Termination. 2) A global state from which both decision values are still possible depending on the schedule. 3) Consistency and Availability (when Partition tolerance is required).
Finished this topic? Mark it so your progress, study plan and readiness keep up.
Stuck on something here?