Discussion
Loading...

Discussion

Log in
  • About
  • Code of conduct
  • Privacy
  • Users
  • Instances
  • About Bonfire
Fränz Friederes
@friends@chaos.social  ·  activity timestamp last week

Sequential IDs are faster. UUIDs are safer.
I wanted both speed and security, so I picked both.

Screenshot of a database table showing team data with two ID columns: privateId, a sequential number, and id, a prefixed Nano ID like tm_imswzl4d93om used externally. The table includes names like Alice, Bob, and Wierk, and is ordered by privateId.
Screenshot of a database table showing team data with two ID columns: privateId, a sequential number, and id, a prefixed Nano ID like tm_imswzl4d93om used externally. The table includes names like Alice, Bob, and Wierk, and is ordered by privateId.
Screenshot of a database table showing team data with two ID columns: privateId, a sequential number, and id, a prefixed Nano ID like tm_imswzl4d93om used externally. The table includes names like Alice, Bob, and Wierk, and is ordered by privateId.
  • Copy link
  • Flag this post
  • Block
Fränz Friederes
@friends@chaos.social  ·  activity timestamp last week

Postgres' bigserial is compact, fast, and plenty large. But it leaks row counts and makes your API vulnerable to ID enumeration.

UUIDs solve that, but they’re bulky, slow to index, and annoying to select or copy.

  • Copy link
  • Flag this comment
  • Block
Fränz Friederes
@friends@chaos.social  ·  activity timestamp last week

So I split responsibilities:
- privateId: a sequential bigserial, used only for db internal references
- id: a prefixed Nano ID like us_msny03yjrocv, used everywhere else

The prefix (e.g. us_, ag_, dn_) reveals the entity type. The rest is short, unambiguous, and random.

  • Copy link
  • Flag this comment
  • Block
Fränz Friederes
@friends@chaos.social  ·  activity timestamp last week

This setup delivers the best of both worlds:
- Fast joins and cache-friendly indexes
- Opaque, secure public IDs with great DX

No need to compromise.

#BuildInPublic#Postgres

  • Copy link
  • Flag this comment
  • Block
Log in

bonfire.cafe

A space for Bonfire maintainers and contributors to communicate

bonfire.cafe: About · Code of conduct · Privacy · Users · Instances
Bonfire social · 1.0.0-rc.2.1 no JS en
Automatic federation enabled
  • Explore
  • About
  • Members
  • Code of Conduct