by Kondasamy Jayaraman

Module 23 · Replication & consistency

Advanced · by Kondasamy Jayaraman

Three copies of one count, and the day they disagree

Keeping a copy of your data in every region makes a shop fast and keeps it open. It also lets two regions sell the last item. Here you watch Larkspur’s three warehouses drift apart, then choose what each product can risk.

New to databases? Start with Databases & indexes.

Read as

The whole idea in one example

One drill press, two receipts

West, cut off

sold

10:08

Dev buys it. West’s count said 1.

North

sold again

10:12

Eve buys it too. North never heard.

Counts come from a simulated morning: Larkspur’s own orders and planning numbers, not a measurement of any real database.

How it works

Four ideas carry the module

  1. 1 Copies lag

    West still counts a hinge North sold

    Dynamo describes itself as an eventually consistent data store: all updates reach all replicas eventually.

    Source, checked 24 October 2026

  2. 2 The line goes down

    Stay open or stay right, not both

    Gilbert and Lynch (2002) proved that when the network can lose messages, no read/write data store can guarantee both availability and atomic consistency: the CAP theorem.

    Source, checked 24 October 2026

  3. 3 Quorums

    Reads and writes that always overlap

    Amazon’s Dynamo paper (2007): R is the fewest replicas a read must reach and W the fewest a write must reach; setting R + W > N gives a quorum-like system.

    Source, checked 24 October 2026

  4. 4 Who wins

    One place decides, one order at a time

    In the Dynamo paper, “last write wins” means that when versions diverge, the one with the largest timestamp is kept as the correct version.

    Source, checked 24 October 2026

The story

Larkspur’s count goes regional

Larkspur Supply Co. copies its stock count to three warehouses; the team finds how the last hinge sells twice, and picks what each product can risk when the line goes down. You’re on the team that keeps the counts.

19
orders and stock checks in Larkspur’s morning, the one every chapter runs
3
warehouses, each with its own copy of every stock count
1
drill press in stock, the one-off the owner will never sell twice
9
stock policies tie for best in chapter 7

Your path

The chapters

  1. Chapter 1

    One count, three copies

    When North sells a hinge, what do the other copies show?

  2. Chapter 2

    Two buyers, one hinge

    What happens when two warehouses sell the last unit at the same moment?

  3. Chapter 3

    The link goes down

    When the warehouses can’t talk, should West keep selling?

  4. Chapter 4

    Quorums

    How many copies must a read and a write reach to never miss the latest sale?

  5. Chapter 5

    Who wins

    When two writes clash, which one wins, and what is lost?

  6. Chapter 6

    Eventually

    Why can a customer miss their own order, and how do you stop it?

  7. Chapter 7

    Set Larkspur’s stock policy

    Which settings never sell the drill press twice and refuse the fewest orders?

Who it’s for

  • Engineers
  • Product managers
  • Analysts
  • No code needed

Anyone whose product keeps the same data in more than one place, and who wants to know why it sometimes sells what it doesn’t have. No background needed beyond what a database is.