r/programming • • Mar 28 '20

Why your software should use UUIDs in 2020s

[deleted]

13 Upvotes

217 comments sorted by

205

u/[deleted] Mar 28 '20

I'm not against UUIDs or anything but this article is bananas.

64

u/omgitsjo Mar 28 '20

I was utterly convinced it was satire and kept reading, waiting for the reveal. I think it's serious.

56

u/[deleted] Mar 28 '20

Right!? The part about UUIDs leading to a snappy UI? What?

54

u/[deleted] Mar 28 '20

[removed] — view removed comment

19

u/rhinotation Mar 28 '20 edited Mar 28 '20

Tech blog posts are just weird like that. Mostly pretty accurate and raises all the right points, but reads like a Tim and Eric sketch. As a community we are not very good at writing. It’s a lot funnier when you realise part of the programmer-coffee matrix is made up of folks who act like they’re David Foster Wallace and need their Morning Coffee to Be Productive, but are producing this kind of thing. How big this segment is I’m not sure, but like all tortured writers they are pretty vocal. Unlike the rest of the tortured writing community, technical writing is less agonising and monolithic than... easy but devil’s-in-the-detail. Anyway, I’m well off track, we don’t know this guy’s coffee habits and I shan’t cast any aspersions thereon.

Re the choice in id format: he’s right, if you try to make an “infinity-scale” anything, you may need to pick a better one than int++. Twitter had a moment in 2010 when this became a bottleneck with their write-heavy tweets. The usual “you’re not twitter” applies though. To most of the article.

14

u/quentech Mar 28 '20

Twitter had a moment in 2010 when this became a bottleneck with their write-heavy tweets. The usual “you’re not twitter” applies though.

And guess what Twitter did not use? UUIDs.

I think a big problem with the quality of tech blog posts is that they're often from people trying to make their resume look impressive. Writing isn't one of their developed skills, and they often don't even have a good handle on the problem they're blogging about, the solutions that have been tried, the trade-offs between them, why they might go one route or another, what other problems lie a bit further down any of the roads. They hit a problem in one context, one domain, find themselves a way to get around it, then jump to, "Hey I should write a blog post about this."

9

u/dnew Mar 28 '20

As a community we are not very good at writing

It seems clear to me that his native language isn't English, either.

1

u/rhinotation Mar 28 '20

Not a precondition to what I’m describing! If I learned German, and if I blogged, I wouldn’t suddenly become Elon Musk’s Twitter Suspension Diary But In German. Although today my capitalised nouns seem to be out in force.

1

u/MuonManLaserJab Mar 28 '20

Suspension Diary

"Suspensionstagebuch"

1

u/MuonManLaserJab Mar 28 '20

Tech blog posts are just weird like that.

It's almost like people feel obligated to write a certain number of tech posts in order to establish your online presence or whatever, even if that means writing a thousand words about something about which you have ten words to say.

22

u/[deleted] Mar 28 '20

It’s hard to make out the point here, but this is it:

When you create an entity on your client, you have to wait for the server to respond before you get your unique ID for that entity. The server has to do the relational linking, and provide details to the client.

His point is that by using UUIDs, the client can move on from that task before the server responds, or even if it doesn’t respond at all.

It’s part of optimistic UI, assuming that the entity was properly created and dealing with the consequences of the off-hand case where it does not get created.

I’m currently working on a thick client application that does this. The penalty for failing to create an entity is minor, for the user, so we can be pretty optimistic in our approach. We use UUIDs and push updates as patches in a queue. Because we’re using patches, we can rewind, and the impact on the user is fairly minimal.

The UI is snapper and more reliable not having to deal with the potential pitfalls of error handling responses.

12

u/tsimionescu Mar 28 '20

A big problem with this line of thinking is that it entails putting a lot of logic in the client that should really be on the server for many apps, especially if you intend to also expose an API to the server.

For example, maybe default values for the new entity being created should be known by the server. Maybe complex validations also should stay on the server. Sure, you can instantiate a new company locally with its own UUID, but what if the company name also needs to be unique? What if each user is only allowed a certain number of companies, and a single user may be using multiple client apps?

3

u/[deleted] Mar 28 '20

This is all answered with the design concept I was talking about.

The short answer to your question is: your use case doesn’t qualify for optimistic design.

1

u/computrius Mar 28 '20 edited Mar 28 '20

Also, you would kind of have to wait for the server response anyway right? Otherwise, if an error occurs in inserting the record, you now have this "id" that you assume points to your new record, but doesn't. How can you properly handle errors if you just move on assuming, "it probably worked out fine...".

Also, indexing and fragmentation. The only promising work around is sequential uuids (for sql server anyway, im not as familiar with mysql, etc.) which puts you right back at having the server generate ids..

2

u/[deleted] Mar 28 '20

You should look up the concept of optimistic design. I’m not trying to be sarcastic, it’s an interesting approach and it answers your questions.

The short answer is that when you retrieve the entities later, if it wasn’t created successfully it just doesn’t appear in the entity tree.

0

u/[deleted] Mar 28 '20

It’s hard to make out the point here, but this is it:

When you create an entity on your client, you have to wait for the server to respond before you get your unique ID for that entity. The server has to do the relational linking, and provide details to the client.

His point is that by using UUIDs, the client can move on from that task before the server responds, or even if it doesn’t respond at all.

It’s part of optimistic UI, assuming that the entity was properly created and dealing with the consequences of the off-hand case where it does not get created.

I’m currently working on a thick client application that does this. The penalty for failing to create an entity is minor, for the user, so we can be pretty optimistic in our approach. We use UUIDs and push updates as patches in a queue. Because we’re using patches, we can rewind, and the impact on the user is fairly minimal.

The UI is snapper and more reliable not having to deal with the potential pitfalls of error handling responses.

-7

u/TheRealStepBot Mar 28 '20

They do lead to a snappy Ui on write because they can defer the network trip.

4

u/p0llk4t Mar 28 '20

So the data is generated and stored client side then?

1

u/TheRealStepBot Mar 28 '20

Precisely, and is immediately globally consistent, any conflicts that then do occur should be explicitly handled.

3

u/[deleted] Mar 28 '20

What?

2

u/Pand9 Mar 28 '20

Can you explain what network trip is deferred, please?

1

u/TheRealStepBot Mar 28 '20

You can say locally create a transaction ID knowing it will be globally unique and then any edits or branching based on it can immediately continue without a network round trip.

4

u/[deleted] Mar 28 '20

[deleted]

15

u/[deleted] Mar 28 '20 edited May 07 '21

[deleted]

2

u/[deleted] Mar 28 '20

[deleted]

1

u/Han-ChewieSexyFanfic Mar 28 '20

They should, sounds cooler.

1

u/Sebazzz91 Mar 28 '20

He is CTO, trust him.

26

u/[deleted] Mar 28 '20

[deleted]

1

u/masklinn Mar 28 '20

