A consistent hashing ring with replicas for more even distribution (virtual nodes) and binary searching for best performance.
This hashring uses the MurmurHash algorithm which creates a 32-bit integer as opposed to using something like a 128-bit MD5. Which means, in comparison to an MD5 based hashring, this offers a lot more performance.
npm install node-hashing
// or
yarn add node-hashring
This will create a hashring for two primary nodes, by default each node will be comprised of 80 virtual nodes.
const HashRing = require('node-hashring');
const hashRing = new HashRing([
'server-address-1',
'server-address-2',
]);
const serverAddress = hashRing.findNode('my-key');
hashRing.addNode('server-address-2');
hashRing.removeNode('server-address-2');