tags:

views:

62

answers:

4

I need to create objects and make them available on the web. Similarly to stackoverflow, I have something like.

http://stackoverflow.com/users/78374

However, in my case the ID of the object I create must be unique, so I am thinking about a UUID, leading to a URL like

http://example.com/users/{8e931066-7d87-4f2b-a3b5-608c4c9a9083}

because later on I will have to merge different databases together, and I don't want to have merging issues.

Is this an accepted practice? What are the alternatives?

+1  A: 

There is no problem in that. Hotmail does that.

Shawn Mclean
+4  A: 

If it's just a question of merging databases, giving each db a unique identifier and then combining that with the auto-increment PK would give unique ids for every object you could use and not worry about merging issues.

code_burgar
I think this is the right approach. Using UUIDs is overkill. URLs is something that users see; they need to be short and simple if possible.
Martin v. Löwis
but that would mean that the IDs will change at the merge
Stefano Borini
I've merged some by just adding 10,000 to the second databases' IDs, and then adjusted my sequences. In one case, where I've got a sort of materialized view into two databases that are still growing, one of 'em is multiplied by `-1` before merging. But in cases like this, you just have two columns in the merged table, with the naming authority and the assigned number as the primary key.
Joe
+1  A: 

If merging must be 100% seamless, then a UUID is probably your best bet. If you are looking to generate more human-friendly URL's, you may consider using a unique "Account Name" that the user can define. This would potentially create conflicts if merging databases, but they can be overcome.

Mike
+1  A: 

I would agree that this is an acceptable practice because it keeps the user ID unique when using it over multiple databases and applications.

I use the same practice in my caching application block. The caching application block generates a GUID when an item is cached and the application uses that GUID to retrieve the item from the cache.

Michael Kniskern