Scrivio Interview library
DesignAdvanced6 min read · updated 12 November 2026

Different teams implement soft delete in different ways (flags, status values, deleted_at columns, archive tables). Should you standardise it, and how?

Yes, but we standardise the decision before the mechanism. First each team names the purpose (undo, audit, legal retention or keeping references valid), because each purpose points to a different design. For the common undo-style case we offer one pattern: a deleted_at timestamp, partial unique indexes, filtering at the ORM and a purge job with a retention period. Audit goes to Envers or event tables, erasure rules for personal data are explicit, and the standard ships as a library or template with tests, not just a document.

Why this question is asked

When five teams solve the same problem five ways, every cross-team report, data migration and privacy request has to learn five dialects: is_deleted, status = 'REMOVED', deleted_at, an archive table, or nothing at all. Bugs follow, such as a report counting removed rows because it assumed the wrong convention. Interviewers ask this at a senior level because standardising badly is as harmful as not standardising: a single mandated flag forced onto every use case creates new problems. In this answer, we will recap the variants, start from purpose, define the standard pattern, route audit and erasure to the right tools, and look at how to make teams actually adopt it.

1A Quick Recap of the Variants in Use

A boolean flag (deleted true or false) is the simplest form: one column, one filter. A status value (ACTIVE, CLOSED, DELETED) mixes deletion with business lifecycle, which is fine until someone adds a fourth status and forgets the filter. A deleted_at timestamp records when the row was deleted, which a purge job needs, and doubles as the flag (null means live). An archive table moves deleted rows elsewhere, so the live table stays clean and queries need no filter, at the cost of a move operation and a second schema to maintain.

Each variant works. The trouble is that they answer different questions, and teams usually picked one without saying which question they were answering.

2Start From the Purpose, Not the Column

The first step of the standard is a short question every team must answer: why do we keep deleted data? The answer selects the design. Undo needs the row kept for a short window and restored easily. Audit needs a record of who changed what and when, for every change, not just deletes. Legal retention needs certain fields kept for a fixed period, often outside the live table. Referential integrity, keeping old orders pointing at a customer, often needs a business status such as CLOSED rather than deletion at all.

Purpose decides the design
PurposeRecommended designWhy
Undo for a short windowdeleted_at + purge after N dayssimple restore, bounded growth
Audit of changesEnvers or an event/audit tablerecords every change, not only deletes
Legal retentionarchive table with minimal fieldskeeps what law needs, live table clean
Old rows still referencedbusiness status such as CLOSEDit is not really a deletion
None of the abovehard deletenothing to keep, nothing to filter
Most disagreements between teams disappear once the purpose is written down.

3The Standard Pattern for the Common Case

For undo and short-term recovery, which covers most cases, we define one pattern and make it the default. The column is deleted_at TIMESTAMPTZ NULL, so we know when rows were deleted. Unique constraints become partial unique indexes over live rows (WHERE deleted_at IS NULL on PostgreSQL, or a generated column on MySQL). Filtering happens at the ORM, with @SoftDelete on Hibernate versions that support a timestamp strategy, or @SQLDelete with @SQLRestriction otherwise, and every database also gets a view of live rows for reporting. A purge job hard-deletes rows older than the team's declared retention period.

Java
@Entity
@SQLDelete(sql = "UPDATE customer SET deleted_at = now() WHERE id = ?")
@SQLRestriction("deleted_at IS NULL")
public class Customer extends SoftDeletable { ... } // base class from the shared library
@MappedSuperclass
public abstract class SoftDeletable {
private Instant deletedAt; // null = live
public boolean isDeleted() { return deletedAt != null; }
}
# application.yml, read by the shared purge job
data.soft-delete.retention.customer: 30d

Notice that the team declares only the retention. The column, the filter, the purge job and the reporting view come from the shared building blocks, so they behave the same everywhere. If the team is on a Hibernate version whose @SoftDelete supports a timestamp strategy, the library can switch to it without changing entity code; check your version before standardising on it.

