Hacker News new | past | comments | ask | show | jobs | submit login

Anything with atomic increments can do this, we use a simple table called idsequence with a single column and row. When an application starts up, it upserts 100000 and gets the new value. This gives both the min and max values that the app can then use as ids for any entities with no overlap with anything else.

It's actually not Hi/Lo but similar. You can also add another column to that table if you want multiple "sequences" but we like to keep it simple and with bigints, you'll never realistically run out.

If you're using an ORM, you might need some extra work but most of the time they are smart enough to use an existing ID if the object already has one rather than try to get one from the database.




What was your reason for not using database sequences?


It was in my original post:

>> This means plenty of ID space, maintains rough numeric ordering, allows ID creation without a roundtrip for every insert, is easily portable across different databases, and produces unique IDs for every row in the database which greatly simplifies everything from caching to replication.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: