(no title)
tlrobinson | 1 year ago
- K-sortable: ensures good locality when used as an id in a database (e.x. https://github.com/jetify-com/typeid https://github.com/segmentio/ksuid )
- checksum: primarily useful when an id might be conveyed verbally (e.x. customer support) or transcribed (e.x. Bitcoin wallet backup, BIP-39)
treyd|1 year ago
medstrom|1 year ago
hot_gril|1 year ago
bruce511|1 year ago
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".
j16sdiz|1 year ago
Depends on your access pattern, you may prefer the other way, even on the same DBMS.
stephenr|1 year ago
medstrom|1 year ago
[1] https://github.com/paralleldrive/cuid2?tab=readme-ov-file#no...
ndriscoll|1 year ago
In postgres for example, full_page_writes (default on, generally not safe to turn off unless you can be sure your filesystem can guarantee it) means you have to write the entire page to WAL if you write one record. This will make your WAL grow way faster if you're doing random IOs. So right off that bat that's going to be a huge write impact.
infogulch|1 year ago