Rodrigo's Unique Identifier

Overview

RUID - Time-Travel-Safe Unique 64 bit ids generated in Rust

RUIDs (Rodrigo's Unique Identifiers) are 64 bit ids mathematically guaranteed to be unique when generated within the same RUID root.

An RUID root is a set of RUID generators where each generator can be uniquely identified through shared configuration. E.g. a root can be implemented as a set of VMs on the same subnet, each identified by the last n bits of its internal IP address.

Schema Design

The canonical version of RUIDs (this repo) uses 41 bits for timestamp, 14 bits for a monotonically increasing sequence, and 9 bits for the root id.

  • 41 bits is enough to cover Rodrigo's projected lifespan in milliseconds.
  • 14 bits is about the # of RUIDs that can be generated single threaded in Rodrigo's personal computer (~20M ids per second).
  • 9 bits is what remains after the calculations above, and is used for root id. The root id is further split into 5 bits for a cluster id, and 4 bits for a node id.

Time Travel

RUIDs are designed with time travel as a requirement. Whereas other unique id implementations fail (sometimes silently) if the system generating ids goes back in time, RUIDs will still output valid, unique ids.

In v0.1, this is achieved by:

  • Defining a millisecond maximum time travel threshold MMTTT (sometimes shortened as M2T3).
  • Comparing the current generation timestamp Ct with the previous generation timestamp Pt. When Ct < Ct + MMTTT < Pt, RUIDs are generated with Pt as the timestamp.
  • Sleeping for MMTTT when the server starts, and validating the system clock indeed increased by at least MMTTT at the end.

Note that timestamps for RUIDs generated after time travel and before MMTTT has elapsed will not match the system's clock, which is both a feature and a bug (unsurprisingly, time travel incurs bug/feature duality).

Unfortunately this design is not mathematically correct if time travel happens while the RUID generator is not running; plans for fixing this bug--technically a higgs-bugson--are underway and planned for a v2 release of RUID.

Performance

Being coded in Rust and statically linked to musl, the RUID generator is exceptionally performant. v0.1 provides RUIDs via an actix HTTP server, for ease of integration and testing. The resulting standalone docker container is less than 15MB uncompressed. Further optimizations can be made by moving to a more performant RPC framework, and are planned for the RUID v1 release.

Why?

Rodrigo needed unique 64 bit ids to run benchmarks against 128 bit UUIDs in various distributed, database-intensive scenarios. Rodrigo was unsatisfied with existing implementations for various reasons, including questionable programming language choices and flaky project names.

Inspiration

RUIDs were inspired by the great efforts other engineers have gone through to generate 64 bit application-unique identifiers. In particular, inspiration was drawn from Instagram, Twitter's Snowflake, and Sony's Sonyflake.

You might also like...
Releases(v0.1)
Owner
Statsig
Statsig
Generates a unique hash/identifier for a system given a set of parameters.

uniqueid ?? Generates a unique hash/identifier for a system given a set of parameters. Example usage use uniqueid; pub fn main() { let data = vec

Checksum 2 Aug 19, 2022
A type-safe, K-sortable, globally unique identifier

type-safe-id A type-safe, K-sortable, globally unique identifier. Typed implementation of https://github.com/jetpack-io/typeid in Rust. Examples Stati

Conrad Ludgate 13 Jul 10, 2023
Figures out the local timezone as IANA / Olson identifier

localzone Utility crate to figure out the IANA (Olson) timezone of the current machine. The IANA timezones have been largely established as the standa

Armin Ronacher 11 Jan 4, 2022
Parallel finance a decentralized lending protocol built on top of the Polkadot ecosystem. Our unique approach will allow users to earn "double interests" from staking and lending their tokens simultaneously.

Parallel Finance A new Cumulus-based Substrate node, ready for hacking ?? Getting Started Follow these steps to get started with the Cumulus Template

parallel-finance 100 Dec 17, 2022
Generate unique, yet sortable identifiers

ulid-lite About An implementation of the ULID ("Universally Unique Lexicographically Sortable Identifier") standard. A ULID is 128-bit compatible with

Tim McNamara 17 Aug 20, 2022
Mononym is a library for creating unique type-level names for each value in Rust.

Mononym is a library for creating unique type-level names for each value in Rust.

MaybeVoid 52 Dec 16, 2022
httm prints the size, date and corresponding locations of available unique versions of files residing on ZFS snapshots

httm prints the size, date and corresponding locations of available unique versions of files residing on ZFS snapshots, as well as allowing their interactive viewing and restoration.

null 837 Dec 30, 2022
Game of life rendered in your terminal with over 500+ unique patterns to choose from.

Controls a: play animation n: next generation s: stop j or down arrow: go down next pattern (note: you have to stop the animation to browse the patter

Omar Magdy 20 Dec 22, 2022
A fast, simple and powerful open-source cross platform utility tool for generating strong, unique and random passwords

password-generator-pro A fast, simple and powerful open-source cross platform utility tool for generating strong, unique and random passwords. Feature

Sebastien Rousseau 3 Dec 16, 2022
A simple to use rust package to generate or parse Twitter snowflake IDs,generate time sortable 64 bits unique ids for distributed systems

A simple to use rust package to generate or parse Twitter snowflake IDs,generate time sortable 64 bits unique ids for distributed systems (inspired from twitter snowflake)

houseme 5 Oct 6, 2022