| The point about the storage size of UUID columns is unconvincing. 128 bits vs. 64 bits doesn't matter much when the table has five other columns. A much more salient concern for me is performance. UUIDv4 is widely supported but is completely random, which is not ideal for index performance. UUIDv7[0] is closer to Snowflake[1] and has some temporal locality but is less widely implemented. There's an orthogonal approach which is using bigserial and encrypting the keys: https://github.com/abevoelker/gfc64 But this means 1) you can't rotate the secret and 2) if it's ever leaked everyone can now Fermi-estimate your table sizes. Having separate public and internal IDs seems both tedious and sacrifices performance (if the public-facing ID is a UUIDv4). I think UUIDv7 is the solution that checks the most boxes. [0]: https://uuid7.com/ [1]: https://en.wikipedia.org/wiki/Snowflake_ID |
But it's not just the size of that one column, it's also the size of all the places that id is used as a FK and the indexes that may be needed on those FK columns. Think about something like a user id that might be referenced by dozens or even hundreds of FKs throughout your database.