Scrivio Interview library
ScenarioAdvanced7 min read · updated 12 November 2026

A regulator requires you to delete a customer's personal data, but your account service is event-sourced and events are immutable. How do you comply?

We comply by making sure the personal data can no longer be read, even though the events stay. The cleanest design keeps personal data out of events, referencing it in a separate store we can delete from; where it is already in events, crypto-shredding encrypts personal fields with a per-customer key and deletes the key. In both cases we also clean projections, caches, backups and every other copy of the events within the legal time limit, and we document the approach with the legal and data protection teams.

Why this question is asked

The right to erasure under GDPR, and similar rules elsewhere, collides directly with the central promise of event sourcing: events are immutable and kept forever. A team that has not planned for it discovers the problem when the first request arrives, with a deadline of about a month. Interviewers ask this scenario because it tests whether we can reconcile an architecture with a legal obligation, and whether we think beyond the event store to every place data has spread. In this answer, we will recap the conflict, look at keeping personal data out of events, go through crypto-shredding in code, and then cover projections, backups, other copies and the documentation that makes the approach defensible.

1A Quick Recap of the Conflict

An event-sourced account service stores events such as CustomerRegistered with name, email and address, and AddressChanged with the new address. The store is append-only by design; rewriting old events breaks the audit history, invalidates any checksums or hashes, and may not even be supported by the event store.

The regulation, however, requires that personal data about this customer is erased without undue delay, usually within one month, unless another law requires keeping it. Note that some records may need to be kept, for example transaction records for anti-money-laundering or tax rules, so the first step is always to agree with legal what must be deleted and what must be retained. The question is then how to make the personal parts unreadable while the facts that must remain stay intact.

2Option 1: Keep Personal Data Out of Events

The best answer is a design decision made before the first event is written. Events carry a customer id, not the name and email. The personal details live in a separate, ordinary table, a personal data store, which supports updates and deletes. When the regulator's request comes, we delete or anonymise that row, and every event that mentions the customer id now points at nothing personal.

Java
// stored event: no personal data, only a reference
record CustomerRegistered(UUID customerId, Instant at, String country) {}
// personal data store: mutable, deletable
// customer_pii(customer_id PK, name, email, address)
@Transactional
public void erase(UUID customerId) {
jdbc.update("DELETE FROM customer_pii WHERE customer_id = ?", customerId); // 1 row
outbox.add(new CustomerErased(customerId)); // tells projections and other services
}

The trade-off is that the event stream alone no longer tells the full story; to show a customer's name we join with the personal data store. For most systems that is a small price, and it also limits how far personal data spreads, since events copied to other topics carry only ids.

3Option 2: Crypto-Shredding

When personal data must be in the events, or already is, we use crypto-shredding. Each customer gets their own encryption key, kept in a key store or a KMS, a key management service. Personal fields in events are encrypted with that key before they are stored. To erase the customer, we delete the key. The ciphertext stays in the events, but without the key nobody can decrypt it, so the data is effectively destroyed.

Java
record CustomerRegistered(UUID customerId, String nameEnc, String emailEnc, String country) {}
CustomerRegistered event(UUID id, String name, String email, String country) {
SecretKey key = keys.getOrCreate(id); // one AES key per customer
return new CustomerRegistered(id, crypto.encrypt(key, name), crypto.encrypt(key, email), country);
}
String readName(CustomerRegistered e) {
return keys.find(e.customerId())
.map(k -> crypto.decrypt(k, e.nameEnc())) // "Ana Silva"
.orElse("[erased]"); // after erase: "[erased]"
}
public void erase(UUID customerId) {
keys.delete(customerId); // the events now hold unreadable bytes
outbox.add(new CustomerErased(customerId));
}
Step throughErasing a customer with crypto-shredding
Erasure workflowKey storeEvent storeProjections
delete key for customer 42
deleted
CustomerErased(42)
remove rows, clear caches
replay: decrypt fails, show [erased]
erasure confirmed

6 messages in order. Play them, or step through them one at a time.

The events stay; what made them readable is gone.

Notice two details. The code must handle a missing key gracefully, because replaying old events after erasure is normal. And the key store itself becomes critical: if keys are lost by accident, data is destroyed by accident, so the key store needs its own backups, with a deletion that also reaches those backups within the deadline. Whether crypto-shredding satisfies the law in a given case is a legal judgement, which is why the next sections matter.

