0

I've been looking at resources to understand UUIDs. I now understand what they are, but I still don't really see where they are truly useful.

Most of the information I've found revolves around the idea of a distributed system: you get almost truly unique id's automatically generated and so on all the distributed systems you shouldn't expect to see an id twice.

But why do you want that? what is the issue if two different databases have the same id? Is this only useful if you want to collect all the data from all databases and have them be unique?

RonJohn
  • 694
  • 2
  • 12
  • 31

2 Answers2

1

what is the issue if two different databases have the same id?

Picture a distributed application and database system that allowed you to place Orders for certain Products, like the Amazon mobile app. Let's pretend the app allowed offline functionality for when people had bad cell service, such as being able to place an Order offline. And then the next time they're online, that Order gets synced from the local database on their mobile device to the central database on Amazon's servers.

If the app was designed to use an auto-increment column as the key, let's call it OrderId, that got generated locally when the device was offline, it would be possible for two different people to generate the same OrderId for two completely different and unrelated Orders. Hopefully that's clear how that's a problem when they go to sync to the centralized database on Amazon's servers.

A GUID is a decent solution to this problem, since the chance of collisions (the same value being generated twice globally) is relatively low.


Of course there are other solutions than using GUIDs such as error handling the collisions of two auto-increment IDs. But that may require more thought and work than using a GUID. But there are alternative solutions, which come down to preference, all things considered.

J.D.
  • 40,776
  • 12
  • 62
  • 141
0

if you are using a distributed DB which might have data loads on multiple nodes, GUID might be a good idea for many considerations:

  • Scalability and Performance (incremental ID is centralized and asking for a new ID and checking the sequence and the last ID might consume resources)
  • Sharding (Using an incremental ID might cause hotspot nodes which might be accessed more than others which is against the distributed principle)