Notespartitioning🌱 seedling

Request Routing

Also: Shard Routing · Partition-Aware Routing · Query Router · Shard Map

How a request finds the node that currently owns its key. The map from keys to nodes changes during rebalancing, so the hard part is keeping one authoritative copy and making stale copies harmless.

How it works

  • Any node forwards: clients hit any node; it forwards if it doesn't own the key. Cassandra learns ownership by gossip.
  • Routing tier: a stateless proxy holds the map and plans scatter-gather queries: Vitess VTGate, MongoDB mongos, Figma DBProxy, DynamoDB request routers.
  • Partition-aware client: the client caches the map and goes straight to the owner: Kafka producers, Redis Cluster clients.
  • Stale maps are corrected by redirects: Redis Cluster answers MOVED <slot> <node> and the client refreshes.
  • Authoritative map: kept in a Coordination Service (etcd, ZooKeeper) or in the database's own replicated metadata (CockroachDB's meta1/meta2 ranges).

Trade-offs

Design Gains Costs
any node forwards no extra tier extra hop on misses; every node needs the map
routing tier thin clients; central query planning another fleet; an extra hop
aware client fewest hops fat clients in every language; stale caches

In practice

  • DynamoDB moved partition metadata into MemDS, and routers refresh their cache asynchronously on every hit so metadata load doesn't swing with cache hit ratio.

Pitfalls

  • Treating the map as static: moves make every cached copy stale. Design the redirect path.
  • A routing cache whose misses all hit the metadata store at once after a restart: a Cache Stampede.

Recall

These cards are also in your review deck, scheduled with spaced repetition.