{"id":22556085,"url":"https://github.com/munawwar/hrw-hash","last_synced_at":"2025-04-10T05:30:20.983Z","repository":{"id":57267121,"uuid":"457500858","full_name":"Munawwar/hrw-hash","owner":"Munawwar","description":"🤹 HRW / Rendezvous hashing in JS","archived":false,"fork":false,"pushed_at":"2024-07-14T06:31:02.000Z","size":205,"stargazers_count":6,"open_issues_count":0,"forks_count":2,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-08T07:41:30.078Z","etag":null,"topics":["consistent-hashing","hash","hashing-algorithm","hrw-hashing","nodejs","rendezvous-hashing"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Munawwar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2022-02-09T19:31:32.000Z","updated_at":"2025-02-11T21:35:31.000Z","dependencies_parsed_at":"2024-12-07T19:11:15.747Z","dependency_job_id":"58e252f9-0fe9-4174-bf5e-382cd996c3b5","html_url":"https://github.com/Munawwar/hrw-hash","commit_stats":{"total_commits":6,"total_committers":1,"mean_commits":6.0,"dds":0.0,"last_synced_commit":"1e72db8337e0c22998b36378e6a38a0d6a660247"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Munawwar%2Fhrw-hash","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Munawwar%2Fhrw-hash/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Munawwar%2Fhrw-hash/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Munawwar%2Fhrw-hash/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Munawwar","download_url":"https://codeload.github.com/Munawwar/hrw-hash/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248162871,"owners_count":21057826,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["consistent-hashing","hash","hashing-algorithm","hrw-hashing","nodejs","rendezvous-hashing"],"created_at":"2024-12-07T19:11:12.258Z","updated_at":"2025-04-10T05:30:20.952Z","avatar_url":"https://github.com/Munawwar.png","language":"JavaScript","readme":"# HRW (Highest Random Weight) hashing / Rendezvous hashing\n\nhttps://en.wikipedia.org/wiki/Rendezvous_hashing.\n\n```\nnpm install hrw-hash\n```\n\n```js\nimport { hrwHash } from 'hrw-hash'\n// or const { hrwHash } = require('hrw-hash')\nconst servers = ['image-server-1.example.com', 'image-server-2.example.com']\nconst domainToUse = hrwHash('example.png', servers)[0] // always 'image-server-2.example.com'\n```\n\nAdvantage of this hashing over other sticky load balancing algorithms is that:\n1. it does not use a shared lookup table / ring\n2. it is independent of the order of destinations (hrwHash('john', ['a', 'b']) is same as hrwHash('john', ['b', 'a']))\n3. it distributes keys evenly (probabilistically) when a destination is added or removed\n\nDisadvantage of this hashing method:\n1. Replacing a destination with another one will re-route keys unnecessarily as the algo is order insensitive\n\nThe implementation is small (0.5 kb minified) and with no 3rd party dependencies. It uses bigint, unescape and encodeURIComponent, so it supports modern browsers, node.js \u003e= 12.5.0 and cloudflare workers.\n\nIt uses `mulberry32(fnv1a32('key'))` as hash function internally for the random hash. In my tests, this gives better distribution than fnv1a-32 alone and still keeps the implementation fast and small.\n\n\n```js\n// for advanced use cases you can import the hash function\nimport { hashFunc } from 'hrw-hash'\nhashFunc('string') // returns positive integer \u003c 2^32\n```\n\n# Dev Test\n\nTest the types against https://arethetypeswrong.github.io\n\n# Breaking Change V2\n\n- Removed minified dist files (dist/*.min.js). If you want minified build for browser, then use `import { hrwHash } from 'https://esm.sh/hrw-hash'`\n- Removed UMD build\n- Changed minimum node.js version requirement from \u003e= v12.0.0 to \u003e= 12.5.0","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmunawwar%2Fhrw-hash","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmunawwar%2Fhrw-hash","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmunawwar%2Fhrw-hash/lists"}