The friendly, pragmatic and functional ID system

Overview

pika

Combine Stripe IDs with Snowflake IDs and you get... pika! - the last ID system you'll ever need, combining pragmatism with functionality.

Example ID: user_MTI5Njg4Njg1MDQwODg5ODYx

Features

  • Object type prefixes
  • Type prefix atomicity
  • Guaranteed multi-node space-time uniqueness
  • Timestamped
  • Fast & simple
  • Shorter than UUIDs
  • Standalone
  • Option to be cryptographically secure

Disadvantages / Trade-offs vs. Snowflakes

  • Unable to sequence by integer (pikas are strings)
  • Slower generation (by a few nanoseconds - pika is 1.5m ops/sec vs snowflake 2m ops/sec on an M1, however all Snowflakes and Pikas have a theoretical limit of generating a maximum of 1,024,000 IDs per node per second, so there won't be a difference in throughput either way)
  • Slightly larger sizes (pikas are ~28 bytes vs Snowflake's 8 bytes)

Implementations

JS (TypeScript) - Fully typed, optimized, 0 deps

The ID

Pika IDs consist of 2 sections: the type prefix and the tail, separated by an underscore.

Type Prefixes

When creating a pika ID, you must specify the prefix to be prepended - the general rule of thumb should be to use a different prefix for each object type (e.g. user, team, post, etc).

Type prefixes should be lowercase, short, alphanumeric strings. If you have an object type with a long name, then it's recommended to shorten it down into an acronym or similar. For example, if we had an object type called "connected account", then we'd make the type prefix ca - or even if we had a type called "channel", we might want to shorten it down to ch - it's up to you to decide what you think makes the most distinctive sense.

Tail

The tail is the part that comes after the underscore (e.g. MTI5Njg4Njg1MDQwODg5ODYx). Usually, this is just a base64-encoded Snowflake ID, however, if the pika is cryptographically secure, then the base64 decoded string value will start with an s_ prefix, followed by a cryptographically random string, then followed by another underscore and the Snowflake ID.

Example of a normal decoded tail: 129688685040889861

Example of a cryptographically secure decoded tail: s_387d0775128c383fa8fbf5fd9863b84aba216bcc6872a877_129688685040889861

Type Prefix Atomicity

To guarantee that developers use the correct pre-defined prefix types for the right object types, pika requires you to "register" them before they're used to prevent warnings from being thrown. This is also where you define if a prefix type should be cryptographically secure or not.

You might also like...

TChart.js - simple and configurable Bar and Line Chart library in Javascript

TChart.js - simple and configurable Bar and Line Chart library in Javascript

TChart.js Simple and configurable Bar and Line Chart library in Javascript Description TChart.js is a canvas-based simple Javascript Bar and Line Char

Mar 3, 2021

Chart.js plugin to calculate and draw statistical linear, exponential, power, logarithmic, and polynomial regressions.

chartjs-plugin-regression Chart.js plugin to calculate and draw statistical linear, exponential, power, logarithmic, and polynomial regressions using

Dec 18, 2022

Visualize your tech stack and database with a simple, beautiful, and interactive web app.

Stacify Visualize your tech stack and database with a simple, beautiful, and interactive web app. Why Stacify Why would you want to use Stacify? Well,

Jan 20, 2022

Bring data to life with SVG, Canvas and HTML. :bar_chart::chart_with_upwards_trend::tada:

D3: Data-Driven Documents D3 (or D3.js) is a JavaScript library for visualizing data using web standards. D3 helps you bring data to life using SVG, C

Jan 3, 2023

Apache ECharts is a powerful, interactive charting and data visualization library for browser

Apache ECharts is a powerful, interactive charting and data visualization library for browser

Apache ECharts Apache ECharts is a free, powerful charting and visualization library offering an easy way of adding intuitive, interactive, and highly

Jan 9, 2023

Redefined chart library built with React and D3

Recharts Introduction Recharts is a Redefined chart library built with React and D3. The main purpose of this library is to help you to write charts i

Jan 2, 2023

The Swiss Army Knife of Vector Graphics Scripting – Scriptographer ported to JavaScript and the browser, using HTML5 Canvas. Created by @lehni & @puckey

Paper.js - The Swiss Army Knife of Vector Graphics Scripting If you want to work with Paper.js, simply download the latest "stable" version from http:

Dec 30, 2022

The lightweight library for manipulating and animating SVG

SVG.js A lightweight library for manipulating and animating SVG, without any dependencies. SVG.js is licensed under the terms of the MIT License. Inst

Dec 25, 2022

Progressive svg pie, donut, bar and line charts

Peity Peity (sounds like deity) is a jQuery plugin that converts an element's content into a mini svg pie, donut, line or bar chart. Basic Usage HTM

Jan 1, 2023
Comments
  • Make improvements to JS implementation

    Make improvements to JS implementation

    This PR...

    • Renames a few types to be either more descriptive or more consistent • More strongly types Pika#gen (because we easily can). • Adds benchmark to readme • Adds JSDoc to certain public interfaces • Renames inconsistently named fields (and deprecates the old names, but not removed — they'll still work)

    opened by alii 2
  • Modernize project

    Modernize project

    This PR: • Does some standard housecleaning and formatting • Implements ESM exports • Adds prefix inference types

    const pika = new Pika(['a', 'b']);
    type Prefixes = InferPrefixes<typeof pika>;
    // ^? 'a' | 'b'
    
    opened by alii 0
  • Fix seq not incrementing

    Fix seq not incrementing

    • Struct previously implemented Copy which passed by value
    • Implemented a generate_snowflakes test so we don't miss stuff like this in future
    • Bumped version to 0.1.2
    opened by robjmorrissey 0
  • Pika in Browser

    Pika in Browser

    Currently, the JS implementation for Pika uses NodeJS dependencies. Would it be possible to somehow make Pika (either with a separate implementation or by changing the current one) work on Browsers? This could be useful for web applications without a backend (working with LocalStorage for example)

    opened by OfficialCRUGG 0
Owner
Hop
The Realtime Engine
Hop
A friendly reusable charts DSL for D3

D4 D4 is a friendly charting DSL for D3. The goal of D4 is to allow developers to quickly build data-driven charts with little knowledge of the intern

Mark Daggett 429 Dec 5, 2022
Flat, round, designer-friendly pseudo-3D engine for canvas & SVG

Zdog Round, flat, designer-friendly pseudo-3D engine View complete documentation and live demos at zzz.dog. Install Download zdog.dist.min.js minified

Metafizzy 9.5k Jan 3, 2023
A cross platform high-performance graphics system.

spritejs.org Spritejs is a cross platform high-performance graphics system, which can render graphics on web, node, desktop applications and mini-prog

null 5.1k Dec 24, 2022
Free Bootstrap 5 Admin and Dashboard Template that comes with all essential dashboard components, elements, charts, graph and application pages. Download now for free and use with personal or commercial projects.

PlainAdmin - Free Bootstrap 5 Dashboard Template PlainAdmin is a free and open-source Bootstrap 5 admin and dashboard template that comes with - all e

PlainAdmin 238 Dec 31, 2022
Processing Foundation 18.6k Jan 1, 2023
A library optimized for concise and principled data graphics and layouts.

MetricsGraphics is a library built for visualizing and laying out time-series data. At around 15kB (gzipped), it provides a simple way to produce comm

Metrics Graphics 7.5k Dec 22, 2022
danfo.js is an open source, JavaScript library providing high performance, intuitive, and easy to use data structures for manipulating and processing structured data.

Danfojs: powerful javascript data analysis toolkit What is it? Danfo.js is a javascript package that provides fast, flexible, and expressive data stru

JSdata 4k Dec 29, 2022
Matteo Bruni 4.7k Jan 4, 2023
A library optimized for concise and principled data graphics and layouts.

MetricsGraphics is a library built for visualizing and laying out time-series data. At around 15kB (gzipped), it provides a simple way to produce comm

Metrics Graphics 7.5k Dec 22, 2022