ExCuid2
An Elixir implementation of CUID2 (Collision-Resistant Unique Identifiers).
ExCuid2 generates secure, collision-resistant unique identifiers designed for efficiency and horizontal scaling. They are an excellent choice for primary keys in distributed databases.
Features
- Collision-Resistant: Uses multiple entropy sources to minimize the probability of collisions, even in high-concurrency systems.
- Secure: Starts with a random letter to prevent enumeration attacks and uses
:crypto.strong_rand_bytesfor cryptographically secure entropy. - Scalable: Includes a process fingerprint to ensure uniqueness across different nodes and application restarts.
- Efficient: Implemented with a stateful
Agentto manage an atomic counter quickly and safely. - Customizable: Allows generating IDs with a length between 24 and 32 characters.
Installation
The package is available in Hex and can be installed by adding ex_cuid2 to your list of dependencies in mix.exs:
def deps do
[
{:ex_cuid2, "~> 0.9.1"}
]
endUse
iex> ExCuid2.generate()
"v8p7k3f9z1m0c2x4b6n5j7h8"
iex> ExCuid2.generate(30)
"b5n6m4j3h2g1f0d9s8a7q6w5e4r3t2"