Data Modeling medium
Why would you choose a UUID (GUID) as a Primary Key over an Auto-Increment Integer?
- A It allows clients to generate unique identifiers while offline and prevents the leaking of sensitive business metrics through sequential IDs.
- B UUIDs offer significantly faster b-tree traversal and index lookups due to their inherently compact, non-fragmented binary representation.
- C UUIDs consume less overall storage space on the disk as they are natively optimized by the database's internal prefix-compression algorithms.
- D UUIDs are strictly required by all modern REST and GraphQL APIs to ensure high availability and prevent cross-origin resource sharing errors.
Answer: A. It allows clients to generate unique identifiers while offline and prevents the leaking of sensitive business metrics through sequential IDs.
UUIDs are ideal for distributed systems because they can be generated independently without a central 'ID master', avoiding contention. They also hide metadata: an ID of '123' tells a competitor you have ~123 customers, while a UUID reveals nothing. Note that the trade-off is performance: UUIDs are 128-bit (vs 32/64-bit integers) and, when random, cause significant index fragmentation compared to sequential integers.
One system design question a day, with spaced repetition so the ones you miss come back.
Get the appRelated questions
- When modeling a Distributed Transaction using the Saga Pattern (Choreography or Orchestration), what type of consistency do you achieve?
- Which practice prevents SQL Injection attacks?
- What is 'Bi-Temporal' data modeling (e.g., in SQL:2011 standard)?
- Adding an Index to a database column generally improves Read performance. What is the negative trade-off?
- Log Systems Merge (LSM) Trees (used in RocksDB, Cassandra) optimize for fast writes. What is their primary downside regarding Disk I/O?
- What is the primary objective of normalizing a relational database schema (e.g., to 3NF)?