6

I noticed some people don't bother having the usual incremented number as ID but instead simply generate a GUID. The advantages include:

  • Quick and easy
  • No need to keep track of previous IDs
  • Guaranteed to be unique even across machines without knowledge of each other

Some disadvantages are:

  • Possibly performance bottleneck
  • Uses a large number of bytes

My understanding is that using a GUID is beneficial in most cases, except if optimization for time or space is an issue. Did I miss something? Or do you agree with this idea?

skaffman
  • 381,978
  • 94
  • 789
  • 754
mafu
  • 28,708
  • 38
  • 138
  • 232
  • 3
    not guaranteed to be unique, just very probable – fearofawhackplanet May 03 '10 at 11:39
  • 3
    Indeed not guaranteed, but extremely unlikely as far as I know. – mafu May 03 '10 at 11:42
  • 2
    @fearofawhackplanet, @mafutrct: See this great answer on uniqueness of the various GUID algorithms: http://stackoverflow.com/questions/703035/when-are-you-truly-forced-to-use-uuid-as-part-of-the-design/786541#786541 – Dirk Vollmar May 03 '10 at 11:56
  • 1
    Similar questions: http://stackoverflow.com/questions/829284/guid-vs-int-identity, http://stackoverflow.com/questions/1151625/int-vs-unique-identifier-for-id-field-in-database, http://stackoverflow.com/questions/1171201/sql-server-guid-vs-long – Dirk Vollmar May 03 '10 at 11:59
  • I think the proposed dup is database specific does not go into detail. This questions deals with using GUIDs in the general case rather than databases. – mafu May 03 '10 at 11:59
  • due to birthday paradox, if you generate around trilion GUIDs, there is 1% chance that you hit at least one duplicate. still unlikely but not as unlikely as some websites seem to teach on the internet. – lubos hasko May 03 '10 at 12:08
  • 10^18 (http://www.google.com/search?q=(-2+*+(2^128)*+ln(0.99))+^+0.5) but keep in mind that GUID generators are not evenly using all bits. in theory it's 10^18 but in practice could be 10^12... there are reports on the internet from people who claim to hit duplicates. it's still rare but certainly not unbelievable. – lubos hasko May 03 '10 at 12:16
  • I added a separate question on that topic: http://stackoverflow.com/questions/2757910/how-are-net-4-guids-generated – mafu May 03 '10 at 12:25

1 Answers1

1

A couple of cons:

  • Pain in the neck if you have to delve into anything manually (debuggin etc). They are completely unreadable.
  • Horrible if you ever need to pass them in a URL
vasanth
  • 695
  • 10
  • 23
UpTheCreek
  • 28,433
  • 31
  • 143
  • 214