Skip to content

Using Masked Identifiers to Reference ActiveRecord Models

blog.matthodan.com
5 pointsstevedewald2 comments
On HN

Comments

Why not use a UUID? Seems wasteful to have to do a SELECT for every INSERT.

I thought so too at first, but this way I can control the length of the unique ID while still guaranteeing that every ID is unique. Clearly, if you decided to have a 2 character masked identifier, you'd end up with a small number of possible objects before problems start to happen. As a TODO, I need to implement an elegant way to handle situations when all possible UIDs have been exhausted. If you know of a good UUID lib that lets you control the length of the UID, guarantees 100% unique codes, and gracefully handles issues when UIDs have run out, let me know! I'd definitely consider replacing my CodeGenerator.

AboutSource Built by g1lg1l

Hackerly is an independent reader for Hacker News, built on the public HN API. Not affiliated with Y Combinator.