Skip to content
Tutorials Center
My learning

Topics

Lesson 63 of 80 ยท Privacy, Cloud and Secure Design

Privacy and Data Protection

Understand personal data, GDPR and CCPA principles, data minimization, retention, and the difference between pseudonymization and anonymization with demos.

Security protects data from people who should not see it. Privacy asks a wider question: should we have collected this data at all, what may we do with it, and what rights do the people it describes have? The two are linked. You cannot have privacy without security, but a perfectly secured database that holds data you never needed is still a liability, and a breach of it will hurt real people.

In this lesson you will learn what counts as personal data, the main principles of laws such as the EU GDPR and California's CCPA, how to practice data minimization and retention, and why pseudonymization is not the same as anonymization. The demos run on invented records.

This lesson explains concepts for engineers. It is not legal advice. Laws differ by country and change over time, so involve your privacy officer or legal counsel for real decisions.

What is personal data?

Personal data (the GDPR term; US laws often say personal information) is any information relating to an identified or identifiable person. It is broader than names and addresses:

  • Direct identifiers: name, email address, phone number, government ID number.
  • Indirect identifiers that identify someone when combined or looked up: IP address, device ID, cookie ID, precise location, employee number.
  • Information about a person: purchase history, browsing activity, photos, voice recordings, salary.
  • Special categories (sensitive data) that carry higher protection and stricter rules: health, genetic and biometric data, racial or ethnic origin, political opinions, religious belief, union membership, sexual orientation. US state laws define similar "sensitive" classes, which also often include precise geolocation and children's data.

If a record could be linked back to a person by anyone with reasonable means, treat it as personal data.

The big laws in one picture

Many countries have privacy laws. Two widely cited examples show the common structure.

GDPR (EU/EEA) CCPA/CPRA (California, USA)
Scope Any organization handling personal data of people in the EU, wherever the organization is For-profit businesses meeting size or data thresholds, handling California residents' data
Lawful basis needed? Yes: consent, contract, legal obligation, vital interests, public task or legitimate interests No general requirement; focuses on notice and opt-outs
Core rights Access, rectification, erasure, restriction, portability, objection Know, delete, correct, opt out of sale or sharing, limit use of sensitive data
Breach rule Notify the authority within 72 hours of becoming aware (if risk to people) State breach laws and a private right of action for certain breaches
Penalties Up to 20 million euros or 4% of worldwide annual turnover, whichever is higher Civil penalties per violation, enforced by the state

Other laws you may meet include Brazil's LGPD, India's DPDP Act, and sector rules such as HIPAA (US health data) and PCI DSS (card data, see Compliance and Security Frameworks).

The principles behind the rules

GDPR spells out seven principles that nearly every modern privacy law echoes in some form:

  1. Lawfulness, fairness and transparency. Have a valid reason, do not mislead, and explain clearly what you do (a readable privacy notice).
  2. Purpose limitation. Collect for specified, legitimate purposes and do not reuse the data for incompatible ones.
  3. Data minimization. Collect only what is adequate, relevant and necessary.
  4. Accuracy. Keep data correct and fix errors.
  5. Storage limitation. Keep it no longer than needed.
  6. Integrity and confidentiality. Protect it with appropriate security: this is where this whole course applies.
  7. Accountability. Be able to demonstrate compliance with records, assessments and policies.
flowchart LR
    C["Collect<br/>only what is needed"] --> U["Use<br/>for the stated purpose"]
    U --> S["Store and protect<br/>(encrypt, restrict access)"]
    S --> SH["Share<br/>only with a reason"]
    SH --> R["Retain<br/>until the retention limit"]
    R --> D["Delete or<br/>anonymize"]

The data lifecycle: each step needs a reason, a control and an owner.

Privacy by design

Privacy by design means building privacy in from the start, as a default, not as an afterthought. Concretely: ask whether a field is needed before adding it to a form, make the private option the default, give users control, log access to sensitive records, and run a data protection impact assessment (DPIA) before launching something high-risk such as large-scale profiling. This connects to Secure Architecture and Design Patterns.

Data minimization in practice

The cheapest data to protect is data you do not hold. Before collecting a field ask: what is it for, who uses it, and what would break without it? A newsletter signup needs an email address, not a birthday and a phone number. Minimization also applies to access: most staff do not need to see full records, which is the principle of least privilege from The CIA Triad and Core Principles.

A common technique is masking: showing only as much of a value as the task needs. A support agent verifying a caller might see the last four digits of a phone number, not the whole thing. Logs, error messages and analytics are common places where personal data leaks by accident (see Secrets, Logging and Error Handling).

