Hacker News new | ask | show | jobs
by chaz6 38 days ago
Every time a discussion like this comes up I am reminded of Microsoft's "RID master" used in Active directory. A central server issues out chunks of ID's to each server on demand (usually when a watermark is reached), so each server always has a pool of ID's available to use.

Are there any extensions for PostgreSQL that do this?

3 comments

This is actually a very interesting question. I assume that you are referencing extensions that add shards to Postgres, since it runs on a single server out of the box. You made me curious how those extensions/rewrites handle sequences.

It looks like Citus (one such extension that runs shards on separate workers) does something a little like what you described. Each node gets an ID, which becomes the high bits of the sequences it generates. So serial IDs are monotonic within a shard, but not across shards.

Aurora PostgreSQL Limitless uses different abstractions, but also ends up reserving different chunks of IDs for different routers to use.

Not sure how something like:

https://dev.to/aws-heroes/scalable-sequence-for-postgresql-3...

Would interact with sharding?

I use this pattern in mysql. One row, and one update query gets you a block of IDs. Don't want to attempt to write it out here without looking, but the trick is using the last insert id in the query (and on the result).

It's one query, so shouldn't require a plugin I hope.