Quick revision
The short answer
Audit requirements want an append-only history of every change, privacy law wants personal data truly erased on request, and the two conflict, so the company needs a clear written policy rather than case-by-case decisions. The core design is to separate personal data from business records, so history of orders, payments and changes can be kept while names, emails and addresses are erased or pseudonymised; crypto-shredding covers backups and logs where rows cannot be deleted. Soft delete is used only where undo or retention requires it, because it adds a filter to every query and breaks unique constraints without partial indexes, and every dataset gets an owner, a retention schedule and automated deletion jobs that leave evidence for auditors.
What to remember
In this answer, we saw that audit history and erasure pull in opposite directions and need a written policy. Separating personal data from business records lets history be kept while people are erased or pseudonymised, crypto-shredding covers backups and logs, soft delete is used only where undo or retention needs it, with partial unique indexes, and owners, retention schedules, automated deletion jobs and recorded evidence make the policy provable to auditors.
Your turn
Answer it aloud as you would in the interview, or type your answer below. Then show one part at a time and compare.
Audit requirements want an append-only history of every change, privacy law wants personal data truly erased on request, and the two conflict, so the company needs a clear written policy rather than case-by-case decisions. The core design is to separate personal data from business records, so history of orders, payments and changes can be kept while names, emails and addresses are erased or pseudonymised; crypto-shredding covers backups and logs where rows cannot be deleted. Soft delete is used only where undo or retention requires it, because it adds a filter to every query and breaks unique constraints without partial indexes, and every dataset gets an owner, a retention schedule and automated deletion jobs that leave evidence for auditors.
Background to this question
Two pressures have grown at the same time. Regulators, auditors and enterprise customers want proof of who changed what and when, which pushes us to keep everything forever. Privacy laws such as the GDPR give people the right to have their personal data erased, which pushes us to delete. A company that handles this with ad hoc decisions ends up with deleted_at columns everywhere, audit tables full of emails that should have been erased, and backups nobody can clean. In this answer, we will look at the tension itself, the tools we have for history and for deletion, how separating personal data resolves most of the conflict, how crypto-shredding handles backups and logs, when soft delete is worth its cost, and how ownership and automation make the policy provable.
1Understanding the Conflict
Audit history answers questions such as: who changed this customer's credit limit, and what was it before? To be trustworthy, that history must be append-only, meaning nobody can quietly edit or remove entries. Common ways to keep it are audit tables written by triggers or by the application, change data capture (CDC) streams that record every row change from the database log, and temporal tables that keep each row's past versions with validity periods.
Erasure answers a different demand: delete everything about this person. If the audit history recorded that the customer's email changed from ana@example.com to ana.k@example.com, the history now contains exactly the personal data we must erase. So keeping complete history and erasing personal data cannot both be done naively. A policy has to decide, for each kind of data, which requirement wins and how the other is still satisfied.
2Separating Personal Data From Business Records
The design move that resolves most of the conflict is to keep personal data in a few clearly identified places, apart from the business records that must be retained. An order needs to keep its amount, date, items and tax for, say, ten years for accounting. It does not need the customer's name and address in its own row; it can reference a customer id. The customer's personal details live in a customer_profile table, and audit history for business tables records ids and amounts, not personal fields.
- Business recordsorders, payments, ledgers: retained by law
- Audit and CDC historyids and amounts, no personal fields
- Personal data storenames, emails, addresses: erasable
- Backups and logsencrypted per person: crypto-shredding
4 layers, from the top down. Step through them one at a time.
After the erasure, the orders still exist with customer_id 42, so revenue reports and audits stay correct, but the id no longer leads to a person. Whether this pseudonymised state counts as anonymous depends on what other data could re-identify the person, which is a question for legal and privacy experts, not only engineers.
3Crypto-Shredding for Backups and Logs
Some copies cannot realistically be edited row by row: database backups kept for 35 days, archived WAL, log files in a log platform, events in a Kafka topic retained for weeks. Rewriting all of them for each erasure request is impractical. Crypto-shredding solves this. Personal fields are encrypted with a key specific to each person, kept in a key management service, and only the encrypted value is stored everywhere. To erase the person, we delete their key. Every copy, in every backup and log, becomes unreadable at once.
The cost is complexity: encryption and decryption in the application, key management at scale, and the fact that encrypted fields cannot be searched or indexed by value without extra techniques such as a keyed hash for lookups. So I would apply it to the personal fields that spread widely, not to everything.
4Soft Delete and Its Hidden Cost
Soft delete means marking a row as deleted, usually with a deleted_at column, instead of removing it. It gives an undo button and keeps history in place, which is why teams like it. But it has costs that grow over time. Every query must remember to filter AND deleted_at IS NULL, and the one that forgets shows deleted data. Unique constraints break: a user who deletes their account cannot sign up again with the same email, because the soft-deleted row still holds it, unless we use a partial unique index. And soft delete is not erasure, so it does nothing for privacy requests on its own.
So my policy would allow soft delete only where there is a real need, such as a legal retention period during which a record must be restorable, or a product requirement for undo, and it would require partial unique indexes and a scheduled hard delete or erasure when the retention period ends.
5Ownership, Retention Schedules and Evidence
A policy only works if someone is responsible for each dataset. Every table or topic holding personal data gets a data owner, a retention schedule stating how long each category is kept and why, and an automated job that enforces it, deleting or erasing on schedule and when requests arrive. The jobs record what they did: request id, datasets processed, rows affected, time. That record is the evidence auditors and regulators ask for.
- Request verifiedidentity confirmed, ticket created
- Look up the person in the data mapevery system holding their data
- Erase personal store, pseudonymise referencesbusiness records kept
- Delete the person's encryption keybackups and logs become unreadable
- Record evidencesystems, rows, time, request id
- Confirm to the person within the legal deadline
6 steps in order. Play them, or step through them one at a time.
Behind this is a data map, an inventory of where personal data lives, kept current by requiring new services to register their datasets. Without it, an erasure request is a search through hundreds of databases, and we can never prove we found everything.
6Follow-up questions
Do audit logs have to keep the person's name to be valid?
Usually not. An audit entry that says user 42 changed the credit limit of account 7 from 1,000 to 5,000 at a certain time is complete and verifiable. The mapping from 42 to a name sits in the personal data store and can be erased. Where a regulation requires the name itself to be retained, that requirement overrides erasure for that record, and the policy should say so explicitly.
How do you handle analytics copies in a warehouse?
The warehouse is one more system in the data map. Erasure requests flow to it through the same process, typically by deleting or pseudonymising rows by person id, and its retention schedule is often shorter for raw personal data than for aggregated, anonymous data. CDC pipelines should carry the erasure as an event too, so downstream copies follow automatically.
7Conclusion
In this answer, we saw that audit history and erasure pull in opposite directions and need a written policy. Separating personal data from business records lets history be kept while people are erased or pseudonymised, crypto-shredding covers backups and logs, soft delete is used only where undo or retention needs it, with partial unique indexes, and owners, retention schedules, automated deletion jobs and recorded evidence make the policy provable to auditors.
Open with
Audit and privacy pull in opposite directions: auditors want an append-only history of every change, through audit tables, CDC or temporal tables, while privacy law says personal data must really be erased on request.
Then, if they want more
So I'd set a clear policy instead of letting each team decide. The main design move is separating personal data from business records.
Orders, payments and ledgers keep ids, amounts and dates for their legal retention period, and audit history records ids rather than personal fields, while names, emails and addresses live in a personal data store that can be erased or pseudonymised.
For copies we can't edit row by row, like backups, WAL archives, logs and Kafka topics, I'd use crypto-shredding: personal fields encrypted with a per-person key, and deleting the key makes every copy unreadable.
Soft delete I'd allow only where undo or retention requires it, because every query needs a deleted filter and unique constraints break unless we use partial unique indexes, and soft delete isn't erasure anyway.
Finally, every dataset gets an owner, a retention schedule and automated deletion jobs that record evidence, backed by a data map of where personal data lives, so we can prove to auditors that erasure actually happened.
About this answer
- Last updated
- 12 November 2026
- Versions it names
- Hibernate 6
- Checked
- Its structure and format are checked automatically. Use it as a carefully prepared study note: where a detail matters, confirm it against the documentation below. What the checks cover
- Where the question comes from
- Written by Scrivio for practice. It is not taken from an interview.
- Official documentation
- PostgreSQL documentation, The SQL Language
Report an issue with this answer
Copy the line below and send it to the author with what you found. It carries the address of this page.
Issue with "Regulators and customers increasingly demand that you can prove who changed data and...": https://scrivio-interview-library.netlify.app/databases/sql-fundamentals/0a37e6a0d9/