We Chose NanoIDs for PlanetScale's API
planetscale.com
We Chose NanoIDs for PlanetScale's API
1–8 of 8 posts
Re: We Chose NanoIDs for PlanetScale's API
#2Can’t you just… remove the hyphens? UUIDs are just arrays of bytes, the hyphens are not part of the data.
Instead, they use a less popular, less supported, more collision-prone ID format.
Re: We Chose NanoIDs for PlanetScale's API
#3So UUIDs were the perfect solution except that, if a user double-click a url with a UUID in it, it won’t select all of it. Can’t you just… remove the hyphens? UUIDs are just arrays of bytes, the hyphens are not part of the data. Instead, they use a less popular, less supported, more collision-prone ID format.
Re: We Chose NanoIDs for PlanetScale's API
#4Re: We Chose NanoIDs for PlanetScale's API
#5So UUIDs were the perfect solution except that, if a user double-click a url with a UUID in it, it won’t select all of it. Can’t you just… remove the hyphens? UUIDs are just arrays of bytes, the hyphens are not part of the data. Instead, they use a less popular, less supported, more collision-prone ID format.
Notion seems to use UUIDs without hyphens in their links, and it works just fine.
Re: We Chose NanoIDs for PlanetScale's API
#6So UUIDs were the perfect solution except that, if a user double-click a url with a UUID in it, it won’t select all of it. Can’t you just… remove the hyphens? UUIDs are just arrays of bytes, the hyphens are not part of the data. Instead, they use a less popular, less supported, more collision-prone ID format.
See that: https://blog.bitsrc.io/why-is-nanoid-replacing-uuid-1b5100e6...
By definition, if you base62 or base64 your uuid4 it will be longer (30%?).
This generate directly in the final encoding so it is a lot shorter. Based on the simulator calculation, you just need 24 chars to be equivalent to an uuid4 that is 35 chars.
But being able to determine the length of the resulting id is one of the greatest feature. Did it never happened to you the case that you would like a shorter uuid4 and think that you can just truncate it? Not realizing that some parts of the uuid have a special meaning and are not random...
Re: We Chose NanoIDs for PlanetScale's API
#7It works like a charm. Length decided by setting number of random bytes.
Re: We Chose NanoIDs for PlanetScale's API
#8 uuid : c5831108-6f95-442a-b2b0-3c62dc0abdd1
base62: 60hNvkHrZykznfLaESuDBp
This format also lets you attach a prefix with '_' so you can keep track of the semantic type of each ID. This pattern is widely used by the Stripe API, and I've grown quite fond of it (so much easier to grep). url: api.planetscale.com/v1/deploy-requests/deploy_60hNvkHrZykznfLaESuDBp
Additionally, within an in-memory value or a database, you probably want to store the decoded form of any ID. The value "deploy_60hNvkHrZykznfLaESuDBp" is 29 bytes long, but could be represented by `type DeployID byte[16]` for ~50% space savings and stronger type validation.