What’s your opinion on using UUIDs as database row identifiers, particularly in web apps?

Question :

What’s your opinion on using UUIDs as database row identifiers, particularly in web apps?,

Answer :

I’ve always preferred to use long integers as primary keys in databases, for simplicity and (assumed) speed. But when using a or Rails-like URL scheme for object instances, I’d then end up with URLs like this:


And then the assumption is that there are also users with IDs of 782, 781, …, 2, and 1. Assuming that the web app in question is secure enough to prevent people entering other numbers to view other users without authorization, a simple sequentially-assigned surrogate key also “leaks” the total number of instances (older than this one), in this case users, which might be privileged information. (For instance, I am user #726 in stackoverflow.)

Read More  Learning Version Control, and learning it well

Would a /GUID be a better solution? Then I could set up URLs like this:


Not exactly succinct, but there’s less implied information about users on display. Sure, it smacks of “security through obscurity” which is no substitute for proper security, but it seems at least a little more secure.

Is that benefit worth the cost and complexity of implementing UUIDs for web-addressable object instances? I think that I’d still want to use integer columns as database PKs just to speed up joins.

There’s also the question of in-database representation of UUIDs. I know MySQL stores them as 36-character strings. Postgres seems to have a more efficient internal representation (128 bits?) but I haven’t tried it myself. Anyone have any experience with this?

Read More  Is there some way of recycling a Crystal Reports dataset?

Update: for those who asked about just using the user name in the URL (e.g., , that works fine for object instances with names that are unique, but what about the zillions of web app objects that can really only be identified by number? Orders, transactions, invoices, duplicate image names, stackoverflow questions, …


I can’t say about the web side of your question. But uuids are great for n-tier applications. PK generation can be decentralized: each client generates it’s own pk without risk of collision.
And the speed difference is generally small.

Make sure your database supports an efficient storage datatype (16 bytes, 128 bits).
At the very least you can encode the uuid string in base64 and use char(22).

Read More  How do I check if a SQL Server text column is empty?

I’ve used them extensively with Firebird and do recommend.

That’s the answer What’s your opinion on using UUIDs as database row identifiers, particularly in web apps?, Hope this helps those looking for an answer. Then we suggest to do a search for the next question and find the answer only on our site.

Disclaimer :

The answers provided above are only to be used to guide the learning process. The questions above are open-ended questions, meaning that many answers are not fixed as above. I hope this article can be useful, Thank you