GDPR and privacy for engineers
A practical engineering view of personal data: lawful basis, minimisation, consent, user rights and breaches.
In 30 seconds
The GDPR is the EU law that governs how organisations collect and use personal data about people in the EU. For engineers it boils down to a few habits: know what personal data you hold and why, collect less, protect it well, let people see, export and delete their data, and report breaches fast. This lesson is a practical engineering guide, not legal advice: for real decisions, involve a lawyer or your data protection officer.
Not in my daily stack — I know the concepts and would learn the details when a project needs it.
Why it matters
- It applies far beyond Europe: any product that offers goods or services to people in the EU, or monitors their behaviour, falls under it.
- Fines can reach €20 million or 4% of worldwide annual turnover, whichever is higher, and regulators actively enforce it.
- Most compliance work is engineering work: data models, retention jobs, access control, logging, export and deletion features.
- Privacy built in early is cheap; retrofitting deletion and consent into a mature system is slow and risky.
How it works
01What counts as personal data
Personal data is any information relating to an identified or identifiable living person. Names and emails are obvious. Less obvious: IP addresses, device IDs, cookie IDs, order histories, location points, voice recordings and support chat logs. If you can link it back to a person, alone or combined with other data you could reasonably get, it counts. Some categories are 'special' and need stronger justification: health, biometric data used for identification, religion, political opinions, sexual orientation, trade-union membership, racial or ethnic origin, genetic data. Pseudonymised data, such as a user ID in an analytics table, is still personal data because you can re-identify it. Only truly anonymised data, where re-identification is not reasonably possible, falls outside the law, and real anonymisation is harder than it looks.
- Controller: decides why and how data is processed (usually your client or company).
- Processor: processes data on the controller's behalf (your hosting, email or analytics vendor).
- Data subject: the person the data is about.
02The principles, translated into engineering
Article 5 lists the principles every system must follow, and each maps to concrete design choices. Lawfulness, fairness and transparency: a valid reason for each use, explained in a privacy notice. Purpose limitation: data collected for delivery is not silently reused for unrelated profiling. Data minimisation: do not collect a birth date if you only need to know the user is an adult. Accuracy: let users correct their data. Storage limitation: delete or anonymise data when its purpose ends, with automatic retention jobs. Integrity and confidentiality: encryption, access control, logging. Accountability: be able to show what you do, through documentation, records and audit trails. Article 25 adds 'data protection by design and by default': the most private option should be the default setting.
03Lawful bases and consent done right
Every processing activity needs one of six lawful bases: consent, contract, legal obligation, vital interests, public task or legitimate interests. Engineers often assume consent is always needed; it is not. Processing an order uses 'contract'. Keeping invoices uses 'legal obligation'. Fraud prevention often uses 'legitimate interests' after a balancing test. Consent is right for optional things such as marketing emails or non-essential tracking, and it must be freely given, specific, informed and unambiguous: no pre-ticked boxes, no 'by using this site you agree'. It must be as easy to withdraw as to give. For cookies and similar storage on a device, the separate ePrivacy rules require consent for anything not strictly necessary, so analytics and advertising cookies wait until the user agrees.
-- Store consent as an auditable event, never as a single boolean
CREATE TABLE consent_events (
id BIGSERIAL PRIMARY KEY,
user_id BIGINT NOT NULL REFERENCES users(id),
purpose TEXT NOT NULL, -- 'marketing_email', 'analytics'
granted BOOLEAN NOT NULL, -- true = given, false = withdrawn
notice_version TEXT NOT NULL, -- which privacy text the user saw
source TEXT NOT NULL, -- 'signup_form', 'settings_page'
created_at TIMESTAMPTZ NOT NULL DEFAULT now()
);
-- Current state = latest event per (user_id, purpose)
04Building data subject rights into the product
People have rights you must be able to honour, usually within one month (extendable by two further months for complex requests). Access: give them a copy of their data and information about how it is used. Rectification: let them fix inaccurate data. Erasure (the 'right to be forgotten'): delete data when there is no longer a valid reason to keep it, while retaining what a law requires, such as invoices. Portability: provide data they gave you in a structured, machine-readable format like JSON or CSV. Objection and restriction: stop certain processing, such as direct marketing, on request. Engineering-wise, this means a data map that knows every table, bucket, log and third party holding a user's data, plus tested export and deletion jobs. Verify the requester's identity first, so the access feature does not become a data leak.
- Self-service export and delete in account settings reduce support load.
- Deletion must reach backups, search indexes, caches and processors on a known schedule.
- Log each request and its completion for accountability.
05Security, breaches and the 72-hour clock
The GDPR requires 'appropriate technical and organisational measures' for security, judged by risk. Typical expectations: encryption in transit (TLS) and at rest, least-privilege access, multi-factor authentication for staff, audit logs on access to personal data, secure development practices and tested backups. A personal data breach is any security incident leading to accidental or unlawful destruction, loss, alteration, disclosure of or access to personal data, not only hacks: an email to the wrong recipient counts. The controller must notify the supervisory authority within 72 hours of becoming aware of it, unless it is unlikely to result in a risk to people, and must inform affected people directly when the risk is high. Processors must tell the controller without undue delay. Every breach, even unreported ones, must be documented internally.
06Vendors, transfers and paperwork that matters
Each vendor that processes personal data for you, such as hosting, email delivery, analytics or error tracking, is a processor and needs a data processing agreement (Article 28). Keep a list of them; it doubles as your sub-processor list for customers. Sending personal data outside the European Economic Area requires a transfer mechanism: an adequacy decision (including the EU-US Data Privacy Framework for certified US companies), standard contractual clauses, or another Chapter V tool. Organisations must keep records of processing activities (Article 30), and high-risk processing such as large-scale monitoring or sensitive data needs a data protection impact assessment (Article 35) before launch. Engineers rarely write these documents, but they supply the facts: what is collected, where it is stored, who can access it and for how long.
Use it when
- Any product with users, customers, employees or visitors in the EU or EEA.
- When designing new features that collect, combine or share personal data.
- When choosing analytics, email, AI or hosting vendors that will see user data.
- When a customer's security questionnaire asks about data handling and sub-processors.
Skip it when
- Truly anonymous, aggregated data that cannot reasonably be linked back to people (verify this carefully).
- As a substitute for legal advice: national laws, sector rules and recent guidance change the details.
- Treating a cookie banner as 'GDPR done'; it covers one narrow ePrivacy question.
Alternatives
- UK GDPR and Data Protection Act 2018
Near-identical regime for the UK, with its own regulator (ICO) and transfer rules.
- US state laws (for example CCPA/CPRA)
Rights-based but different: opt-out of sale or sharing, different definitions and thresholds.
- ISO/IEC 27701
A privacy management standard that extends ISO 27001; helps organise and certify the practice.
- Privacy-preserving analytics
Cookieless, aggregated tools can remove the need for consent for basic metrics, depending on configuration.
Best practices
- Keep a data map: every personal field, where it lives, why, its lawful basis and retention period.
- Collect the minimum and make the private choice the default setting.
- Store consent as versioned events, and block non-essential trackers until consent is given.
- Automate retention: scheduled jobs that delete or anonymise expired data, with logs.
- Pseudonymise analytics and keep identifiers out of logs and URLs.
- Build tested self-service export and deletion that reaches every store and processor.
- Write and rehearse a breach runbook with a named owner and the 72-hour clock.
Common mistakes
- Assuming everything needs consent, or that consent fixes everything.
- Logging full request bodies with emails, phone numbers, tokens or card data.
- Soft-deleting users forever and calling it erasure.
- Copying production data into staging and developer laptops without masking.
- Adding a third-party script or SDK without checking what data it collects and sends.
Deep dive
07Privacy by design in the data model
Design the schema so privacy is easy. Separate identity data (name, email, phone, address) from behavioural data (orders, events), joined by an internal ID, so analytics and exports can work on the behavioural side without identity fields. Mark personal columns in code or schema comments so tooling can find them. Add retention metadata: a created date, a purpose and an expiry rule per table. Use field-level encryption for highly sensitive values, with keys managed outside the database. Keep audit tables of who accessed or changed personal data, especially from admin panels. When a user is deleted, the design should make it a few well-defined operations rather than a hunt across the codebase.
// Retention job: anonymise inactive guest orders after the retention period
await db.order.updateMany({
where: {
userId: null,
createdAt: { lt: subMonths(new Date(), RETENTION_MONTHS) },
anonymisedAt: null,
},
data: {
guestEmail: null,
guestPhone: null,
shippingAddress: null,
anonymisedAt: new Date(),
},
});
08Logs, observability and AI tools
Logs are the most common hidden store of personal data. Request logs capture emails, tokens and IP addresses; error trackers capture form payloads; session replay tools can record everything typed. Configure scrubbing at the source: allow-list fields rather than block-list, mask query strings, and set short retention for raw logs. Treat observability vendors as processors with agreements and regions you chose. The same applies to AI services: sending support tickets or user documents to a large language model API is a transfer to a processor, so check the vendor's data processing terms, retention, training use and region, and strip identifiers when the task does not need them.
09International transfers in practice
Chapter V restricts transfers of personal data outside the EEA. The cleanest route is an adequacy decision: the EU has recognised countries such as the UK, Switzerland, Japan and South Korea, and the EU-US Data Privacy Framework covers US companies that self-certify; it survived a first court challenge at the EU General Court in 2025, though further appeals are possible. Otherwise, standard contractual clauses plus a transfer impact assessment are the usual tool. Engineering choices reduce the problem: choose EU regions for primary storage, check where support and sub-processors access data from, and avoid sending raw personal data to tools that do not need it. Keep the vendor and region list current, because customers will ask.
10Change is coming: keep an eye on reforms
Privacy law is not static. In November 2025 the European Commission proposed a 'Digital Omnibus' package that would amend parts of the GDPR and the cookie rules; at the time of writing (November 2026) the data-protection part is still being negotiated by the Parliament and Council, so the current GDPR text applies unchanged. National regulators also publish guidance that shifts practice, for example on cookie banners, pseudonymisation and legitimate interests. As an engineer, build systems that are easy to adapt: configurable retention periods, purpose-tagged consent, a central data map and feature flags around trackers. When the rules change, you then adjust settings rather than rebuild.
Real-world scenarios
A user asks: send me all my data
Problem
A customer emails support asking for a copy of all their personal data. The data is spread across the main database, a mailing tool, a helpdesk and analytics. Nobody knows where to start.
How to solve it
Verify identity through the logged-in account or a confirmation email to the registered address. Use the data map to collect everything: profile, addresses, orders, consent history, support tickets, mailing list status and the purposes and recipients involved. Produce a structured export (JSON or CSV in a zip) plus a short human-readable cover note. Deliver it securely, for example a time-limited download link in the account. Log the request date and completion; the deadline is one month. Then turn the manual steps into a self-service export so the next request costs nothing.
Marketing wants a new tracking pixel
Problem
The marketing team asks to add an advertising pixel to every page, including checkout, to measure campaign conversions. It goes live tomorrow.
How to solve it
Check what the pixel collects and sends: URLs, purchase values, hashed emails, device IDs. Advertising tracking needs opt-in consent, so load it only through the consent manager under the advertising purpose, never by default. Keep it off sensitive pages or strip query parameters that could carry personal data. Ensure the vendor terms cover data processing and transfers. Update the privacy notice and cookie list. Offer marketing a server-side, aggregated conversion option for users who decline. Ship it behind a feature flag so it can be removed quickly if needed.
A leaked database dump on a staging server
Problem
An engineer discovers that a staging server has been publicly reachable for two weeks with a copy of production data, including names, emails and order history.
How to solve it
Contain: close public access immediately, preserve access logs and snapshot the server for investigation. Notify the person responsible for privacy at once; the 72-hour clock starts when the organisation becomes aware. Check logs to see whether anyone actually downloaded the data and how many people are affected. Prepare the notification to the supervisory authority and, if risk is high, to affected users. Then fix the root cause: no unmasked production data in staging, masked seed scripts, private networking and an automated check for public endpoints.
Cheat sheet
- Breach notification to regulator
Within 72 hours of awareness (Art. 33), unless unlikely to risk people's rights- Respond to a rights request
Within 1 month; extend by 2 more for complex cases, telling the person why- Maximum fine (top tier)
€20M or 4% of worldwide annual turnover, whichever is higher- Six lawful bases (Art. 6)
Consent, contract, legal obligation, vital interests, public task, legitimate interests- Vendor processing data for you
Signed data processing agreement (Art. 28) + sub-processor list- High-risk new processing
Run a DPIA (Art. 35) before launch- Strip PII from logs
Allow-list logged fields; mask email, phone, tokens, card data; short retention- Non-essential cookies
Load only after opt-in; 'Reject' as easy as 'Accept'- Transfers outside the EEA
Adequacy decision (incl. EU-US DPF) or standard contractual clauses + TIA
Questions & answers
Q1Does GDPR apply to a company outside the EU?
Often yes. Article 3 applies the regulation to organisations established in the EU, and also to organisations outside it that offer goods or services to people in the EU or monitor their behaviour there, for example through tracking and profiling. Signs of targeting include EU languages and currencies, EU shipping or EU-focused marketing. A non-EU company caught by this usually also needs an EU representative. Merely having a website reachable from Europe is not enough by itself. For a definitive answer about a particular business, ask a qualified lawyer; this is the general engineering understanding, not legal advice.
Q2Do we always need consent to process personal data?
No. Consent is one of six lawful bases. Handling an order or running an account uses 'performance of a contract'. Keeping tax records uses 'legal obligation'. Security monitoring and fraud prevention often rely on 'legitimate interests', which requires a documented balancing test showing your interest is not overridden by the person's rights. Consent fits optional processing: marketing emails, non-essential cookies, optional profiling. Choosing consent where it does not fit is a trap, because people can withdraw it at any time, and then you must stop. Pick the basis per purpose, document it, and mention it in the privacy notice.
Q3How do you implement the right to erasure in a real system?
Start from a data map listing every place a user's data lives: main database tables, file storage, search indexes, caches, analytics, logs, backups and third-party processors. Build a deletion workflow that hard-deletes or anonymises each item, keeping only what a law requires, such as invoices, possibly with reduced fields. Use a job queue so it is retryable and logged. For processors, call their deletion APIs or document their retention. For backups, accept that data ages out on the backup schedule and make sure restores re-apply deletions. Verify identity before acting and record completion within the one-month deadline.
Q4What is the difference between anonymisation and pseudonymisation?
Pseudonymisation replaces direct identifiers with a key, such as a user ID or a hash, while the means to re-identify still exist somewhere. It is a good security measure that the GDPR encourages, but the data remains personal data and all the rules still apply. Anonymisation means the data can no longer be linked to a person by any means reasonably likely to be used, so it falls outside the GDPR. True anonymisation is hard: combinations of postcode, birth date and gender, or detailed location trails, can re-identify people. Aggregation, generalisation and removing rare values help, but test the result against realistic re-identification attempts.
Q5What happens in the first hours after a data breach?
Contain first: revoke leaked keys, close the hole, preserve logs and evidence. Start the clock: the controller has 72 hours from becoming aware to notify the supervisory authority, unless the breach is unlikely to result in a risk to people. Assess scope quickly: which data, how many people, whether it was encrypted, whether it was actually accessed. If you are a processor, inform the controller without undue delay. If the risk to people is high, they must be told directly, with clear advice such as resetting passwords. Document everything, including decisions not to notify. A rehearsed runbook makes those hours calm instead of chaotic.
Q6How should we handle cookies and analytics?
Under the ePrivacy rules, storing or reading information on a user's device needs consent unless it is strictly necessary for the service the user asked for, such as a session cookie or a cart cookie. Analytics and advertising cookies normally need opt-in consent before they load. That means a real choice with 'reject' as easy as 'accept', no pre-ticked boxes, and scripts that do not fire until consent exists. Record consent and honour withdrawal. Some regulators accept narrowly configured, privacy-friendly audience measurement without consent, under strict conditions; check the guidance in your target countries before relying on that.
Senior-level questions
S1How would you make a multi-service platform able to honour erasure reliably?
Treat erasure as a distributed workflow, not a SQL statement. Each service registers the personal data it owns in a central data map. A deletion request becomes an event, such as 'user.erasure_requested', consumed by every service, each of which deletes or anonymises its own data and emits a completion event. An orchestrator tracks completion with deadlines and retries, and escalates stuck services. Third-party processors get API calls or tickets, also tracked. Legal-hold data, such as invoices, is minimised rather than deleted. Backups expire on schedule, and restore procedures replay the erasure log. The trade-off is complexity versus certainty; the reward is that you can prove completion to a regulator.
S2Legitimate interests or consent for product analytics?
It depends on the method and on the separate ePrivacy rules. If analytics reads or writes device storage (cookies, local storage, device IDs) for non-essential purposes, ePrivacy usually requires consent regardless of the GDPR basis. If you use server-side, aggregated, first-party metrics with no cross-site tracking and short retention, some regulators accept it without consent, and legitimate interests may cover the GDPR side after a documented balancing test. Consent gives a clearer legal footing but loses data from people who decline, which skews metrics. Many teams combine a minimal, privacy-friendly baseline for everyone with richer, consent-based analytics. Check the guidance of the regulators in your key markets and document the decision.
S3How do you keep production personal data out of non-production environments?
Default to synthetic data: seed scripts and factories that create realistic fake users, orders and edge cases. When production-shaped data is truly needed, for example to reproduce a performance issue, run a masking pipeline that replaces names, emails, phones and addresses with consistent fakes, shifts dates, and removes free-text fields, before the data leaves production. Restrict who can run it, log each run, and give the copy a short expiry. Block direct production database access from developer machines. The trade-off is fidelity: masked data can hide bugs that depend on real distributions, so keep a few documented, approved exceptions instead of an informal habit of copying dumps.
Glossary
- Personal data
- Any information about an identified or identifiable living person, including IDs, IP addresses and behaviour linked to them.
- Controller
- The organisation that decides why and how personal data is processed, and carries the main legal responsibility.
- Processor
- A service provider that processes personal data on the controller's instructions, such as a hosting or email vendor.
- Lawful basis
- One of six legal reasons that make a specific use of personal data allowed, such as contract or consent.
- Data minimisation
- Collecting and keeping only the personal data that is actually needed for the stated purpose.
- Pseudonymisation
- Replacing direct identifiers with keys; still personal data, but safer because identities are separated.
- DPIA
- Data protection impact assessment: a documented risk analysis required before high-risk processing starts.
- DSAR
- Data subject access request: a person asking for a copy of their data and how it is used.
- DPO
- Data protection officer: an independent role advising on and monitoring compliance, required for some organisations.
Keep learning
Have a product in mind?Let's build it.
Tell me about your idea, your product or your team. I usually reply within one working day.