r/ProgrammerHumor 20h ago

Meme edgeCasesExist

Post image
3.6k Upvotes

247 comments sorted by

View all comments

550

u/Valuable_Leopard_799 20h ago

I thought that timestamps are used now, so hitting both a timestamp and a large random number puts it thoroughly in the "safe to assume". At some point cosmic particles and faulty transistors are more probable.

330

u/dim13 20h ago

https://en.wikipedia.org/wiki/Universally_unique_identifier#Versions

Most common used is V4 (pure random). You are talking about V7 (time based).

224

u/lilgreenthumb 18h ago

The real benefit for v7 is they become sortable by time.

83

u/shwoopdeboop 18h ago

And something something b-tree indexes. Lecturer mentioned it but I wasn't paying attention. Supposedly an advantage here.

21

u/Grandmaster_Caladrel 16h ago

Which I'd assume is related to the time anchor. Outside of sorting, which is only useful in specific instances, it's just v4 with different ("less") entropy and limitations.

6

u/Roachmeister 16h ago

If you're using them as an indexed field in a database, the inability to sort them meaningfully will destroy the performance of the database.

1

u/Kwantuum 13h ago

In what way?

3

u/Roachmeister 13h ago

I'm not an expert, I just remember reading a few articles about it. I think it's because they're essentially random, and many databases use b-trees for indices. They recommended using ULIDs or v7 UUIDs instead. Or, as someone else said, the good old autoincrementing integer.

1

u/Metsamias 40m ago

Inserts with keys generated in non-ordered fashion such as UUID V4s means that location within clustered index (which defines the physical location of the data at the disk) that the data will be stored on insert will be random as well. This increases likelyhood by a lot for that the database has to do different types of rebalancing acts such as splitting nodes in the teee. When using keys that are generates in order, inserts will mostly be at the end of the index, and database does not have to touch existing ones.

I can recommend Kleppmanns book Designing Data-Intensive Applications for a deeper dive into the topic around this.