Database / REDIS
How does Redis Cluster shard data across nodes?
Redis Cluster divides the entire keyspace into 16,384 fixed hash slots, and assigns ownership of ranges of those slots to each master node in the cluster — a 3-master cluster might own roughly 5,461 slots each, for example. A key's slot is computed as CRC16(key) mod 16384, so which node a given key belongs to is a deterministic function of the key itself, not a lookup table that has to be consulted for every single key individually.
CLUSTER KEYSLOT mykey CLUSTER ADDSLOTS 0 1 2 3 4
To let related keys be co-located for multi-key operations, Redis supports hash tags: if a key contains a substring wrapped in {}, only that substring is hashed to determine the slot, so user:{1001}:profile and user:{1001}:orders both land on the same slot despite being different keys. Slots (and their data) can be migrated between nodes for rebalancing without downtime, and a client that sends a command for a key not owned by the node it contacted gets redirected to the correct node via a MOVED response, which is why cluster-aware client libraries cache the slot-to-node mapping rather than guessing on every request.
More Related questions...
