Saltar al contenido
uencoder

Usar consistent hashing para distribution

Consistent hashing distributes claves across servers con minimal redistribution cuando servers son added o removed. Usado en CDN y distributed caches.

  1. 1

    Consistent hashing maps both keys and servers to a ring (0 to 2^32-1). A key is assigned to the next server clockwise on the ring. When a server is added or removed, only keys in that server's segment are remapped — most keys stay on the same server. This minimizes data movement, unlike modulo hashing which remaps everything.

  2. 2
    Calculadora de hash →

    Hash server IDs and keys to the ring using SHA-256. The hash determines the position on the ring (0 to 2^256-1, or mod 2^32 for a 32-bit ring). To find the server for a key: hash the key, find the next server clockwise. Use virtual nodes (150-200 per server) for better distribution.

  3. 3
    Hash SHA-3 / Keccak →

    Use SHA-3-256 for consistent hashing. The hash function should be fast and uniformly distributed — SHA-3 or SHA-256 are good choices. The key property: adding/removing a server affects only 1/n of the keys (where n is the number of servers), not all keys as with hash(key) % n.

Preguntas frecuentes

What are virtual nodes?
Each physical server is mapped to multiple positions on the ring (virtual nodes). This improves load distribution — with 150 virtual nodes per server, the load is balanced within ~10% even with heterogeneous server capacities. Without virtual nodes, a server's load depends on its position on the ring, which can be uneven.
Where is consistent hashing used?
CDNs (Akamai, Cloudflare) to route requests to edge servers, distributed caches (Memcached, Redis Cluster) to distribute keys, databases (Cassandra, DynamoDB) to distribute partitions, and load balancers. Any system that needs to distribute data across servers with minimal redistribution on topology changes.

Flujos que resuelven esta tarea

Herramientas relacionadas