New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

cluster-id

Package Overview
Dependencies
Maintainers
0
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cluster-id

Database cluster friendly object id with great query isolation.

  • 1.0.4
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

Cluster-id — id generator with great database query isolation

Great replacement for MongoDB's built-in ObjectID or ShortId.

Cluster-id generates ids in url-friendy base64 format and can have length 13 (without scope) or 26 (with scope) base64 symbols.

Generated ids are non-sequential that helps distribute write load across whole database cluster.

Generated ids encode information about generation time, scope/parent context and geo region, so records can be grouped by geo region and scope and in same time can be ordered by creation time.

In MongoDB's sharded cluster you can avoid broadcast queries during loading a doc by id and still keep related docs in same shard.

Cluster-id can be used with any database but it's especially useful for databases that store records in primary key order (MySQl/InnoDB, CockroachDB, RocksDB, LevelDB, etc). In this case related records, for example comments of an blog post, or products of an shop will be stored together in same shard and even in same part of a disk. It's greatly improves query isolation in distributed databases and hence reading performance.

Customized version of Cluster-id is used at buyer-focused marketplace wikiket.com (electronics, smartbands, FPV drones). For example, take a look at Mi Band 9 smartband url.

Installation

npm i -S cluster-id

Usage

> let id = require('cluster-id/generator')()
> id()
'-cha7--0PQmBK'
> id({scope: '-cha7--0PQmBK'})
'-cha7--0PQmBK-0PQmBrj8j7--'
> id({segment: 42, scope: '-cha7--0PQmBK'})
'-cha7--0PQmBKe0PQmDotjC8--'
> id({segment: 42})
'exYV8--0PQmF0'
> id({segment: 42, time: Date.now()})
'eKE_8--0PQmFK'

Keywords

FAQs

Package last updated on 17 Jan 2025

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc