Lesson 7 of 11
Privacy Engineering & Data Protection
Privacy engineering is the discipline of building systems that respect user privacy by design. With GDPR, CCPA, and HIPAA imposing significant fines for privacy violations, privacy can no longer be an afterthought - it must be engineered into systems from the start.
Privacy by Design Principles
# Ann Cavoukian's 7 Privacy by Design Principles
1. PROACTIVE NOT REACTIVE
Anticipate and prevent privacy violations before they occur
Privacy risk assessment before building, not after
2. PRIVACY AS THE DEFAULT
Default settings must be the most privacy-protective option
User must OPT IN to less privacy, not opt out of more privacy
GDPR: Consent must be explicit and unambiguous
3. PRIVACY EMBEDDED INTO DESIGN
Privacy controls built into the system architecture, not bolted on
Example: Data minimization at collection, not via post-processing
4. FULL FUNCTIONALITY (positive-sum)
Privacy AND security AND functionality - not one at expense of others
Reject the false trade-off: "Users want features OR privacy"
5. END-TO-END SECURITY
Protect data throughout its lifecycle: collection → processing → deletion
Define and enforce data retention periods
6. VISIBILITY AND TRANSPARENCY
Users can see what data you hold and how it's used
Audit logs for all data access - who accessed what, when
7. RESPECT FOR USER PRIVACY
User data is the user's data - you are a custodian, not an owner
Right to erasure, right to portability, right to access
# Technical implementations:
Data minimization: Only collect what you need for the stated purpose
Pseudonymization: Replace PII with tokens (store mapping separately)
Differential privacy: Add mathematical noise to query results -
prevents inference of individual records from aggregate statisticsData Protection Engineering
# Practical privacy engineering patterns
# 1. Data minimization - only collect what you use
# BAD: Collect everything, figure out use later
user_data = {
"name": ..., "email": ..., "phone": ...,
"ssn": ..., "salary": ..., "medical_history": ... # Do you NEED this?
}
# GOOD: Collect minimum necessary for the specific feature
user_data = {
"name": ..., "email": ..., # Only what's needed for registration
}
# 2. Pseudonymization - separate PII from behavioral data
# Instead of: log_event(user_id=42, action="purchase", amount=99.99)
# Use a token:
import hmac, hashlib
def pseudonymize(user_id: int, secret: bytes) -> str:
return hmac.new(secret, str(user_id).encode(), hashlib.sha256).hexdigest()
token = pseudonymize(42, app_secret)
log_event(user_token=token, action="purchase", amount=99.99)
# Analytics can be done on tokens; PII is never in logs
# 3. Data retention enforcement
# Automated deletion of personal data after defined retention periods
# PostgreSQL scheduled deletion
CREATE OR REPLACE FUNCTION delete_expired_personal_data()
RETURNS void LANGUAGE sql AS $$
DELETE FROM user_sessions WHERE created_at < NOW() - INTERVAL '30 days';
DELETE FROM email_logs WHERE created_at < NOW() - INTERVAL '90 days';
DELETE FROM audit_logs WHERE created_at < NOW() - INTERVAL '1 year';
$$;
SELECT cron.schedule('daily-retention', '0 2 * * *', 'SELECT delete_expired_personal_data()');
# 4. Right to erasure implementation
def delete_user_data(user_id: int):
# Hard delete from primary tables
db.execute("DELETE FROM users WHERE id = ?", (user_id,))
db.execute("DELETE FROM orders WHERE user_id = ?", (user_id,))
# Pseudonymize in logs (cannot delete without breaking audit trail)
db.execute("UPDATE audit_logs SET user_id = 'DELETED' WHERE user_id = ?", (user_id,))
# Notify all third-party processors to delete (GDPR Art. 17)
notify_processors(user_id, action="erasure_request")Common Mistakes
- Keeping data indefinitely 'because it might be useful' - data you don't need is liability, not an asset. Each extra data point is additional breach exposure and compliance risk
- No data flow documentation - you cannot protect what you don't know you have. Data flow diagrams showing where personal data is collected, stored, transmitted, and deleted are a prerequisite for privacy compliance
- Treating right-to-erasure as optional - GDPR Article 17 requires deletion within 30 days of verified request; non-compliance fines are up to 4% of global annual revenue
Tip
Tip
Practice Privacy Engineering Data Protection in small, isolated examples before integrating into larger projects. Breaking concepts into small experiments builds genuine understanding faster than reading alone.
The foundational security model: Confidentiality (privacy), Integrity (trust), and Availability (uptime).
Practice Task
Note
Practice Task - (1) Write a working example of Privacy Engineering Data Protection from scratch without looking at notes. (2) Modify it to handle an edge case (empty input, null value, or error state). (3) Share your solution in the Priygop community for feedback.
Quick Quiz
Common Mistake
Warning
A common mistake with Privacy Engineering Data Protection is skipping edge case testing - empty inputs, null values, and unexpected data types. Always validate boundary conditions to write robust, production-ready cybersecurity code.
Key Takeaways
- Privacy engineering is the discipline of building systems that respect user privacy by design.
- Keeping data indefinitely 'because it might be useful' - data you don't need is liability, not an asset. Each extra data point is additional breach exposure and compliance risk
- No data flow documentation - you cannot protect what you don't know you have. Data flow diagrams showing where personal data is collected, stored, transmitted, and deleted are a prerequisite for privacy compliance
- Treating right-to-erasure as optional - GDPR Article 17 requires deletion within 30 days of verified request; non-compliance fines are up to 4% of global annual revenue
Finished this lesson?