Skip to the page

Data modelling · mid

Surrogate keys, Kimball, Data Vault and one big table

Warehouses use their own surrogate keys, not source ids. Modelling methods differ in who they serve: Kimball marts for users, Data Vault for audit and many sources, one big table for fast dashboards.

The notes

What you must know

  • A surrogate key is a meaningless number owned by the warehouse. It gives one key per version in type 2, protects against reused or merged source ids, and is a small, fast join key.
  • Natural keys collide when two systems use the same ids. Use a key on source system plus natural key.
  • Generation: identity columns (Delta GENERATED ALWAYS AS IDENTITY, Snowflake sequences or AUTOINCREMENT); max(sk) + row_number() forces numbering through one partition; hash keys (sha2 or xxhash64 of source system and natural key) are deterministic, parallel and safe to rerun.
  • 64-bit hashes have a real collision risk at billions of rows, so large tables use 128 bits or more. monotonically_increasing_id() is unique in one run but not stable: a rerun gives a different key.
  • Unknown member (-1, Unknown): fact rows whose dimension row has not arrived point to it instead of being dropped by an inner join. A later job fixes them (late-arriving dimensions).
  • Kimball: star schemas per business process with conformed dimensions (the bus matrix). Best for people who query.
  • Data Vault 2.0: hubs (business keys), links (relationships), satellites (attributes with load dates and history). Insert-only, auditable, parallel loads, good for many sources. Many joins, so marts go on top.
  • One big table: a pre-joined wide table. Fast and simple for dashboards in columnar engines, but duplicates data and is hard to change. Good as a final mart, not the only layer.
  • Typical layering for many sources and strict audit: raw landing, an integration layer (Data Vault or disciplined normalised), Kimball marts and a few wide tables. A small team with five sources skips the vault.

The red pen

Common traps: mistake → fix

  • Mistake: Use the app's auto-increment id as the warehouse key

    Fix: ids can be reused, changed or collide across systems.

  • Mistake: Hash keys never collide

    Fix: 64-bit hashes can at very large sizes.

  • Mistake: Data Vault for a five-table startup

    Fix: too much overhead; match the method to the problem.

Easy to hard

Questions interviewers ask, easy to hard

  1. Why use surrogate keys instead of the app's customer id?
  2. How would you generate surrogate keys in Spark?
  3. What is the unknown member and why do you need it?
  4. Kimball, Data Vault or one big table for a bank with 40 source systems?

Explain it out loud

Explain it out loud to an AI interviewer that follows up, and see where your answer is thin.

Practise by voice

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview