| I understand the performance implications of using a UUID for a primary key. And if performance is your primary concern, then this is good advice for large tables. But if I could go back 25 years and only give myself one bit of advice, it would be to use UUIDs as the primary key. Because in a different context to raw performance, it offers a lot of advantages. While there are advantages in numerous areas, I'll focus on one for this post. The area of distributed data. We started by running a database on prem. Each branch or store got their own db. 15 years later always-on networking happened. 15 years after that, all businesses have fibre. So now all the branches use a giant shared online database. With merged data. Uuid based this task would be trivial. Bigint based, yeah, it's not. Along the same timeline data started escaping from our database. It would go to a phone, travel around a bit, change, get new records, then come home. Think lots of sales folk, in places without reception, doing stuff. So you're right in the context of a single database (cluster) which encompasses all the data all the time. But in the context where data lives beyond the database, using uuids solves a lot of problems. There are other places as well where uuids shine. So as with most advice when it comes to SQL, I'd add "context matters". |
If you're copying a DB, mutating, then merging back in, you just have to reset the bigint pkeys. I can see how in some contexts that might be less convenient (or if merges are very frequent and reads are not, less performant), but that's a special case and not something to assume from the start. For example I've done merges like this before pretty easily with bigints, and I've also been in places where they start out with uuids pkeys then never benefit.