Python Mask personal data before it reaches logs or support screens

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Masking hides data from viewers. It is not the same as protecting it at rest: the underlying value still exists, so it also needs encryption and access control.

Retention and deletion

Storage limitation means each type of data gets a retention period with a reason (a legal duty to keep invoices for several years, but no reason to keep a rejected job application forever). Then something must actually enforce it: a scheduled job that deletes or anonymizes expired records, including copies in backups and analytics systems. "We keep everything just in case" is the opposite of the principle, and it enlarges every future breach.

Python Find records past their retention period

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Don't forget the other half of the loop: the right to erasure and similar rights mean you must be able to find all of one person's data across databases, files, logs, exports and backups. That is much easier if you know where personal data lives (a data inventory) and if it is linked by a stable key.

Pseudonymization versus anonymization

These two words are often confused, and the difference has legal weight.

  • Pseudonymization replaces direct identifiers with a token or code, but a way to link it back to the person still exists (a lookup table, a secret key). The data is still personal data under GDPR. It reduces risk and is encouraged, but obligations remain.
  • Anonymization changes data so that people can no longer be identified by any means reasonably likely to be used, by anyone, including you. Properly anonymized data falls outside GDPR. This is hard to achieve, and often overclaimed.

How you pseudonymize matters. A plain hash of an email address looks protective but is not: anyone can hash a list of guessed addresses and compare. A keyed hash (HMAC) with a secret key stored elsewhere is much better, because without the key the mapping cannot be recomputed. See HMAC and Message Authentication.

Python Plain hash vs keyed pseudonym

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Pseudonyms stay stable for the same input, which is useful for analytics joins, but that stability is also a linkability risk. Rotate or separate keys per purpose if records from different systems should not be joined.

Why anonymization is hard

Removing names is rarely enough. Combinations of ordinary attributes (postcode, birth year, gender) can single out a person, especially when matched with another dataset such as a public register. k-anonymity is a simple measure: each combination of identifying attributes must appear in at least k records. You raise k by generalizing values (exact age to an age band, full postcode to its first digits) or by suppressing rare rows.

Python Measure and improve k-anonymity

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Generalizing alone merged most rows but left two people alone in their group (k was still 1), so the last step suppressed those rows and reached k = 2 at the cost of two records. The trade-off is visible: the safer the data, the less detail an analyst keeps. Even k-anonymity has weaknesses (if everyone in a group shares the same diagnosis, an attacker still learns it), which is why stronger ideas such as differential privacy exist for statistics on sensitive data. When in doubt, call data "pseudonymized" and protect it like personal data.

Rights requests and breaches

Prepare a repeatable process for data subject requests: verify the requester's identity, locate their data in every system, respond within the legal deadline (one month under GDPR, with limited extensions), and record what you did. Prepare for breaches too: they are security incidents with legal clocks, so your incident response plan should include who decides whether regulators and individuals must be notified.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. Which of the following is personal data under GDPR?

    The definition is broad: direct and indirect identifiers both count, and so does information about a person that can be linked to them.
  2. 2. What does the data minimization principle require?

    Minimization is about not collecting or exposing more than a stated purpose needs, which also reduces the impact of any breach.
  3. 3. A table stores SHA-256 hashes of email addresses as 'anonymous' IDs. What is the problem?

    Unkeyed hashes of guessable values can be re-identified by guessing. A secret key helps, and even then the data remains personal data if re-linking is possible.
  4. 4. What is the legal difference between pseudonymized and anonymized data under GDPR?

    If the data can be linked back to a person with additional information, it stays in scope of the law. Only data that cannot reasonably be re-identified is outside it.
  5. 5. In the k-anonymity demo, what does generalizing an exact age to a ten-year band achieve?

    Coarser values make more people look alike, so each group contains more records and singling out an individual gets harder.

Summary

  • Personal data is anything relating to an identifiable person, including IP addresses and device IDs; special categories need extra care.
  • GDPR and CCPA differ in details, but share themes: transparency, purpose limitation, minimization, retention limits, security, accountability and rights for individuals.
  • Collect less, mask what viewers see, and delete on a schedule that you actually enforce, including copies and backups.
  • Pseudonymized data is still personal data. Use keyed hashes rather than plain hashes, and treat anonymization claims with skepticism; k-anonymity is a simple way to measure re-identification risk.
  • Plan for rights requests and breach notification before they happen.

Next: Secure Architecture and Design Patterns, where privacy and security are built into the design from the start.