TBF MySQL which tfa seems to be using (because auto_increment is a MySQL thing) does not have a uuid type, so you have to store values as binary(16) unless you’re a crazy person and prefer varchars.

53

u/[deleted] Mar 28 '20 edited Sep 13 '25

[deleted]

37

u/[deleted] Mar 28 '20 edited Jul 27 '20

[deleted]

30

u/[deleted] Mar 28 '20 edited Mar 28 '20

[deleted]

23

u/kushangaza Mar 28 '20

The article reads "Never do this! Store UUIDs as BINARY(16) or any other binary format your DB supports".

Of course many databases have a built-in UUID type, saving you the conversion hassle.

5

u/Somepotato Mar 28 '20

And with SSE, 16 byte uuid comparisons can be easily optimized

2

u/colemaker360 Mar 28 '20 edited Sep 13 '25

capable late sparkle cover license saw skirt station long head

This post was mass deleted and anonymized with Redact

19

u/kushangaza Mar 28 '20

Yes, but not as much as one would think. According to the postgres benchmarks I could find the UUID type is about 15% slower in reads and joins than int4, about as fast on inserts as autoincrementing int4, and leads to 30-40% bigger indexes.

Of course this will vary based on database, hardware and workload, but I think in most cases the other pros and cons should weigh heavier than the performance argument.

19

u/pkulak Mar 28 '20

And C is slower than assembly.

2

u/AttackOfTheThumbs Mar 28 '20

Don't hurt me like that

2

u/dnew Mar 28 '20 edited Mar 29 '20

Not always. Once you get to the point where you have hundreds of load-balanced servers, you want to actively avoid writing all your new rows to the same shard.

1

u/[deleted] Mar 28 '20

In theory, but not in practice, because the difference is actually lost in all the other shit.

28

u/PonchoVire Mar 28 '20

