Database design PKID vs GUID

This is an old school debate, actually some people believe GUID is better some have opposite idea. However, each has its own pros and cons which I have listed as much as I could,

PKID advantages

  • Easy to remember
  • Incremental and therefore query speed is faster
  • Causes less fragmentation in database
  • It is following particular pattern
  • Uses less storage

PKID disadvantages

  • In the case of removing rows causes fragmentation in db
  • Make syncing process impossible (causes duplicate keys issue)

GUID advantages

  • Can do syncing flawlessly
  • Allows merging different tables and databases
  • Easy to generate and no need to be worry about sequence

GUID disadvantages

  • Causes slower query and sometimes time out (Performance issue)
  • Causes fragmentation in db
  • Takes more storage which sometimes cumbersome
  • Difficult to remember and debug
  • Values do not follow any sequence or order

The final conclusion is the usage of each depends on the situation and the purpose of your application. For instance, if you want to do data syncing or distributed database and/or merging for sure you have to use GUID, otherwise, my recommendation is stick to PKID as it is easier to maintenance and it is more efficient in terms of performance.

Send your idea and information to kasra@madadipouya.com

Leave a Reply