Reference · Cheat sheet
Lesson 0007 distilled — one primary, oplog, elections, failover. Built to print.
One primary (all writes go here). One or more secondaries (replicate via oplog). Optional arbiter (votes only, holds no data).
Standard deployment: 3 full nodes — tolerates 1 failure. 2-node set requires arbiter for elections.
local.oplog.rs — a capped collection on every member.
Logical: records operations (insert/update/delete), not page changes.
Idempotent: applying the same entry twice = same result as once. Enables safe crash recovery.
Window: when full, oldest entries overwritten. Lagging secondary that misses the window needs a full resync.
Heartbeat every 2s. If no primary heard for electionTimeoutMillis (default 10s), a secondary calls an election.
Winner must have: most up-to-date oplog AND votes from a majority of voting members.
Election window ~10–30s: writes fail during this period. Use retryable writes (default in drivers ≥4.2).
primary (default): all reads → primary. Strong consistency, always read your own writes.
secondaryPreferred: secondary if available, else primary. Possible stale reads.
secondary: always secondary. Accepts staleness for scale-out reads.
| Postgres WAL | MySQL binlog | MongoDB oplog | |
|---|---|---|---|
| Level | Physical | Logical | Logical |
| Idempotent | No | Partial | Yes |
| Tied to version | Yes | Less so | No |
| Location | pg_wal/ | binlog files | local.oplog.rs |
Automatic election on primary failure — no Patroni/PaceMarker needed. Applications see a brief write gap (~10–30s), then a new primary is elected.
Priority 0 member: can vote but never becomes primary (good for distant data centers).