4Audit and Erasure Need Their Own Rules

Soft delete is a poor audit trail. It records that a row was deleted, but not who changed the email last month or what the old value was. For real audit we standardise on Hibernate Envers, which writes a revision table for every insert, update and delete of an audited entity, or on explicit event tables where the business already thinks in events. This keeps the live table free of dead rows and gives auditors the history they actually ask for.

Personal data needs explicit erasure rules, written down per entity: what counts as personal, how long it may be kept after deletion, and what happens on a GDPR erasure request. Soft-deleted rows with a name and email that stay forever are a compliance problem, and so are audit tables that copy personal fields. The standard should say, for example, that a customer's personal fields are purged or anonymised 30 days after deletion, including in Envers revisions, while the financial records kept for law hold only an id.

5Shipping the Standard So Teams Use It

A wiki page that says please use deleted_at is ignored within a quarter. What changes behaviour is making the right way the easy way. We publish a small library with the base class, the purge job, the reporting-view migration template and test helpers. We add a project template that already contains them. And we ship tests that each team runs against its own entities: a soft-deleted row must be invisible to repository queries, re-registration with the same unique value must succeed, and the purge job must remove rows past retention.

Step throughRolling out the standard
  1. Inventory current variantsper team, with their purpose
  2. Agree purposes and designsone table, reviewed by teams
  3. Ship library and templatebase class, purge job, tests
  4. New entities use itchecked in code review
  5. Migrate old ones when touchedexceptions listed openly

5 steps in order. Play them, or step through them one at a time.

The standard spreads through tools and templates, not through a mandate.

Existing implementations do not need a big-bang migration. New entities use the standard immediately; old ones move when a team next touches them or when they cause an incident, and a short list of exceptions with their reasons is kept in the open. Adoption is measured by counting entities on the standard, not by counting documents read.

6Follow-up questions

Why deleted_at rather than a boolean?

Because the timestamp carries the information the purge job needs, works as a flag on its own, and makes partial indexes and retention rules straightforward. A boolean plus a separate timestamp column is two things to keep consistent.

What if a team really needs restore after a year?

Then the purpose is closer to retention than undo, and an archive table with a restore procedure is usually better than keeping a year of dead rows in the live table where every query must avoid them. The point of the standard is that this is a stated, reviewed exception, not a silent variation.

Who owns the shared library?

A platform or data-layer team should own it, with contributions from product teams, a version policy and a changelog. Without an owner, the library becomes another variant.

7Conclusion

In this answer, we saw that standardising soft delete starts with purpose: undo, audit, legal retention and referential integrity each lead to a different design. For the common case we defined one pattern with deleted_at, partial unique indexes, ORM filtering, a reporting view and a purge job with declared retention. Audit moves to Envers or event tables, personal-data erasure is written down per entity, and the standard is delivered as a library, template and tests so teams adopt it because it is the easiest option.

What to say in the interviewAbout 80 seconds aloud

Open with

I'd standardise, but I'd standardise the decision first and the mechanism second. Soft delete gets used for different purposes: undo, audit, legal retention, or keeping old references valid, and each one wants a different design.

Then, if they want more

So the first rule is that each team states its purpose. For undo, the common case, I'd define one pattern: a deleted_at timestamp, partial unique indexes over live rows, the filter applied in Hibernate, a view of live rows for reporting, and a purge job driven by a retention period the team declares.

For audit, I'd point teams to Envers or event tables instead, because soft delete only tells you a row was deleted, not who changed what. For legal retention, an archive table with minimal fields. And sometimes the honest answer is a business status like CLOSED.

For personal data I'd make erasure rules explicit per entity, including audit tables, so we can answer GDPR requests. Then I'd make the standard easy to adopt: a small shared library with a base class, the purge job and test helpers, a project template, and tests teams run on their own entities. New entities use it immediately and old ones migrate when they're touched.

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 "Different teams implement soft delete in different ways (flags, status values...": https://scrivio-interview-library.netlify.app/databases/jpa-fundamentals/be4f936bd0/