4Cleaning Projections, Caches and Backups

Deleting the source is only the start. Projections built from the events hold decrypted copies: a customer table, a search index, a CRM sync. Each must consume CustomerErased and delete or anonymise its rows. Caches such as Redis entries must be evicted. If a projection is rebuilt later, crypto-shredding or the missing personal data row ensures the erased data does not reappear.

Backups need a plan too. Restoring an old database backup would bring deleted personal data back. Common approaches are short backup retention, so backups age out within the legal window, or a record of erasures that is re-applied after any restore. Whatever we choose, it must happen within the legal time limit and be written down.

5Checking Every Other Copy

Events rarely stay in one place. They are copied to other Kafka topics, mirrored to another cluster, landed in a data lake, logged by a consumer that prints payloads, and attached to dead-letter topics. Each copy is a place where personal data survives. So we make an inventory: every topic, sink and log destination that receives these events, with retention and owner.

For copies we cannot delete selectively, such as a long-retention Kafka topic, crypto-shredding is what saves us, because encrypted fields stay unreadable everywhere once the key is gone. That is a strong argument for encrypting personal fields at the source rather than in each consumer, and for keeping payload logging off in production.

Where a customer's data may survive
CopyErasure approach
Event storedelete PII row or delete key
Projections and read modelsconsume CustomerErased, delete rows
Cachesevict by customer id
Other topics and mirrorsencrypted fields unreadable without key
Data lakedelete partitions or rely on encryption
Backupsshort retention or re-apply erasures after restore
Logs and dead-letter topicsavoid payload logging; limited retention

6Document It With Legal and Data Protection

Finally, we write down the approach and agree it with the legal team and the data protection officer: which data is deleted and which is retained under which law, how crypto-shredding works and why we consider it erasure, how long each copy takes to be cleaned, and how we prove it per request. That document is what we show a regulator, and it also guides every new team that consumes these events.

7Follow-up questions

Is crypto-shredding really deletion?

Many organisations and regulators accept that data encrypted with a destroyed key is no longer personal data in practice, because it cannot be recovered with reasonable means. It is still a legal judgement that depends on the strength of the encryption and on proving the key and its backups are gone, so we agree it with the data protection officer rather than assume it.

Why not just rewrite the events?

Some event stores allow it, and for a small system it may be acceptable. But rewriting breaks the immutability that consumers and audits rely on, does not reach the copies in other topics and the data lake, and needs careful handling of versions and hashes. Separating or encrypting personal data handles all copies at once.

What about data we must keep for other laws?

We keep the facts the law requires, such as the transaction amounts and dates for anti-money-laundering rules, and erase what is not required, such as contact details. Designing events so that required facts and personal details are separate fields makes this split possible.

8Conclusion

In this answer, we saw that immutable events and the right to erasure can be reconciled by making personal data unreadable rather than rewriting history. The best design keeps personal data out of events in a deletable store; where it is in events, crypto-shredding with a per-customer key lets us erase it by deleting the key. We then clean projections, caches and backups, check every copy of the events in other topics, data lakes and logs, and document the approach with legal and data protection so it is defensible.

What to say in the interviewAbout 80 seconds aloud

Open with

I would start by agreeing with legal exactly what must be erased and what we must keep for other laws, like transaction records. Then the approach depends on the design.

Then, if they want more

Ideally events contain only a customer id and the personal details live in a separate, mutable personal data store, so erasure is just deleting that row and publishing a CustomerErased event.

If personal data is already in events, I would use crypto-shredding: encrypt personal fields with a per-customer key held in a KMS or key store, and delete the key on request. The events stay immutable, but the personal fields become unreadable everywhere, including in copies we cannot delete selectively. The code must treat a missing key as erased data.

Deleting the source is not enough, so every projection, search index and cache consumes CustomerErased and deletes its rows, and backups either expire within the legal window or have erasures re-applied after a restore. I would inventory every other copy, other topics, mirrors, the data lake, logs and dead-letter topics.

Finally I would document the approach with the data protection officer, including how we prove erasure for each request within the deadline.

About this answer

Last updated
12 November 2026
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.
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 "A regulator requires you to delete a customer's personal data, but your account service...": https://scrivio-interview-library.netlify.app/spring-boot/event-driven-patterns/e211057ceb/