Use PostgreSQL, etcd, and CouchDB to observe stale reads, quorum behavior, and write conflicts, then choose explicit consistency and availability guarantees.
Learning Objectives
Trace a write through primary and replica acknowledgement points.
Reproduce a stale read and explain read-your-writes and eventual convergence.
Compare linearizable, sequential, and causal consistency using small histories.
Explain quorum overlap and its limits.
Apply CAP during a partition and PACELC during normal operation.
Observe concurrent revision conflicts and apply an explicit merge policy.
Select a consistency policy for one project operation using experimental evidence.
Core Concepts
Replication
Maintain copies of the same logical data on multiple nodes.
Stale read
A read that omits a relevant completed update.
Linearizability
An operation appears to occur at one point between its invocation and response, preserving real-time order.
Read your writes
A session observes its own completed writes in subsequent reads.
Eventual consistency
Replicas converge once updates stop and propagation and repair succeed.
Quorum
A required subset of replicas participating in an operation.
CAP
Under a partition, linearizability and availability cannot both be guaranteed for a replicated register.
PACELC
During partitions consider availability versus consistency; otherwise consider latency versus consistency.
Diagrams
A primary and a read replica
flowchart TD
P[Primary accepts stock update]
P -->|WAL records| R[Read replica]
R -->|Possibly stale stock| C[Reader]
Writes go to the primary. The standby replays the log and may serve older state until it catches up.
The log connects the primary and the replica
%%{init: {"flowchart": {"nodeSpacing": 16, "rankSpacing": 32, "padding": 6}, "themeVariables": {"fontSize": "22px"}}}%%
flowchart LR
C[Writer] -->|Write request| P
subgraph P[Primary]
direction TB
E[Transaction engine] -->|Generate WAL| L[Durable WAL log]
L -->|Log records| T[WAL sender]
E -->|Flush pages after WAL| D[Primary data pages]
end
P <-->|WAL to replica / progress to primary| S
subgraph S[Replica]
direction TB
R[WAL receiver] -->|Write and flush| W[Local WAL log]
W -->|Records in order| A[Replay process]
A -->|Apply changes| B[Replica data pages]
end
S -->|Read query result| Q[Reader]
Inside each boundary, arrows show local work. The network carries WAL records to the receiver and progress feedback to the primary. Replica reads see replayed changes. Client acknowledgement depends on the replication mode shown next.
Two connected members and one isolated member
flowchart TD
A[etcd1 accepts stock 9] <-->|Peer traffic| B[etcd2 stock 9]
B -.->|Network disconnected| C[etcd3 local stock 10]
The majority can accept a new value. The isolated live member retains an older value and cannot satisfy a fresh linearizable read.
Two edits from a shared cart revision
flowchart TD
S[Cart contains book] -->|Writer A adds pen| A[Branch A]
S -->|Writer B adds notebook| B[Branch B]
A -->|Replicate revision| C[CouchDB retains both branches]
B -->|Replicate revision| C
Both writers start from the same revision. Replication preserves divergent revisions, so application logic must inspect and resolve the conflict.
Examples, Discussions, and Project Ideas
Slide 1: Module goal — design reliable replicated systems
Choose replication and consistency guarantees that protect application correctness while balancing latency, availability, and failures.
Explain what a successful read or write guarantees across replicas.
Predict stale reads, quorum behavior, and outcomes during network partitions.
Use PostgreSQL, etcd, and CouchDB experiments to justify a consistency policy for your project.