Cheat Sheets / Architecture & System Design

Distributed Data cheat sheet

13 commands from every lesson of Distributed Data — Replication, Partitioning & Consensus, on one page.

01 · Replication and consistency

PostgreSQL replication

pg_basebackup -h primary -U repl -D dir -R -X streamClone a primary and write standby settings (-R)
SELECT * FROM pg_stat_replication;On the primary: each standby's state, sync_state and lag
SELECT pg_current_wal_lsn();On the primary: current write position
SELECT pg_last_wal_receive_lsn(), pg_last_wal_replay_lsn();On a standby: how far it has received and replayed
SELECT pg_wal_replay_pause(); / pg_wal_replay_resume();Pause or resume replay on a standby (lab use)
synchronous_standby_names = 'ANY 1 (a, b)'Quorum commit: wait for any one of two standbys
SELECT pg_promote();Promote a standby to primary

Guarantees

LinearizableAcknowledged write visible to every later read, everywhere
CausalEffects after causes; strongest model available under partition
Read-your-writesA client always sees its own writes
W + R > NRead and write sets overlap; not linearizable by itself
PACELCPartition: A or C; Else: Latency or C
Fencing tokenMonotonic term number storage checks to reject a stale leader