https://github.com/pixelastic/shar-teel
Consistently shard a value in any given array.
https://github.com/pixelastic/shar-teel
nodejs shard
Last synced: 7 months ago
JSON representation
Consistently shard a value in any given array.
- Host: GitHub
- URL: https://github.com/pixelastic/shar-teel
- Owner: pixelastic
- License: mit
- Created: 2021-07-24T18:58:37.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2025-01-17T18:24:59.000Z (9 months ago)
- Last Synced: 2025-01-17T19:34:28.476Z (9 months ago)
- Topics: nodejs, shard
- Language: JavaScript
- Homepage:
- Size: 1.37 MB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# shar-teel
Consistently shard a value in any given array.
## Installation
```sh
yarn install shar-teel
```## Usage
```js
const sharTeel = require('shar-teel');// This is the array of possible values
const servers = ["amn", "baldur", "cormyr"];// This is the key on which to shard. It can be anything: an id, an email, an url, etc
const key = "gorion@candlekeep.com";// This is the shard, one of the three possible server, randomly selected
// The same key will consistently return the same shard
const shard = sharTeel(servers, key)
```## Why would I need this?
This can be used in a load-balancing logic. You might want to split your traffic
between different servers, read your data from different replica databases or
parrallelize heavy operation accross different machines.`shar-teel` helps in picking a random value out of a set, in a consistent way.
This means that running the same `sharTeel(possibleValues, key)` is idempotent
and will always return the same value.## Why this name?
`shard` was already taken as an npm module. I tend to name my projects from
characters of my favorite books and video games. Shar-Teel is a character in
Baldur's Gate.