Skip to main content

Command Palette

Search for a command to run...

Should you stop using UUIDs?

Published
1 min readView as Markdown
Should you stop using UUIDs?
C
酷愛計算機技術Ardently Love Computer Technology 長期關註反洗錢反欺詐Long-term Focus on Anti-Money Laundering and Anti-Fraud 精通支付結算的技術、系統、流程和製度Proficient in the Technology, System, Process and Institution of Payment and Settlement

UUIDs (Guid in C#) are widely used as unique identifiers in databases. UUIDs are random, which makes them popular in distributed systems.

However, UUIDs have some drawbacks:

  1. UUIDs slow down database inserts. Each insert must update the clustered index, a B+ tree. Because UUIDs are random, this is an expensive operation as it requires rebalancing the tree

  2. Higher storage costs. A UUID is 128 bits long, and it's even longer if you store it in human-readable format as a string.

So, let me introduce you to ULIDs.

ULID attempts to solve the drawbacks of UUID. It's also 128-bit, so it's compatible with a UUID. However, unlike a UUID, ULIDs are sortable. The first 40 bits of a ULID represent a timestamp, making ULIDs monotonically increasing.

There's a .NET package that implements the ULID spec, so you can start using it immediately. However, you'll need to write some code if you want ULID to work with popular ORMs.

What do you think about ULIDs?


More from this blog

Penetration Test、Python、Weaponization

721 posts

微信 smartcat9999 反欺詐Anti-Fraud 反洗錢Anti-Money Laundering 反逃稅Anti-Tax Evasion 滲透測試Penetration Test 武器化Weaponization