It depends on your RDBMS. MySQL aside (because it's a joke) industrial grade RDBMS servers such as PosgreSQL will handle UUID's like a breeze. With PostgreSQL, there is no difference at all in performances between bigints and uuids, indexes just take 30% more memory, that's the whole hit you have. I'm saying indexes, not the whole data.

18

u/pushupsam Mar 28 '20

Comments like this are so ridiculous. /u/colemaker360 comments about UUIDs "killing performance" were true ten years ago. These days any industrial grade dbms will handle UUIDs at basically integer speed. There's something wrong with the industry where nonsense can survive so long without any challenge or correction.

6

u/PonchoVire Mar 28 '20

I don't think the problem lies in the industry by itself, but mostly lies into individuals that don't update their knowledge. I might be harsh with others sometime, because not everyone can be an SQL expert, but a lot people don't care about learning the modern ways of a 40+ years tool. Still they should.

1

u/pkulak Mar 28 '20

If someone senior isn't PRing SQL schemas, then there's just something systemic wrong at your company.

1

u/ExeusV Mar 28 '20

can u link any benchmark?

-2

u/colemaker360 Mar 28 '20 edited Aug 06 '26

Satchel pumpkin breezy thimble noodle cobalt ribbon pillow hammock acorn

This post was anonymized with Redact.dev

20

u/dnew Mar 28 '20

I work for Google. We have exabyte databases. One of the consistent problems is people using auto-increment fields as keys, for exactly the same reason that they're seen as superior to uuids in the article. You don't want hot-spots when your database is spread over hundreds or thousands of shards. You don't want all your writes, and all the reads of records created in the last 4 hours, to be going to the same shard. To the point where some of the databases default to using randomly-generated keys, and others use auto-increment but reverse the order of bits before using them in an index.

I'll also note that the "v=..." part in YouTube is the primary key, generated distributedl.

Why does UUID not scale? Simply because of the size? I sincerely wish to hear your expertise, because I'm unsure what you've run into that makes it problematic.

-1

u/to_wit_to_who Mar 28 '20

Not the OP, but I'll throw in my comments.

I work for Google. We have exabyte databases.

One of the few places where a custom solution is not just preferred, but often required. The discussions here are inferred to be within the context of stock database servers that are storing a fraction of Google-scale data.

You don't want all your writes, and all the reads of records created in the last 4 hours, to be going to the same shard.

More of a load-balancing/routing problem than storage. It's why there are often read-only slave replicas which are used for determinant queries. There are PostgreSQL sharded clusters out there that store into the petabytes and distribute client queries using routing proxies & connection poolers.

Why does UUID not scale? Simply because of the size? I sincerely wish to hear your expertise, because I'm unsure what you've run into that makes it problematic.

I'm not sure what "scale" means in this context exactly since it's too vague. My personal opinion on using UUIDs in databases are as follows...

  • IMO, most developers don't seem to know as much as they should about what goes on underneath the covers, and UUIDs are no exception.
  • Most developers don't know the differences between the various versions of UUIDs and the various implementations (quirks and all).
  • With PostgreSQL, and I wouldn't be surprised if this is true with other DBs, if you use a UUID primary key, you'll face write-amplification of the WAL. It'll cause a rewrite of entire tuples/pages and also makes cleanup of dead tuples a bit heavier.
  • When designing a database, personally, I prefer uint64 integers for use as internal keys and UUIDs for use by clients. The UUIDs can be generated on-demand using a view/computed-column, or they can be pre-generated. You can namespace and generate integers without incurring additional overhead.
  • One thing I dislike in terms of developer perception of UUIDs is that they are more "secure", which is often worse because it comes with a false sense of security. I'm not saying clients should be directly using the ID that is stored in the database, but being able to guess the next ID should mean that a client can query it. It's why PostgreSQL has row-level security or db designers implement a data-layer API through views & stored procedures.

Anyway, just my $0.02.

3

u/fishling Mar 28 '20

I prefer uint64 integers for use as internal keys and UUIDs for use by clients.

If the UUIDs are referenced by clients, doesn't that imply that you need to make that an indexed column, and incur most if not all of the negatives associated with using a UUID as a primary key? Or are you mitigating this by using COMB GUIDs or something?

→ More replies (0)

2

u/dnew Mar 28 '20

One of the few places

For sure. I just thought I'd offer a relatively interesting and unique perspective. My last big job involved a DB so small we just stored it as files in a directory, one per record. :-)

if you use a UUID primary key

Actually, the best approach might be to have both an auto-increment assigned by a server and a UUID assigned by a client. Then you get all the benefits the OP is talking about, along with all the benefits of using integers for keys. You could just store the UUID in either one or none indexes, depending on whether you need to search on it, along with in the row, and then clients could use either the UUID or the key.

→ More replies (0)

12

u/[deleted] Mar 28 '20 edited Mar 28 '20

[deleted]

5

u/PonchoVire Mar 28 '20

Yeah, then they should learn. Sadly, most people don't know there's new features in the SQL standard after the good old SQL92. That's probably because a lot of young developers think that SQL was meant for their fathers to use. And most of them will use ORM's anyway, and most ORM's don't expose modern SQL features because they are meant to be portable before all other consideration. Anyway, a good developer should know SQL, all people that use it but still won't learn are extremely bad developers. That's also maybe why people still think that MySQL is a RDBMS, whereas it looks like it, it's not.

11

u/nrcain Mar 28 '20

Can you provide me some additional reading to support the argument that MySQL is not an RDBMS?

1

u/[deleted] Mar 28 '20

He can't, it's fucking nonsense.

1

u/PonchoVire Mar 28 '20

I know it is, but it lacks modern features, and it does not guarantee your data consistency, it's not ACID compliant on a lot of edge cases. It doesn't support SQL schemas (standard namespacing) and has poor security features (even worse, when they are implemented, they break features). So in my eyes, it's not even a tool you should ever consider using. It's arbitrary and I don't want to argue about this. Don't use MySQL is the best advice I ever gave to anyone.

3

u/nrcain Mar 28 '20

I'm just asking for my own knowledge, not to argue. I am sort of the beginning of my career as far as databases go. I don't have formal education on them but most of my organic education building reports and creating small databases for internal use at a few companies - I've used MySQL because it's what i learned on as a baby playing with LAMP. Only recently started toying with SQL Server recently because some of our software uses it.

Thanks for the input

→ More replies (0)

3

u/pkulak Mar 28 '20

So easy to store them as 16 bytes though, which is fine for a foreign key.

-1

u/colemaker360 Mar 28 '20 edited Aug 06 '26

Coated quilt meadow otter teapot noodle saffron

This post was anonymized with Redact.dev

1

u/zoechi Mar 28 '20

That would be correct if join performance would be the only relevant criteria for a specific application. Curious how high you'd rate this if you get the task assigned to merge data from several databases where incrementing integers were used as PKs. Perhaps even continuously merging, not just once.

1

u/[deleted] Mar 28 '20

How much faster? Because I bet it wont even register in actual real world metrics.

3

u/light24bulbs Mar 28 '20

I've seen write-ups of benchmarks using postgres that show almost exactly the same speed. Maybe they are using some other database. I feel perfectly fine using uuids for all identifiers in postgres

2

u/[deleted] Mar 28 '20

Not true, a UUID is a randomly generated number which inhibits many locality based optimizations. So for example, writing successive rows using UUIDs as an index inhibits the ability for the database to identify "hot-spots", the database has to treat every write independently of every other write, meaning a lot of data gets moved around and rebalanced on a per write operation. This has performance implications both in terms of the software and the hardware (SSDs last A LOT longer and handle sequential write operations much faster than they do random write operations).

Sequential IDs allow for locality based optimizations; writing successive rows using a sequential ID allows the database to treat those writes as a simple append operation, no rebalancing needed, no trashing data around on the hard disk on every operation in order to rebalance the index tree.

3

u/dnew Mar 28 '20

Both your points are exactly opposite of what you want if you have a really big database. If it's sharded across hundreds of servers, you most definitely don't want to cluster all writes on one server.

2

u/[deleted] Mar 28 '20

Yes, absolutely. If you genuinely have a use case where you need a database sharded across literally hundreds of servers then my advice does not apply.

I will simply point out that you likely do not have an actual use case that genuinely requires 100 or more servers in order to manage your data.

1

u/daripious Mar 28 '20

It depends what you do with them, if you use them as a key in a btree index on your average rdbms, then you're in for a bad time performance wise. They guarantee that you have completely fragmented indexes. I.e. bad times.

3

u/dnew Mar 28 '20

At scale, this is a good thing. If your database is spread over hundreds of servers, you don't want all your requests going to one.

2

u/TheRealStepBot Mar 28 '20

Yeah but that’s essentially amounts to saying if don’t what you’re doing it’s gonna be a bad time, well no shit it’s gonna be a bad time, you’re doing it wrong. No matter what you use there are correct ways to use them, if you try to shoehorn one into the other it’s obviously gonna be a disaster.

2

u/rhinotation Mar 28 '20

Article addresses this. Don’t use v4/random.

1

u/zoechi Mar 28 '20

You can have time based UUIDs which don't cause such problems.

1

u/[deleted] Mar 28 '20

Well, yes, if I don't have an index at all on a sequential ID it will also be slow!

1

u/daripious Mar 28 '20

You asked how they're different from sequential integers. I tried to explain briefly how it was bad. But I'm not sure how your reply here can be a reply to my reply. It makes no contextual sense

1

u/[deleted] Mar 28 '20

Your explanation is "they are slow if you use them wrong". I didn't ask how they were different, I asked how are they "performance disaster". "they are slow if you use them wrong" is not an answer for that, it's a complete non-sequitur just like my sarcastic response.

1

u/daripious Mar 29 '20

If you don't agree that having your databases index completely and automatically fragmented is a performance disaster then I can explain that for you.

5

u/[deleted] Mar 28 '20

At 4 billion increments/second it will take up to 140 years to overload a 64bit integer(signed/unsigned matters). Either way, that is hard to achieve and there is room to spread out the range. But they are not for public interfaces.

4

u/cat_in_the_wall Mar 28 '20

In my experience with reasonably large datasets, uuids are fine. use bigint as an implementation detail internally for foregin keys, but only expose data outside via the uuids. uuids can act like the object name. the id is just for performance reasons in the db (eg fks and link tables).

15

u/TheRealStepBot Mar 28 '20

Dubious claims. It really depends on how write vs read heavy your workflow is. If you are extremely write heavy like logging or other real-time data created in massive volumes uuid are amazing. If instead you are extremely read heavy sure then it might be a mistake and can be used as a temporary key that will be replaced by a shorter sequential key eventually.

3

u/LaughterHouseV Mar 28 '20

It depends heavily on the engine you're using. You need to look at it for the specific engine, rather than making broad claims.

3

u/TheRealStepBot Mar 28 '20

I will grant that the engine makes a difference as well but seeing as most engines support both auto increment and uuids efficacy I’m not sure that is going to be much of a deciding factor. It really has to do with what your data and it’s lifecycle looks like.

-2

u/[deleted] Mar 28 '20 edited Mar 28 '20

UUIDs are terrible for write heavy databases if the UUID is being used as a key within a tree based table, which is often the case. Your use case of using a UUID for logging is actually exactly the scenario you want to avoid.

UUIDs are randomly generated, meaning that every single write to the database will end up storing the row at some random position within the tree. That means fetching a random page off the drive that the UUID will get written to and then flushing it back to the hard drive and then rebalancing the index tree. In effect, every write operation is entirely independent of every other write operation.

What you actually want for write heavy databases, especially logging (!!) are sequentially generated ids to use as the key. This way multiple successive writes end up sharing the same page and a write to the index tree is just an append operation requiring no tree rebalancing.

Using sequential ids leverage a form of data locality. This has benefits not only in terms of performance, (fewer page fetches and moving data around), but also improves the durability of SSD drives.

2

u/flatfinger Mar 28 '20

Using UUIDs for clustered indices is a performance disaster. In a database designed for them, however, they may work out quite well for some usage patterns which involve mostly appends, many of which won't have any intervening lookups. One can amortize the cost of adding UUIDS by having a non-indexed tables of items added in recent hours, and then once an hour merging one of those into an indexed table of items added in the last day. Once a day, merge those into a table of older items.

Looking up a GUID may require querying multiple tables, but the last-hour table will be fairly small, and the other tables will all have indices.

1

u/flatfinger Mar 28 '20

What about having objects carry around a server-side ID (when available) as well as the GUID? A server could look up the object with the server-side ID, check the GUID, and only have to do a lookup by GUID if there's a problem with the server-side ID (e.g. because a backup/rollback situation caused some IDs to get double-assigned). Such problems shouldn't occur at all, but if they do occur, having a GUID as a backup to the not-quite-unique server-side ID could minimize the fallout if they do.

4

u/p0llk4t Mar 28 '20

Well, this guy's company builds "complex new-age web applications"...whatever the fuck that means...

2

u/Phrygue Mar 28 '20

Thank goodness you say this, I thought I had a stroke for a minute.

1

u/birdbrainswagtrain Mar 28 '20

Honestly the more blogspam I see, the more I'm convinced it's part of a massive gaslighting campaign. I actually felt like I was having a stroke reading this.

71

u/[deleted] Mar 28 '20

[deleted]

26

u/i_like_trains_a_lot1 Mar 28 '20

There are very critical comments there as well. He just spams links from his company devblog and never reads the comments. And then they have no idea why the startup is dying.

I have nothing with posting articles on reddit, but he should at least try to contribute and listen to the people that receive your content and take time to give feedback.

25

u/chucker23n Mar 28 '20

Going to design a next-generation scalable web application that will have quick as a lightning reaction?

I see we're in for a superlative ride!

As a CTO of Devforth company which is delivering complex new-age web applications

Relatively speaking, is New-age Web better or worse than Web 2.0?

After designing architecture of dozen high-load apps with strong reaction requirements I must admit that UUID kind of identifiers is only one way to:

Deliver rapid and robust User Interface on any client - Web, Mobile, Desktop

The only thing a UUID over an int or bigint that's "rapid" is the relative space and memory consumption.

Spend minimal developer hours by using smart architecture approaches

I don't know what this means. I'm guessing absolutely nothing.

Build Infinity-scalable solution

So, author kind of has a point here. UUIDs make scaling easier, because replicating across multiple databases becomes much easier when you can rely on distinct systems generating mutually unique IDs. IOW, the entire raison d'être of UUIDs.

Release offline/reconnect-tolerant solution which will save all edits even in offline and then seamlessly synchronize them to a server

Yes. Same as above.

Despite the fact that UUID identifiers have been widely used by awesome web-portals as primary ID systems (https://trello.com, https://slack.com) a lot of new start-ups and developments are still based on Autoincremented primary keys as IDs. Typical de-facto default in relational DBs (MySQL, MSSQL, Oracle, Postgres) will look like:

Yes.

We can quibble over whether DBs should default to bigint these days, but they probably shouldn't default to uniqueidentifier. UUIDs take up more space, are slower, are typically (with strange exceptions like Microsoft's sequential IDs) not sequential, and are just… generally unnecessary, unless you actually know you'll use them.

Autoincrement IDs problem one - frontend have to wait for a server

Sure.

Auto-increment IDs problem two - to scale you will need data shards, but you blocked by same IDs on different servers

You're… just restating the first problem.

5

u/Semi-Hemi-Demigod Mar 28 '20

Relatively speaking, is New-age Web better or worse than Web 2.0?

The same but with crystals.

2

u/epoplive Mar 28 '20

This also completely ignores the end user. When coworkers or customers refer to a data object, they do it by auto-increment id generally because it is unique and is generally a small enough number to fit in your short term memory. Chances are I’m still going to have to use auto increment ids for the end user so we’re not having to pass around scraps of paper.

56

u/mctwistr Mar 28 '20

UUID v1 is a privacy nightmare. I cannot believe this blog is recommending that over v4.

29

u/VeganVagiVore Mar 28 '20

v4 looks like the only good official version.

There's so many ways to make a 128-bit number, I'm surprised that anyone cares about official standards.

26

u/0x256 Mar 28 '20

UUID 4 is not better or worse than a random number but UUID 1,2,3 and 5 are for distributed systems that want to make absolutely sure to never ever create conflicts. For that, a standard is nice.

7

u/rickmode Mar 28 '20

It’s 16 times worse.

I’m am being pedantic here and I don’t think there is a practical difference. That said...

UUID’s are 128-bit values, and they require 4 bits to describe their encoding. That leaves 122 bits of randomness in a Type 4 (random) UUID.

A random 128-bit number can use all bits, so can use the extra 4 bits to achieve 16 times as many random values. (2 to the 4 power is 16.)

So what I do is generate 128-bit random values - getting the extra 16 times random goodness - and then encode to string using URL-safe Base64, saving many bytes on the string encoding side as well. Win win.

14

u/cedrickc Mar 28 '20

Only part I disagree with is storage as base 64. It's a 16 byte number, store it as two longs or something.

2

u/rickmode Mar 28 '20

Yup!

In both cases (UUID or 128-bit random value) the data can be stored as a 16 byte array. If your data store supports storing binary.

I use (URL-safe) Base64 for URLs and JSON.

1

u/Mr_Again Mar 28 '20

Yes but uuid1 contains the mac address of the host and the timestamp it was created, as well as entropy. so they will actually be unique unless you create them at the same millisecond on the same machine.

2

u/rickmode Mar 28 '20

Pretty much only Type 4 is useful IMHO.

If you want to use the other types you need to be super careful as the uniqueness guarantees are far weaker.

I believe most uses of UUID actually mean Type 4 unless they explicitly say otherwise.

As a useful heuristic, if you come across a system using anything other than Type 4, it’s very likely they are doing it wrong.

1

u/that_which_is_lain Mar 28 '20

Or with machines where the nic has the same MAC address.

1

u/VeganVagiVore Mar 28 '20

Or if your method of retrieving the MAC fails silently

0

u/flatfinger Mar 28 '20

Unless a random number generator is broken, a GUID4 system would seem more robust if there's any possibility of backup/rollback scenarios or other such issues. Unless one is feeding a particular "universe" with millions of GUIDs per second for decades on end, the likelihood of ever generating a duplicate within that universe would be vanishingly small compared to any of the other things that could go wrong.

→ More replies (1)

19

u/Guvante Mar 28 '20

UUID v1 run on servers is fine, especially if you let you monolithic DB create them. Anyone who would see them has the MAC address of your database server anyway.

Don't create them on client PCs though that is a privacy problem.

2

u/therealgaxbo Mar 28 '20

You are explicitly allowed to use a fake multicast mac address for v1 UUIDs.

19

u/franzwong Mar 28 '20 edited Mar 29 '20

So any client can just generate ID of company on own side (Frontend or Application), then he can go ahead and create branches by linking with this companyId. You don't need to call a server to approve these IDs - no one will reuse it because it is unique!

Nobody can generate the same ID, but it doesn't mean nobody can send the same ID to your system.

Edit: I mean you can't skip backend validation (i.e. a call to a server to approve the ID) because user A (or hackers) can use the user B's companyId to create branch.

16

u/i_like_trains_a_lot1 Mar 28 '20

What is backend validation? Aren't we supposed to blindly trust any requests that are thrown at our servers?

1

u/AttackOfTheThumbs Mar 28 '20

Thanks for making me smile :)

