GithubHelp home page GithubHelp logo

robjmorrissey / pika Goto Github PK

View Code? Open in Web Editor NEW

This project forked from phineas/pika

0.0 0.0 0.0 107 KB

๐Ÿ†” The friendly, pragmatic and functional ID system

JavaScript 1.70% TypeScript 44.80% Rust 53.50%

pika's Introduction

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
Rust

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.

pika's People

Contributors

phineas avatar robjmorrissey avatar alii avatar knvi avatar pxseu avatar m1guelpf avatar maxichrome avatar dustinrouillard avatar rishi8094 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.