Index

Free, with Google

Keep going, free.

A free account opens lessons 2 and 3 of every track, 33 more lessons, and keeps your progress and review cards on every device.

Start free with Google

A chalk plan

Open everything on chalk.

Every lesson, board, video, lab and paper, and the full review decks. Yearly is $39/year.

See plansStart free instead

Module 04 · System Design · The parts, properly · about 21 min to read

Watch: Choosing a datastore: the workload picks the book
▶ VideoPlay it as a journeyTutor comes with a plan

The last vada (inventory contention and locking)

The Right Book for the Job
The Right Book for the Job · Open board

The shelf of books a system keeps its facts in. This lesson opens one of them at a single line, the one that says how many vadas are left, and asks what happens when fifty people write on it at once.

Before you start. From The Right Book for the Job (databases, deeply) you need the book itself: the database, where the stall writes its facts down and reads them back, and which can bundle a few reads and writes into one all-or-nothing unit called a transaction. Transactions showed two such units reading the same line and both writing from it, so one write silently erased the other; The Two Ledgers Must Agree (Distributed Transactions) showed a lock left down by a helper who vanished, freezing everyone behind it. And Charged Twice (idempotency & exactly-once) showed that a retried request must carry one name for one intent, so the second try is not a second charge. Each comes back when it is needed.

Lesson 19 of 115 in System Design

The rest of this lesson is part of a plan.

A plan opens every lesson, board, video, lab and paper on chalk. Yearly is $39/year.

See plansAlready a member? Sign in

Or start free: a free account opens lessons 2 and 3 of every track.

In this lesson

  • 2 March 2014: Flexcoin, and an account that went below zero
  • The stall’s last vada: read, decide, write, and the race condition
  • Guard one: a lock, one hand on the tray at a time
  • Guard two: a version check, write only if nothing changed
  • Guard three: one line per item, a queue with one pair of hands
  • Paying takes two minutes: a hold, and its TTL

Terms it explains: race condition, lock, optimistic concurrency, queue, TTL, No guard, A lock, A version check, One step, One line, Change the TTL.

Lab

Fourteen real queries, six datastores. Which one answers yours without a second system?

Pick A wall of numbered boxes, press Add next question fourteen times, and watch Where the fourteen went fill elsewhere.

Open The right book for the job

Ten vadas left and a crowd reaching at once. How does the stall sell exactly ten, and what does making sure cost?

Drag Buyers reaching for each vada to 12, switch between Hold the tray and Check the count again, and watch Time to an answer.

Open The last vada

Related papers

Review System Design