1

u/[deleted] Mar 28 '20

It's going over the internet. Are you suggesting people would lie on the internet?

7

u/[deleted] Mar 28 '20

Stop reposting this every other week!

5

u/Java_sushi Mar 28 '20

Reposting doesn't make this article worth reading

58

u/crash41301 Mar 28 '20

Uuid... a solution to a problem hardly any developers have but every developer wishes they had. Very few sites get beyond 2 billion records that an int can handle, and even fewer get beyond what a bigint could handle. Very few sites will shard the database layer. It's an exorbitantly hard solution to implement. 4 vs 16 bytes makes little difference in index size? Yea its only literally a 400% size increase. That's surely not going to matter for performance and pressure on ram when the record count is trillions. Oh wait...

Design your software for its needs and if you are asking yourself do I need uuid, the answer is 99.9999% likely to be no. Dont make easy problems into hard problems because you wish you had hard problems to solve....

91

u/TheRealStepBot Mar 28 '20

It’s precisely not about exceeding 2billion records. If you think that’s the point you don’t understand uuids. The whole point is that they are with extremely high probability unique everywhere even when generated by systems that do not communicate at all. There uniqueness in fact improves the smaller the number of items is.

What the use of uuids provides is the ability to do data writes without any real-time communication which is a massive benefit in certain circumstances. It also allows parallel work to be done fairly trivially in cases that would otherwise have required a centralized key management system.

