All articlesBackend / Data systems

Deleting Data Is Harder Than Saving It

Animesh Sharma
5 min read
A hand removes a blue document from a filing cabinet while branching threads lead to copies in stacks, glass drawers, and an archive box.
Gone from here isn't gone from everywhere.

The row is gone. The API returned success. The button did its job.

A minute later, the same information turns up in search.

Nothing particularly exotic has happened. The database knew about the deletion. The search index didn't. Somewhere else, a cache is still having a perfectly normal day.

Imagine a support ticket with an attachment and an automatically generated summary. Saving it might involve one straightforward request. Deleting it means finding out how many systems have been making themselves useful with copies of it.

This is an engineering problem, not a guide to legal retention periods. What a product must retain, and for how long, needs its own agreed policy.

DELETE is a local instruction

Start with the database. Even there, "deleted" doesn't necessarily mean that every old byte has immediately disappeared.

PostgreSQL's vacuuming documentation explains that an update or delete leaves old row versions behind until they can be reclaimed. That supports concurrent transactions; it isn't the application secretly ignoring your query. Reclaiming space is also not the same promise as securely sanitizing every historical storage copy.

At the application level, a soft-delete flag has another meaning again. It can be useful for recovery, but the record is still there. Every relevant read path needs to honour that state, including the export someone wrote six months after the original endpoint.

The record has other addresses

Our ticket may have an attachment in object storage, a cached preview, a search document, an analytics extract, and a summary. Deleting the ticket row doesn't send an instruction to all of those places by magic.

I'd want a data map before a clever deletion script: where is the original, what is copied, what is derived, and which identifiers connect them? If a summary keeps no reference to its source, finding it later becomes detective work.

Copies outside the product's control need a separate answer. An exported file somebody downloaded cannot be recalled just because our endpoint returned 200. The deletion promise needs to describe the boundary the system can actually enforce.

A hypothetical support ticketOne record. More than one address.
Primary store

Remove or restrict the active record

Cache & CDN

Invalidate managed copies

Search index

Remove entries and reject stale updates

Derived outputs

Remove or rebuild dependent summaries

Exports & logs

Track scope and minimize retained content

Backups

Apply retention and restore safeguards

A data map describes work to do, not proof that it has been completed. Downloads outside the product's control need a separate policy.

The job can fail halfway

Suppose we delete the row, then publish an event asking other services to clean up. The process crashes between those two steps. The primary data is gone; the cleanup instruction never leaves.

The transactional outbox pattern addresses this dual-write problem by recording the database change and the event in the same transaction. A separate worker delivers committed events. Consumers still need to handle duplicates, and ordering still matters. The pattern makes the instruction durable; it doesn't prove every destination has finished.

I'd track acknowledgement from each destination, retry failed work, and surface jobs that stop making progress. I'd also guard against an old update arriving after deletion and rebuilding the search entry. A per-record version or generation check can help reject stale work; a timestamp alone isn't a complete ordering strategy.

Backups have excellent memories

A backup taken before the deletion can contain the data we just removed. That is rather the point of a backup, which makes it an awkward place to discover that our deletion design ends at the production database.

Elastic's snapshot restore documentation describes recovering indices and data streams after deletion. Restoring an older snapshot without reconciling later deletion decisions can therefore bring unwanted records back into service.

One approach is to restore into an isolated environment, apply a protected deletion ledger kept independently of the restored snapshot, and verify the result before reopening access. That ledger must itself be minimized, access-controlled, and retained under a defined policy; identifiers aren't automatically anonymous.

Object storage has its own recovery rules. With Cloud Storage soft delete, deleted objects remain recoverable during the configured retention period. Changing the policy later doesn't retroactively shorten the period for objects already soft-deleted. Recovery settings and deletion promises need to agree.

The recovery testA successful restore can undo a successful deletion.
Would yesterday's backup bring the ticket back?

If that backup contains the ticket, restoring it without reconciling later deletion decisions can reintroduce the record. Restore in isolation, apply an independently retained deletion ledger, and verify the relevant stores before reopening access. The ledger itself needs access controls and an appropriate retention policy.

AI gives copies new shapes

The ticket's summary might contain the customer's name and the problem they reported. A retrieval system may have split the attachment into chunks and built embeddings. None of that becomes harmless merely because it is no longer stored as the original file.

Keep lineage from sources to derived outputs. Remove affected retrieval entries, and rebuild or remove summaries that depend on deleted material. If a summary combines several tickets, deleting one input may require regenerating the summary from the remaining permitted inputs.

I wouldn't describe removing an index entry as making a model "forget". Retrieval, stored conversation history, provider retention, and model training are different questions. The system needs to establish which of them applies rather than bundle them into one reassuring sentence.

Give done a definition

"Deletion requested", "removed from active use", and "all applicable retention work complete" are useful distinctions. They aren't interchangeable success messages, and there isn't one universal timeline that fits every system.

I'd test the less photogenic cases: a consumer offline during deletion, a duplicate event, an old update arriving late, a failed cache invalidation, and a backup restored after the request. Then I'd check that the supposedly deleted information doesn't quietly reappear.

Logs deserve a look, too. Copying the full deleted payload into a cleanup error message creates another copy to manage. A bounded operational record can show what happened without reproducing the content we were trying to remove.

Saving data gives it an address. Deleting it properly means understanding everywhere it travelled.

Illustrative lifecycle / no fixed timelineThree different meanings of done.
  1. 01Requested

    The operation is durably recorded, authorized, and tracked.

  2. 02Out of active use

    Relevant serving paths have confirmed removal or restriction.

  3. 03Retention work complete

    Applicable retained copies have been handled under the agreed policy.

Was this useful?
Your take

The conversation

Loading discussion...

Comments