Why this matters
- Conflating linearizability and serializability is a common senior interview trap — they apply at different granularities.
- Distributed locks and leader election need linearizable registers; multi-statement transfers need serializable transactions.
- Jepsen and formal tests verify linearizability claims — marketing "strong consistency" without specifying which guarantee is a red flag.
- ShardPay's architecture uses linearizable single-account updates inside serializable cross-table transactions on one shard.
Two ordering guarantees
A balance read immediately after a transfer must return the new value — that is linearizability on the account register. A batch job that debits one account and credits another on the same shard must execute as if no other transaction interleaved — that is serializability on the transaction schedule.
Linearizability is about individual operations and real-time ordering. Serializability is about multi-operation transactions and equivalent serial execution. ShardPay needs both, at different layers of the stack.
Definitions
- Linearizability — Each operation appears to take effect instantaneously at some point between its invocation and response, respecting real-time order. ShardPay's
GET /balanceafter a successfulPOST /transfersmust return the post-debit balance — not a value from before the transfer completed. - Serializability — The result of concurrent transactions is equivalent to some serial execution of those transactions. ShardPay's ledger applies
debit(A) + credit(B)inside one transaction so no concurrent transfer can observe A debited but B not yet credited. - Strict serializability — Serializable order that also respects real-time precedence. ShardPay's single-shard transfer path targets strict serializability: if transfer T1 completes before T2 starts, the serial order must place T1 before T2.
- Compare-and-set (CAS) — Atomic read-modify-write primitive underpinning linearizable updates. ShardPay's optimistic balance update uses
UPDATE accounts SET balance = :new WHERE id = :id AND balance = :expected— the database CAS enforces single-writer semantics per row.
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 · 3 sections
- Linearizability at the register layer
- Serializability at the transaction layer
- Testing and operating strong guarantees
Test yourself
Answer these before moving on — recall is what makes it stick.