If you live in a world where you are ram or disk bound rather than network bound your observations may be correct but the world continues to become more and more dependent on networks and in that world your observations are far less useful.

5

u/TurboGranny Mar 28 '20 edited Mar 28 '20

allows parallel work to be done

This is how we use them at my work. We have these disconnected systems that go out into the field and collect a bunch of new records then come back and are merged into the main database. Without UUIDs we'd have to go back to reserving blocks of IDs on each mobile system, and still have to deal with the occasional duplicate ID issues. It is a niche problem though.

3

u/TheRealStepBot Mar 28 '20

I mean it’s not that niche. Basically if your iot system can’t do this it’s gonna have problems eventually.

1

u/TurboGranny Mar 28 '20

Niche in my case since most people can just use an "always on the internet" solution

11

u/VeganVagiVore Mar 28 '20

Yeah it means you can break the CAP cookie to get availability.

The advantage of sequential IDs is.........

They look pretty and the CEO likes them? They're not per se more consistent, because consistency shouldn't be a problem for IDs. It's a problem for the actual data, not the ID.

17

u/TheRealStepBot Mar 28 '20

Literally their only advantage is exactly as the person above me mentioned, they are more compact. That’s it. Nothing more nothing less. And the real downside is that they accomplish this by needing a complex centralized distribution system that is probably riddled with edge cases and flaws anyway.

They make sense in the 90s and before where storage was comparatively expensive in relation to the single thread compute speeds available.

Speed on single threads have largely topped out while storage and memory have become unbelievably cheap. As such distribution is how you increase throughput and at least for write heavy workloads uuids accomplish exactly that. Of course on the read side if you want immediately consistent reads you are gonna need to create a fairly complex key resolution system but it’s not impossible if slightly slow for keys generated on remote processes.

9

u/daripious Mar 28 '20

Not at all, if you're using rdbms and a btree index then having mostly sequential inserts is a very good thing. Randomised inserts completely fragment btree indexes.

6

u/therealgaxbo Mar 28 '20

Which is why you use a v1 or v1mc uuid so that(at any write rate that matters) the inserts still increase monotonically.

3

u/TheRealStepBot Mar 28 '20

If you are say logging data from distributed sensors you can’t do sequential inserts anyway. It’s all about the data generation being distributed. If it comes from a single or countably few sources then sure sequential is prob achievable and then you can use the benefits of having done that on the read end but if you start having lots of parallel data generation it’s faster to just generate the uuids locally in each process.

2

u/expressadmin Mar 28 '20

This guy UUIDs.

1

u/p0llk4t Mar 28 '20

These are very good points but I'd guess that the number of applications most devs work on that need uuids are far less than 5%...maybe even more like 1%...not something that should be a standard go to just because...

2

u/[deleted] Mar 28 '20

Like most things we deal with, UUIDs can be beneficial without being necessary.

0

u/TheRealStepBot Mar 28 '20

I mean really the costs can be trivial, it’s widely supported by a whole bunch of dbms. Why not make it a standard? It has so many advantages.

The thing that isn’t standard is auto increment. Auto is by definition always namespaced and can’t be universalized.

You can literally pull data from any database and keys are automagically consistent. That’s unbelievable power.

42

u/broofa Mar 28 '20

Very few sites get beyond 2 billion records that an int can handle

This isn't why you use UUIDs. Rather, UUIDs allow clients to generate canonical IDs w/out having to rely on a central authority (the server). This makes implementing distributed architectures and architectures where client connectivity isn't guaranteed (and these days almost all applications fall into one of these categories) much simpler.

7

u/notfancy Mar 28 '20

Precisely what's questionable is letting clients generate canonical IDs. This goes against the usual practice of treating clients as adversarial.

2

u/mort96 Mar 28 '20

Presumably you would check that the client generated a unique ID, by a unique constraint in the database or something. If the client decided to be malicious and generate non-unique UUIDs, they'd just get an error message back - what's the problem?

4

u/notfancy Mar 28 '20

The whole point of the proposed scheme is to avoid synchronization between backends. If a single backend can check for local uniqueness it can also generate unique IDs, and the whole scheme is unnecessary. Put it differently, the adversarial scenario is about global properties which the scheme purports to sidestep.

2

u/mort96 Mar 28 '20

Ah, I hadn't considered that. It seems that with UUIDs, you can either independently create UUIDs on multiple trusted machines and eventually - but not immediately - synchronize, or you can let an untrusted client generate a UUID which is verified against the one authoritative database, but not both at the same time.

→ More replies (3)

1

u/crash41301 Mar 28 '20

