Why this matters
- Payment flows are chains of cause and effect: authorize → capture → settle; readers must not see settle before capture.
- Global serializability is expensive across ShardPay's 256 shards; causal consistency preserves what users actually care about.
- Session guarantees (read-your-writes) are a weak form of causal consistency every mobile banking app expects.
- Interviewers map happens-before to concrete API and messaging design, not just Lamport's paper.
The happens-before relation
Event A happens-before B (written A → B) if A could have influenced B. Same-thread order, lock unlock before lock acquire, message send before receive, and transitive chains all create → edges. If neither A → B nor B → A, events are concurrent.
ShardPay models transfer lifecycle as a DAG: TransferInitiated → FundsReserved → TransferCompleted → SettlementPosted. Any read path that serves merchant dashboards must not show SettlementPosted without all predecessors visible for that transferId.
Walkthrough: the out-of-order dashboard
Before causal guarantees, a merchant refreshed their dashboard and briefly saw "settled" on a transfer still showing "pending" in the detail drawer — different read replicas lagged differently. ShardPay attached a causal_token (vector summary) to each API response; subsequent reads pass the token so the load balancer routes to a replica at least as fresh as the token requires.
Key points
- Happens-before (→) — a partial order capturing cause and effect, not wall-clock time. ShardPay's saga orchestrator emits events only after predecessor steps commit so downstream consumers inherit a valid → chain per transfer.
- Causal consistency — every read observes a state that respects → for all events it sees. ShardPay merchants never see a refund before the original charge on the same transferId, even though unrelated transfers on other shards may appear in any order.
- Session guarantees — read-your-writes, monotonic reads, and monotonic writes are progressively stronger session properties. ShardPay's mobile API returns a session token after POST /transfers so the next GET from the same device reads a replica that includes that write.
- Linearizability vs causal — linearizability orders all operations as if on one global timeline; causal only orders related ones. ShardPay uses linearizable balance reads on the hot path (single shard) and causal ordering for cross-service event projections.
- CRDTs — conflict-free replicated data types merge concurrent updates without coordination. ShardPay uses CRDT-style
G-Counteronly for non-financial stats (page views on merchant portal), never for ledger balances.
The rest of this guide is part of Pro
Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.
Still to come · 2 sections
- Causal consistency in the payment ledger
- Session tokens on the read path
Test yourself
Answer these before moving on — recall is what makes it stick.