Video in progress

How do you reconcile soft delete (`deleted_at`) with the GDPR "delete my data" requirement in a single system?

Soft delete is a reversible business deletion, while GDPR erasure is truly destroying personal data. I keep them separate: on erasure the personal fields are anonymized, and there's a plan for the copies in backups, logs and CDC as well.

📖 Answer

Soft delete isn't free by itself:

  • You have to add WHERE deleted_at IS NULL to every query. If you forget, "deleted" data shows up. Hibernate 6.4+ has @SoftDelete, and older versions have @Where/@SQLRestriction.
  • Unique constraints break: you can't sign up again with the email of a deleted user. The fix is a partial unique index:
CREATE UNIQUE INDEX uq_users_email_active
  ON users (lower(email)) WHERE deleted_at IS NULL;
  • The table grows with deleted rows; from time to time they have to be moved to an archive.

The GDPR requirement (and Uzbekistan's personal data law) is different: data that can identify a person has to be gone. Setting deleted_at doesn't do that.

Here is what I do:

  • I mark the personal fields (name, phone, email, address) explicitly. On erasure they are anonymized ('deleted-user-123'), while financial records like orders and payments remain without personal data for as long as the law requires.
  • Event logs, Kafka topics, search indexes, the analytics store: all of them are on the list. The erasure event is sent to them too.
  • Backups: you can't modify them. The usual approach is a limited backup retention period, and applying the erasure list again after a restore. Another option is crypto-shredding: each user's data is encrypted with its own key, and deleting the key means the data can't be read.

What makes this question staff-level is seeing not just one table but every place the data flows to.