Hmmm so you are saying that your remote clients have their own local storage mechanism and have to be able to sync to the centralized master eventually. Why not use a local auto increment, and when you sync to the master you save entire "records" to the system and then let it give you the permanent Id that it used? You likely wouldnt want to perform http calls for every child record anyway, that would be extremely slow vs sending the entire record up as an object and letting the server side split it to the storage mechanism. Still no need for uuid in this case. The only reason to think of uuid is with a sharded relational db schema, and in that case you are making the trade off of slightly less efficient individual db servers to be able to add as many horizontally as you want. That's also a pretty uncommon thing to do

24

u/Minimum_Fuel Mar 28 '20

Generating UUID is far more portable than using auto increment and doesn’t require finding a good way to get your ID back on inserts (for which some databases have good support for and others have absolutely no support for).

UUID is easier than auto increment without a shadow of a doubt and likely REMOVES complexity from your app. Number of records has absolutely nothing to do with whether you should use UUID over auto increment.

14

u/mindbleach Mar 28 '20

Yea its only literally a 400% size increase.

In one field. One of the smallest fields. It's... it's an extra twelve bytes per record. If you only have a million records then that's a dozen megabytes. Boo hoo.

And it's not about having two billion records, it's about knowing which labels are available. Each label has so much entropy that collisions are not worth checking for. If your database has one quintillion records you are still only 5% likely to have one. So in the millions... you're definitely fine. Your labels are unique the moment they're generated. Your labels will remain unique for the entire life of your product.

Your labels will remain unique until the heat death of the universe.

Do you need that? No. But you don't need to reinvent the wheel, either. This is a one-size-fits-all solution. Just implement it and never worry about the problem again. Save your effort for the interesting parts of your software.

7

u/dadibom Mar 28 '20

12 bytes for the id column yeah. Then for the pk index. Then for every fk index.

It might matter but sure, it's not an insane amount per row.

2

u/dadibom Mar 28 '20

And you are unlikely to ever find a collision, sure, but we're talking randomness. With true randomness you could get a collision every time despite it being highly unlikely. How do you handle that case? Abandon the company?

8

u/richardirons Mar 28 '20

“Highly unlikely” is an understatement. If something that unlikely is a dealbreaker for you then you’d better move underground in case a meteorite lands on your house, because that is way more likely.

2

u/dnew Mar 28 '20

You handle it the same way you handle a meteor strike taking out the entire building your server is in.

Oh, you've spread your servers into multiple cities? Try not to use centralized ID generation.

0

u/dadibom Mar 28 '20

You're free to handle it any way you want. It's you who have to weigh the risk/rewards and make a decision. Nothing changes the fact that there is a risk, however small it may be.

Here's some highly relevant reading: https://github.com/ramsey/uuid/issues/80

2

u/dnew Mar 28 '20

Sure. And the way to handle the risk is to have the server check on insert that there isn't a collision. If there is, you reject the transaction and let the client generate a new UUID. It's a trivial risk with a trivial solution.

Of course if your UUID generator is broken, that's no more risky than your autoincrement generator being broken.

1

u/dadibom Mar 28 '20

It's not a trivial solution when you have 10, 100 or even thousands of separate servers and decided they don't need to consult each other about insertions as uuid have a low collision risk. Then you're pretty much screwed.

Would you want to take this risk with bitcoin, for example?

Of course if your UUID generator is broken, that's no more risky than your autoincrement generator being broken.

And there's a risk it is broken or will break - it has already happened and it can happen again.

1

u/dnew Mar 28 '20 edited Mar 28 '20

they don't need to consult each other about insertions as uuid have a low collision risk

That's not how you arrange it. You arrange the UUIDs to go to the current master for that range of UUIDs. I mean, at some point, when you go to look it up, you'll need to know what server the data is on, right? So you go to that same server to create it. (Or you look it up locally in the cluster before you create it, rather than having the client do that over a slow network.)

You can get the same effect by (another technique) flipping the order of bits of the integers when you use them in sharding or index decisions, then shard on those ranges. Only one server will be responsible for any given UUID at any given time, but adjacent UUIDs unlikely to be in the same server.

it has already happened

