Mask and Tokenize PII Before Loading Records Into an Analytics Zone
Last updated: November 29, 2026
Quick Overview
Write a function that applies per-field masking rules to records before they leave a secure zone: drop some fields, keep the last four digits of SSNs, keep only the email domain, and replace member ids with deterministic tokens so joins still work.
Deloitte
November 29, 20260
0
0 solved
Write a function that applies per-field masking rules to records before they leave a secure zone: drop some fields, keep the last four digits of SSNs, keep only the email domain, and replace member ids with deterministic tokens so joins still work.
Deloitte data engineers on public sector and healthcare engagements constantly move data containing PII between zones with different access rules. This screen checks basic secure engineering judgment: why hashing alone is weak, why tokens must be deterministic, and how to fail safely on bad input.
What the Interviewer Expects
- Uses a keyed HMAC, not a plain hash, for tokenization
- Keeps tokens deterministic so analysts can still join datasets
- Normalizes values before tokenizing
- Fails safe on unknown rules and malformed values
- Keeps the key out of code (secrets manager, rotation)
- Explains masking versus encryption versus tokenization
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- Why is SHA-256 of an SSN without a key nearly as bad as the raw SSN?
- How would you rotate the tokenization key without breaking historical joins?
- When would you prefer reversible tokenization with a vault?
- How would you test that no PII leaks through free-text fields?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Input: a record dict, a rules dict field -> rule, and a secret key. Rules: keep, drop, tokenize, ssn_last4, email_domain. Unknown rules must raise, so a typo in configuration cannot silent...
High-Level Design
Plain hashing is weak because an SSN has only about a billion possible values; an attacker can hash them all in minutes. A keyed HMAC-SHA256 with a secret held in a secrets manager makes that infeasib...