All glossary terms

Serving

Consistent hashing

Routing each request family to a card by hashing its key, so most families keep their card and their resident prefix even when the fleet grows or shrinks.

Hash routing makes a cache hit a routing decision: hash the request family key, land it on one card, and that card keeps the family preamble resident so every subsequent request starts from a prefix cache hit instead of a full prefill. The design question is what the hash does when the fleet changes, because rented fleets change constantly.

Naive modulo - family index mod card count - redraws nearly every assignment on a resize, so a fleet that doubles re-prefills half its preamble copies at prices of hundreds of megabytes each. Consistent hashing solves this by placing both families and cards on one shared hash ring: each family belongs to the card clockwise of its position, so adding or removing a card moves only the arc that new card owns. Doubling a fleet with a ring still moves families, but modulo doubling moves far more, and the moved share is what the rebuild bill is multiplied by.

The remaining questions are load ones, and they answer themselves once the numbers are visible: one hot family lands entirely on one card, so the busiest card needs an overflow rule or a sharded hot copy; and evicted families - the ones the scratch could not keep - fall back to full prefill no matter how good the ring is, which is why the scratch size gets compared against the copy count the routing plan demands.

A worked example

A fleet grows from 64 cards to serve a rising arrival rate. Compare modulo routing against a consistent hash ring for 64 cached prompt families, where each displaced family must re-prefill a 384 MB preamble copy.

  1. Modulo doubling, 64 to 128 cards: a family keeps its card only when its hash mod 128 stays under 64, so exactly 64/128 = 50 percent of families remap.
  2. Rebuild cost: 64 displaced families x 384 MB = 24,576 MB, about 24.6 GB of re-prefill work across the fleet on the resize itself.
  3. With a hash ring, adding cards one at a time takes over only the new arcs, so roughly 1 of 65 families moves per added card - the ring turns half the fleet into a few percentages of it.

The resize is where routing meets arithmetic: modulo moves 50 percent of families and about 24.6 GB of preamble, and a hash ring moves a small fixed slice per added card.

Where this shows up

Test yourself

Related terms