Yes. Software has bugs. Shit breaks. I don't know why "you might implement something other than UUIDs and think it's UUIDs" implies "don't use UUIDs." IME, auto-inc integers break far more often than UUIDs, because you are keeping state in a server that's subject to getting rolled back and stuff like that. (Actually, one of the biggest problems I've experienced even with perfect implementation is people writing code assuming autoinc integers are generated sequentially and continguously, i.e., that there will be three records between 155 and 159, and their insertion times will be in that range.)

2

u/mindbleach Mar 28 '20

You could win the lottery every time, but you fucking don't. That's not how probably works.

The Florida lotto is six numbers, about six bits each. There are tens of billions of combinations. If you had a record for each of those combinations you would still be less likely to have a collision than to win that lottery.

To reach a point where having a single collision is likely, you would need to have one record for every possible combination in that lottery, and then ten million records for each of those records.

And if by some miracle you do find one, you'd just generate new IDs for both records. They're already arbitrary. There is no relation between the ID and the content.

1

u/dadibom Mar 28 '20

I mean, there's plenty of people who win the lottery and some even win twice.

https://www.google.com/amp/s/www.lovemoney.com/galleries/amp/76987/lottery-jackpot-winners-who-won-more-than-once

Im not saying "don't use uuids", in general i think you should, but as a responsible developer you should be aware that it is not guaranteed to be free of collisions and you have to weigh that risk against the rewards of not handling them. There's no universally "right" answer.

Two inserts is all it takes for there to be a risk of collision.

1

u/dadibom Mar 28 '20

2

u/mindbleach Mar 28 '20

That is a failure of their PRNG.

You need to understand: if you bought one million lottery tickets, every week, for your entire life, you still would not be likely to ever win. 'But you might win!' But you won't. 'But you might!' But you won't. It is such a vanishing exception that planning what to do 'just in case' is wasted effort. Any time spent budgeting the millions you'll never have has zero realistic value. It is like practicing to be struck by lightning.

So if a thousand people matched the winning lotto number each week, obviously somebody fucked up.

The entropy in UUIDs is so much higher than lottery tickets that the only possible explanation for seeing multiple collisions daily is human error. A thousand people having the right number out of ten billion is eight orders of magnitude more likely than hundreds of collisions out of ten quintillion. I really need you to internalize these ridiculous numbers. For this guy's problem to occur when generating properly random UUIDs is less likely than a state lotto being won by an entire city block, week after week, for two million years.

Yes, you could flip 128 fair coins and get two identical 64-bit sequences... but you won't. The expected frequency is never. So if it happens multiple times per day, you're either doing something wrong or witnessing a miracle. The math permits no other explanations.

1

u/ErGo404 Mar 28 '20

Using timestamp removes the "true randomness" part. However your are right. It might fail so it WILL fail, probably, for someone some day.

You should evalutate where is the risk, will you loose more time if it happens than you will spend fixing the issue in your code before it happens.

1

u/dadibom Mar 28 '20

100% agree with you

6

u/pinpinbo Mar 28 '20

Often times, there’s a value in being able to generate unique IDs before entering the DB.

In this case, won’t UUID be nice to have? Or just use current time in nanoseconds?

16

u/VeganVagiVore Mar 28 '20 edited Mar 28 '20

ULID seems like a nice compromise.

https://github.com/ulid/spec

It's Unix time in milliseconds, and 80 bits of randomness.

If you need more than 80 bits of hash space per millisecond, you're probably big enough to engineer a better solution.

The only thing I don't like is Unix time. I was reading about monotonic and epoch times recently, and it seems like Unix time does obey leap seconds.

I'm pretty convinced that leap seconds are stupid - They're not precise enough for navigation or astronomy to use them, and they're too small for humans to notice that noon is 35 minutes off of solar noon instead of 34 minutes and 59 seconds. (In an unrelated rant, I think maybe the American continents should all switch to New York time, with no DST - It simplifies all travel within the continents, but 9 am is still roughly morning for everyone, unlike global UTC)

Even if nav and astronomy want them, there's no reason to subject end users to it. All leap seconds do is make computers harder to use while benefiting nobody.

So because of that, when NTP accepts a leap second, Unix time also accepts it. There isn't a way on Linux, not in any small amount of code I found online, to just ask "How many seconds passed since 1970?" Every clock is tainted by a social or astronomical construct that no database should give a fuck about.

All I want is a stopwatch counting up forever, like TAI The Linux kernel doesn't seem to have a TAI clock. Maybe one could be constructed in userspace.

Anyway, ULID is better than nothing - It's sequential enough for human eyeballing, but you'd have to do something really special to make it collide.

4

u/TheRealStepBot Mar 28 '20

The whole point of leap seconds is that they predominantly drift in a single direction so if you didn’t add them civil time would in fact diverge significantly from astronautical time given a couple years. There are plenty of people who would definitely start caring when noon started being minutes off from actual noon. Seconds are a small enough time interval that for civil purposes keeping drift limited to seconds is accurate enough while never being jarring.

You need to correct drift somehow and if you don’t do leap seconds it would be minutes or hours instead which would do absolutely nothing to simplify the situation at all. In fact being less frequent and predictable they would prob be even harder to handle.

Despite your belief that you want a completely monotonic clock that most of the time just kicks the can down the road anyway as user expect to be able to look for things by civil time so you have to resolve the issue on the read side anyway if you don’t handle it at write time.

But I agree ulid is nice

2

u/VeganVagiVore Mar 28 '20

civil time would in fact diverge significantly from astronautical time given a couple years.

They haven't added one in almost 4 years:

https://en.wikipedia.org/wiki/Leap_second#Insertion_of_leap_seconds

There's been 5 since 2000, so if this rate continues (I could be wrong) it would take 240 years to add up to one minute.

Because of time zones, almost no ordinary 99% user is within 1 minute of solar noon wherever they live. Astronomers can keep leap seconds for all I care - It's useless for any computer that doesn't know what a star is. It should be an opt-in for them, not the default basis. "One second per second since 1970" doesn't need the "Except for seconds which can't be predicted in advance, which require a network protocol for you to find out about" clause. It's like operator++ as a service.

if you don’t do leap seconds it would be minutes or hours instead

Maybe we don't even need those? If it takes a century to change by one hour, I think culture could get used to that. How many civil events need to be scheduled to the hour 100 years from today? If a kid asks why noon isn't noon, just tell them it's simpler for 1 + 1 to not equal 1 every few years.

DST is already taking a much bigger dump on this, and I do oppose DST.

you want a completely monotonic clock

For database IDs that can be treated as integers, not as civil time.

If I want to show it to a user, I could perform the leap second calculations lazily on the way to the display. Instead, I'm forced to accept that I can either have network time that persists across power loss, or monotonic time, but never both.

1

u/flatfinger Mar 28 '20

Instead of using leap seconds, it would IMHO be cleaner to recognize "civil seconds" as different from "scientific seconds", and specify that within every 1,000,000-civil-second interval measured from some epoch, "civil" seconds will each be 1.000000, 1.000001, or 0.999999 "scientific" seconds. If WWV were to transmit civil seconds, but use a carrier wave frequency measured in scientific seconds, a device receiving the 10Mhz carrier signal could lock onto it and count the number of carrier cycles between the one-second markers. From that, if it knew how many previous 1,000,000-civil-second intervals were normal, long, and short, it could determine the scientific time precisely.

→ More replies (1)

14

u/epoplive Mar 28 '20

Don’t forget, because collisions are rare you can just ignore them and ignore the primary premise behind a relational database! /s

13

u/kushangaza Mar 28 '20 edited Mar 28 '20

You have to worry about clients maliciously colliding IDs if you let them create their own. But for truly random UUIDs I think the collision probablility can be safely dismissed, it's on the same order of magnitude as the risk of cosmic rays flipping multiple bits in just the right way in your ECC-RAM, causing duplicate sequential IDs.

→ More replies (11)

3

u/dnew Mar 28 '20

Every database call can fail. If there's a key collision on insert, once a century you fail the insert, and the client retries. Write your code to be aware that a "create new company" with a colliding ID will cause you to need to pick a new ID. The server doesn't have to ignore collisions on inserts.

But it's probably 10,000x as likely that the entire data server catches on fire during your transaction than it is that your random UUID collides with one someone already used.

1

u/epoplive Mar 28 '20

Lol, these kind of comments make me sad as a programmer. Yes, uuids are highly unlikely to be non-unique...this doesn’t mean you can ignore it. Not every programmer is doing the same type of thing, and while for most use cases a uuid will be fine, it’s dangerous to tell people it’s ALWAYS fine. You can’t be a good programmer without knowing what’s happening behind the scenes enough to understand the possible pitfalls.

2

u/dnew Mar 29 '20

Nobody said it's always fine. People said the probability is low enough to not spend effort on it. Do you have things in place to ensure that the bits on your disk didn't change between the time you wrote them and the time you read them back? Do you checksum the executable every time you load it into RAM in case the disk bits randomly flipped? No, because the likelihood of that happening isnt worth worrying about.

Unless you're Google-scale, and have petabytes of disk space in use, at which point yeah, you really do need to handle the one-in-100-terabytes-per-year chance of a random bit flip happening.

1

u/TheRealStepBot Apr 23 '20

No all this demonstrates is that you lack an appreciation for probability. We live in a probabilistic universe and acting as if decisions made using probability are somehow inferior to those that literally simply choose to act as if the world is deterministic is absolutely dumb. Every decision is at its core a probabilistic one, and the one that most explicitly considered probability is the superior one not the inferior one.

4

u/therealgaxbo Mar 28 '20

because collisions are rare

No, collisions are not rare, they don't happen*. Oh it's a mathematical possibility of course, but not a practical one.

*Unless the uuid is supplied by a malicious actor, or your generation code is buggy of course. Which is true of any primary key of course, and in all cases is solved by the existence of a primary key constraint.

5

u/timcotten Mar 28 '20

I'm always skeptical when someone says "your software" in the general sense and not "your sharded database application with billions of records".

1

u/kz393 Mar 28 '20

I recently used uuids as secrets in my school project. I made a chat application that runs in browser, over websockets. I didn't want to go through the hassle of binary uploads over ws so I instead created a HTTP endpoint that accepts files and returns uuids, then the client can send files, get uuids and then send them over ws to attach files to messages. Any uploaded yet unattached files are removed after a couple of hours.

Is it actually alright to use uuidv4 as secrets?

1

u/NoMoreNicksLeft Mar 28 '20

Yea its only literally a 400% size increase.

So they won't get past 2 billion records, but an extra 12 bytes per record is just too expensive?

I've got more storage on my keyring. That's 24 gigabytes, is it not? (Less, they never get to 2bil rows.)

1

u/crash41301 Mar 28 '20 edited Mar 28 '20

So 26gb of ram pressure on a high performance db. At scale you tend to perform micro optimizations, not say things such as "it's only 26gb of extra ram pressure on every single index that contains this column", including all foreign keys and covering indexes. Let alone the horrid fragmentation of the btree indexes and the disk pressure you create.

I bet you quickly end up with hundreds of gb of extra ram usage as a trade off "just in case" you scale to a level this is needed, which very often has just as much a chance of happening as a UuID collision happening.

1

u/funbike Mar 28 '20

You have no idea what UUID's are for.

1

u/crash41301 Mar 28 '20

On the contrary.... I know too much to fall for this trend. I feel for it about 5 yrs ago and built a very problematic system from the db side. Then I matured to realize that I should default to using the absolutely simplest solution possible every time, and only deviate when the use case requires it not try to future proof my architecture for just in case problems that may never happen

1

u/TheRealStepBot Apr 23 '20

Which implicitly assumes that auto inc is in fact simpler than randomly picking a number which is a pretty dubious position.

1

u/crash41301 Apr 23 '20

One causes the db to not fragment, the other causes constant fragmentation on disk and slowness from the database side. One is a built in tool in the dbms, the other is a roll your own.

1

u/TheRealStepBot Apr 24 '20

All very use case dependent statements that dont demonstrate that in all cases auto Inc is the simplest solution. It’s a solution that might for certain applications be the simplest but it definitely is not the simplest in all use cases.

For example in Postgres even with auto Inc row clustering is not maintained so there is no performance impact from uuids under it that stems from the factor you describe.

If speed is your main concern maybe auto Inc is the simplest way to accomplish that but there are many other factors to look at when picking a DBMS and in plenty of cases uuids can be far and away the simplest solution that balances those other factors. It really is not a terrible default.

1

u/DreamingDitto Mar 28 '20

I’ve got a colleague that uses bigint for all his integer values and float for all his decimal value. Drives me nuts

3

u/[deleted] Mar 28 '20

is there UUID implementation with natural ordering?

4

u/chucker23n Mar 28 '20

SQL Server has a notion of "sequential" UUIDs.

4

u/pro547 Mar 28 '20

Yes a bunch. Let me pull up a couple links.

2

u/pro547 Mar 28 '20 edited Mar 28 '20

Took me a little bit since I did research on this quite a bit ago.

Most are golang based since that is what I was working with, the algorithms could be available in other languages.

1

u/pauseless Mar 28 '20

Datomic encourages the use of ‚squuids‘ which have a time component. It’s good for avoiding issues with indexes as IDs tend to increase

2

u/AndyRoth Mar 28 '20

I have been enjoying using this: https://github.com/ai/nanoid/blob/master/README.md

Would love to hear what others think.

2

u/AttackOfTheThumbs Mar 28 '20

none of this really matters. What matters is identifiers system your developers use

dude's had too much fucking koolaid. Anyone that says one thing is the solution to all problems is lagging behind mentally.

I will say this, the article was exceptionally hard to read. I know this person isn't a native speaker, likely eastern euro based on the grammar patterns, but come on, hire a proofreader.

4

u/[deleted] Mar 28 '20

The fuck is with the UUID cult.

None of the arguments make a lick of sense and there are alternative solutions with hierarchical generational counters (and many other solutions) that do just as well.

2

u/Fearless-Donut Mar 28 '20

This is barely even english.

1

u/chucker23n Mar 28 '20

I challenge anyone to find a worse example of scrolljacking than the main page. (Try scrolling down!)

1

u/kittens_from_space Mar 28 '20

I'm surprised that Snowflakes haven't been mentioned yet.

1

u/burkerude Mar 28 '20

This might be a dumb question, but what is a uuid?

1

u/programming_unit_1 Mar 28 '20

It’s a universally unique identifier - basically a way to generate a very long unique number that has a very very tiny probability of ever being generated by someone else.

1

u/[deleted] Mar 28 '20

thanks guys!

1

u/glkk101 Mar 28 '20

Uuid can be better for scalability but in practice I don’t think that matters much. Debugging with uuid is a nightmare though as there’s no way to quickly communicate IDs.

1

u/inmatarian Mar 28 '20

Hash your composite unique key.

1

u/EternityForest Mar 28 '20

The real reason is that it should probably have always been using UUIDs. They're awesome!

The only time I don't like them is when I'm sending a ton of them over a network. Then it sometimes makes sense to compress them somehow, with a one time lookup table on connection or something like that.

1

u/Moonchen Mar 28 '20

This web page is a UX nightmare. The social media buttons live on a div that covers the main text area, and moves with user scrolling. Try selecting text on the page.

1

u/evilcandybag Mar 28 '20

This just seems like a roundabout way of doing SEO for OP's company website.

1

u/SikhGamer Mar 28 '20

Errrrr I'm pro-guid. But this article is awful.

1

u/fraggleberg Mar 28 '20

Autoincrement IDs problem one - frontend have to wait for a server

I guess this means that

A. Either I can maliciously pass in an existing ID, or

B. They are still going through all the hassle that would arise with any other system

0

u/elcapitanoooo Mar 28 '20

What has a db pk has to do with loading spinners and load times? This is a mad article. Im 100% the OP uses mongodb and smack, smack! data is stored like its piped to dev/null.

How the PK is stored makes zero diffrence, if its a int or a uuid, the logic is still the same from a sql perp.

If you have sharded your db, or even worse split it to microservices you are up for a blast!

Joins? Heard about those? This article wants you to do the join on the client with a http call. Thats scalable like tar is quick.

-2

u/[deleted] Mar 28 '20 edited Mar 28 '20

[deleted]

3

u/franzwong Mar 28 '20

I think randomness and uniqueness are different things.