The GDPR Engineer embeds data privacy into systems from the start. Privacy-by-design is not a checklist - it is an architecture discipline that minimises what data is collected, limits who can access it, and makes it technically possible to delete it. The most expensive GDPR problems are discovered after launch when deletion requires restructuring a data model built around user IDs as foreign keys in dozens of tables.
Lawful Basis Summary
| Basis | When to use | Withdrawal? |
|---|---|---|
| Contract | Data needed to fulfil a service the user requested (e.g., account email) | Only by cancelling service |
| Legitimate interest | Business purpose that doesn't override user rights (e.g., fraud prevention, analytics) | User can object; must honour |
| Consent | Marketing emails, non-essential cookies, any optional data processing | Must be as easy to withdraw as to give |
| Legal obligation | Tax records, court orders | No - legally required |
| Vital interests | Emergencies involving life or safety | Rare |
Right to Erasure (Article 17)
// The technical challenge: user data is scattered across many tables
// Design principle: use a single user_id FK everywhere, then delete can cascade
// Step 1: Map all tables that contain user data
const USER_DATA_LOCATIONS = [
'users',
'sessions',
'orders',
'reviews',
'uploads',
'notifications',
'audit_logs', // Exception: some audit logs must be kept for legal obligation
'analytics_events',
];
// Step 2: Build a deletion job (run async - may take minutes for large accounts)
async function handleErasureRequest(userId: string) {
await db.transaction(async (tx) => {
// Anonymise rather than delete where referential integrity requires it
// e.g., orders reference products; delete personal data but keep the order record
await tx.execute(`
UPDATE orders
SET shipping_address = '[redacted]', customer_name = '[redacted]', customer_email = '[redacted]'
WHERE user_id = ${userId}
`);
// Hard delete where no business need to retain
await tx.delete(sessions).where(eq(sessions.userId, userId));
await tx.delete(notifications).where(eq(notifications.userId, userId));
await tx.delete(uploads).where(eq(uploads.userId, userId));
// Finally delete the user record
await tx.delete(users).where(eq(users.id, userId));
});
// Also delete from external services
await intercom.deleteUser(userId);
await stripe.deleteCustomer(stripeCustomerId);
await analyticsService.deleteUser(userId);
// Log the deletion for your own records (without PII)
await db.insert(deletionLog).values({
requestId: crypto.randomUUID(),
deletedAt: new Date(),
// Store only what's needed: no user ID (that's PII too), just a record of compliance
});
}
Data Retention Policy
## Standard retention schedule (document in privacy policy)
User account data: Retained while account is active + 30 days grace period
Session / authentication: 30 days
Analytics events: 2 years (aggregate only after 1 year)
Financial / payment data: 7 years (legal obligation - tax records)
Support tickets: 3 years
Audit logs: 1 year (legal obligation varies by jurisdiction)
Marketing preferences: Until consent withdrawn
Automated deletion:
- Run a nightly cron job that deletes records past their retention date
- Test deletion job in staging with seeded expired data before prod deployment