Company
Date Published
Author
Mike Coutermarsh
Word count
871
Language
English
Hacker News points
79

Summary

When building PlanetScale's API, the team needed a unique identifier that wouldn't reveal record counts in tables, avoiding the use of integer IDs. They considered using UUIDs but found they took up too much space in URLs. To address this, they developed NanoIDs, which are shorter than UUIDs, easy to select with double-clicking, and have a low chance of collisions. The team used 12-character long IDs with a specific alphabet, resulting in a 1% probability of collision over ~35 years if generating 1000 IDs per hour. To generate NanoIDs, they added a public_id column to their database schema for public-facing models and built a concern that could be shared across all models to auto-generate IDs. The same approach was applied in their Go backend service, using a package called go-nanoid/v2 to generate unique public IDs. By solving this detail, PlanetScale aimed to create a great developer experience.