Skip to content

PII in Data Pipelines: Masking, Hashing and Tokenization

Data flowing through a shield into a table with sensitive fields covered.

Personal data in a pipeline is a risk that grows quietly. Every copy of a customer’s email or phone number that lands in a warehouse, a backup or an analyst’s extract is another place it can leak. Masking, hashing and tokenization are the main ways to reduce what a pipeline exposes, and they are not interchangeable.

What counts as PII

PII, or personally identifiable information, is data that can identify a person directly, such as a name, email address, phone number or government ID, or indirectly when combined with other fields, such as a date of birth plus a postcode. What legally counts as personal data depends on the jurisdiction, so treat this post as an engineering overview, not legal advice, and check the rules that apply to you.

Start by not collecting it

The cheapest protection is data minimization: do not ingest fields you do not need. If an analysis only needs the customer’s country, do not carry their full address through the pipeline. Fields that never enter the system cannot leak from it.

Masking

Masking replaces sensitive values with fake or partial ones, such as showing only the last four digits of a card number, or replacing a name with a placeholder. It is useful for test data and for views shown to people who do not need the real values. Masking alone is often one-way, so it suits cases where nobody needs the original back.

Hashing

Hashing turns a value into a fixed-length string that cannot be reversed directly. It is handy for joining records across tables without exposing the raw value, because the same input always gives the same hash. The weakness is that values with few possibilities, such as phone numbers or small ID ranges, can be recovered by hashing every candidate and comparing. Adding a secret salt or using a keyed hash makes that guessing attack much harder.

Tokenization

Tokenization replaces a sensitive value with a random token and keeps the mapping between them in a separate, tightly controlled store. Analysts work with tokens, and only the systems allowed to access the store can turn a token back into the real value. It keeps joins possible and keeps the sensitive data out of the analytics environment.

Encryption

Encryption makes data unreadable without a key and is reversible by anyone who holds the key. It protects data at rest and in transit, but a decrypted analytics table is exposed again, so encryption is a base layer and does not replace masking or tokenization for data that analysts query.

Pseudonymization is not anonymization

Replacing names with tokens or hashes is pseudonymization: the data can still be linked back to a person by someone with the extra information or enough effort, so it generally remains personal data. Anonymization means the data can no longer be tied to an individual, which is a much higher bar and is easy to get wrong when other columns still identify people. Be cautious about calling a dataset anonymous.

Where in the pipeline to protect it

If the destination should never hold raw values, mask or tokenize before loading. That is one of the cases where transforming first beats loading raw data, as discussed in ETL vs ELT. If you do load raw data, confine it to a restricted layer, in the way described in medallion architecture, and expose only the protected versions to analysts.

Keep track of where it flows

You cannot protect or delete data you cannot find. Data lineage shows which tables a sensitive column flows into, and a data contract can label which fields are sensitive and how they must be handled. Also set retention rules, so data is deleted when it is no longer needed, and restrict access by role. When choosing where the data lives, the platform questions in warehouse vs lake vs lakehouse include what access controls each offers.

A quick checklist

  1. Do you actually need each personal field you are ingesting?
  2. Is sensitive data masked or tokenized before it reaches analysts?
  3. Are hashes of low-variety values protected with a secret salt or key?
  4. Do you know which tables each sensitive column flows into?
  5. Are retention and access rules defined and enforced?

If you want a pipeline designed with these controls, see my ETL and ELT engineering service.

FAQ

What is the difference between masking and tokenization?
Masking replaces a value with a fake or partial one and is usually irreversible. Tokenization replaces it with a token and keeps a protected mapping, so authorized systems can reverse it.

Is hashing enough to protect personal data?
Not always. Hashes of values with few possibilities can be guessed, so use a secret salt or keyed hash, and remember that hashed data is usually still considered personal data.

Is pseudonymized data still personal data?
Generally yes, because it can be linked back to a person with additional information. Check the rules that apply to your situation.

Related posts

Leave a comment

Your email address will not be published. Required fields are marked *