Skip to content
Engineering Bible
System Design

System Design on consistency and transactions

A transaction is all or nothing, in one database

  • Atomic: every change in the group happens, or none does.
  • Isolated: transactions running together do not see each other's half-done work.
  • Durable: once committed, the change survives a crash.
  • This is easy inside one database and hard across two.

Strong consistency acts like a single copy

  • Once a write finishes, every later read sees it, whichever replica answers.
  • The formal name is linearizability. It needs coordination, which costs latency.
  • Use it where a wrong answer costs money: balances, stock, unique names.

Eventual consistency lets replicas catch up later

  • A write is accepted quickly and reaches every replica eventually.
  • Until then, two readers can see different values.
  • Fine for click counts on a short link. Not fine for who owns a custom link name.

In a network split, choose consistent or available

  • A partition is when machines cannot reach each other. Networks do this.
  • CAP theorem: during a partition, a node must refuse requests or risk wrong answers.
  • You cannot opt out of partitions, so “pick two of three” is misleading.
  • The choice can differ per feature inside the same system.

Without a split, you trade latency for consistency

  • PACELC adds the normal case to CAP: else, choose latency or consistency.
  • Waiting for replicas to confirm a write makes it consistent, and slower.
  • Abadi argues this everyday trade shaped databases more than CAP did.

Quorums tune the trade per request

  • Keep N copies. A write waits for W of them. A read asks R of them.
  • If R + W > N, every read reaches at least one copy that has the latest write.
  • Dynamo's common setting is N=3, W=2, R=2: one node can be slow or down.
N, W, RWhat you get
3, 2, 2Balanced. Reads overlap the latest write.
3, 3, 1Fast reads. Writes wait for every node.
3, 1, 1Fastest. R + W is not above N: stale reads.
Lower W and R mean lower latency and weaker consistency.

A saga replaces a transaction across services

  • Each service commits its own local transaction, then triggers the next step.
  • If a step fails, compensating actions undo the earlier ones, like a refund.
  • There is no isolation: others can see the half-finished state. Design for that.

All steps succeed

  1. Reserve stock
  2. Take payment
  3. Ship order

Payment fails

  1. Payment fails
  2. Release stockthe compensating action
  3. Order canceled
System Design in seven pages5 / 7