• Stars
    star
    154
  • Rank 242,095 (Top 5 %)
  • Language
    Elixir
  • Created over 2 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

🆔 The friendly, pragmatic and functional ID system

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.

More Repositories

1

lanyard

🏷️   Expose your Discord presence and activities to a RESTful API and WebSocket in less than 10 seconds
Elixir
942
star
2

phineas.io

👨‍💻 React app for my personal website
TypeScript
79
star
3

domain-lookup-tree

🌐 A tree structure in Rust optimized for looking up domain names, with wildcard support
Rust
32
star
4

bungeegate

BungeeGate Runtime 📡 🔐 🌟 Load Balance BungeeCord Traffic
JavaScript
15
star
5

kubehook

Post Kubernetes pod status updates to multiple services
Go
12
star
6

firehose

Example of how to use SSE and Redis to publish events from Redis Pub/Sub to an SSE stream using Elixir
Elixir
8
star
7

mc-utils

NPM library of useful Minecraft-related utilities
JavaScript
4
star
8

cloudbleed-search

Search through Cloudflare domains in pirate/sites-using-cloudflare
Go
4
star
9

Phineas

4
star
10

phinamoji

Simple NodeJS script to change your Twitter name's emoji every few seconds
Shell
3
star
11

parahouse

Home Control (Philips Hue, Kasa, Alexa, Nest, etc) - soon to be for ParaHouse
JavaScript
3
star
12

EULAChecker

Java
2
star
13

instaupdate

Update locations, bios, websites & more on every website at once
JavaScript
2
star
14

nsqsumer

nsq consumer wrapper
Go
2
star
15

google-codein-hw

Task for Google CodeIn 2017
TypeScript
1
star
16

PokemonGOStatusManager

A pretty (bad) uptime manager for pokemongostatus.net, might be useful for someone that uses DigitalOcean (probably not)
Java
1
star
17

google-codein-cf

Cloud Functions for Google CodeIn 2017 (ignore this repo)
JavaScript
1
star
18

PPPP

Python
1
star
19

protostream-compile

Basic pbs stream compiler
Go
1
star