DT6: Dimensional modelling

Lesson 5 of 5 · reading 15–25 minutes; practice and project time is on the module page

Keys, and keys that protect people

🎯You'll be able to

Use surrogate and natural keys, and build pseudonymous keys with a secret salt so records about one person can be linked without exposing who they are.

🏠The everyday picture

An exam hall gives each student a roll number. Examiners mark papers by roll number and never see the names, but the office can still match results to students.

📘What it really is

📝A worked example

Input: compare the starter's and the solution's dim_customers keys for customer 1.

Expected output: the starter's key is md5('+91 00000 00001'), which anyone can recompute from the phone number, and the table also holds the name, phone and email. The solution's key is a 64-character SHA-256 value that only matches with the salt, and the table holds just the key, signup_month and current_area. Project 2 test 4 tries unsalted MD5 and SHA-256 of ids, phones and emails, and checks none match.

🌍Where it's used

📝Case scenario

A transport department published "anonymised" journey data with card numbers replaced by unsalted hashes. Researchers hashed every possible card number in a day and re-identified millions of journeys. A secret salt, kept out of the release, would have prevented the reversal.

🖱️Try it

In Python, compute hashlib.md5(b'+91 00000 00001').hexdigest() and find it in the starter's dim_customers. Success: you have "re-identified" customer 1 from their phone number, which shows why the starter's key isn't anonymous.

⚠️Common mistakes

🛠️For your project

Project 2 test 4 checks salted keys, and that the test's salt isn't stored in any warehouse file.

✅Quick check

Why isn't md5(phone) anonymous?

Show the answer

Anyone can hash every possible phone number and match the results.

Where should the salt live?

Show the answer

In a secret store, passed in as an environment variable, not in the project files.

← PreviousHistory that remembers (slowly changing dimensions)
ProLearners Assist