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 10 · From Scratch · Sharded KV store · with code: Go · about 15 min to read

Watch: Sharding: splitting the ledger
▶ VideoPlay it as a journeyTutor comes with a plan

KV: the ring

Splitting the Ledger
Splitting the Ledger · Open board

One big book cut into several, with a rule that says which book each name goes into. This build writes that rule in Go, and then asks what happens to it on the day a new book arrives.

Before you start. Splitting the ledger (sharding) cut one book into several because one book, on one machine, could not keep up: every name had to live in exactly one of them, and a rule that anyone could work out on their own said which. Partitioning priced the part this lesson is about, which is what has to move when a machine joins. That is all you need: many machines, each holding a slice of the data, and a rule that picks the slice. This is the first of four builds. By the last one you will have a small key-value store (a program that stores a value under a name, like a coat check) spread across five machines, and you will kill two of them and watch it survive.

Lesson 71 of 117 in From Scratch

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

  • 10 April 2007: Last.fm adds a server, and the cache forgets everything
  • A clock face: consistent hashing, where a key walks to the next node
  • One mark per node is a lumpy clock: virtual nodes
  • Three owners, not one: the preference list
  • Part 1: why modulo moves 80%
  • Part 2: the ring’s owner lookup
  • Part 3: what virtual nodes buy, and the noise left over
  • Part 5: the walk that skips duplicates

Terms it explains: hash, node, ring, virtual node, preference list, consistent hashing, cross-shard query, hot shard, range vs hash partitioning, resharding, shard, shard key (partition key).

Lab

Names are mostly A–D. You split A–M / N–Z. What happens?

Start on Split by letter, read the load bars under The books, then switch to Scrambled name and press Add a book.

Open Splitting the ledger

The ring rehomes only 1/N of the keys when a server dies. So why does everyone run two hundred virtual nodes per server?

Drag Points on the ring per server from one upward, stay on Walk clockwise to the next server, and watch What the balance costs.

Open The ring

Related papers

Review From Scratch