Some workloads don't fit hash or range cleanly. Directory-based sharding lets you assign keys to shards explicitly. Trades simplicity for flexibility.

Query key=XDirectory Servicelookup tableShard 1big tenantsShard 2medium tierShard 3shared smallShard 4premium isolatedShard Nshared smallDirectory Cachelookup < 1ms
Directory sharding: table lookup routes queries to explicit shards
Advertisement

The mechanic

Explicit table: key → shard_id. Query starts with directory lookup. Then routes to that shard.

The mechanic

Explicit table: key → shard_id. Query starts with directory lookup. Then routes to that shard.

Advertisement

Extra hop

Every request = 2 hops (directory + shard). Cache directory aggressively — Redis with TTL.

Flexibility wins

Move a hot tenant to isolated shard. Rebalance to spread load. All by updating the directory.

Multi-tenancy

Big customer → dedicated shard. Small customers → shared shard. Directory encodes the policy.

Downside

Directory becomes a critical dependency. Must be HA. Must be fast. Must be sharded itself at scale.

Directory sharding trades a hop for flexibility. Cache the directory, HA-deploy it, worth it for multi-tenant.