(Note · · 5 min read)
Someone deleted a record and nobody knows who
A record is gone. The customer says it was there last week, the database says nothing at all, and there is no way to establish who removed it or what it contained. In a system holding payroll or payments, that is not an inconvenience — it is the absence of the thing the system was trusted to provide.
By Md. Habibur Rahman Shohel, full-stack & AI product engineer in Dhaka
Most deletes are really state changes
An employee who has left, a cancelled booking, a voided invoice: none of these are records that should cease to exist. They are records whose state has changed, and whose history still matters for a report, a reconciliation or a dispute.
Model the state. A status column, or a deletion timestamp, keeps the row while removing it from normal use, and keeps the question answerable afterwards.
Soft delete has sharp edges
The cost of keeping rows is that every query must now exclude them, and the one query that forgets is the bug. Default the exclusion wherever your data layer allows it, so including deleted rows is the deliberate act rather than the reverse.
- Unique constraints stop working as intended: a deleted row still occupies the email address. Scope the constraint to active rows.
- Counts and reports silently include or exclude deleted rows depending on who wrote the query.
- Foreign keys still point at deleted parents, so a child can reference something a user cannot see.
- Joins through a soft-deleted intermediate row produce results nobody expects.
None of these is a reason to avoid soft delete in a system that needs history. They are reasons to decide it deliberately, in one place, rather than adding a flag to a table and hoping.
What an audit trail has to record
A log saying a record was updated answers nothing. A usable entry records who, when, what changed from and to, and ideally why — the request or action that caused it.
Identify the actor as a person, not a service account that everything runs under. An audit trail attributing every change to the application is a trail with the answer removed.
Append only, and separate from the data
Audit entries should be written once and never updated or deleted, by code that has no path to modify them. A trail that the application can rewrite is evidence of nothing in the situation where it matters most.
Keep personal data out of the entries, the same way it is kept out of logs. Record which fields changed and the identifiers; the values themselves can be read from the record under the normal access controls.
When deletion is genuinely required
Sometimes data must actually go — a legal request, a retention limit. Make that an explicit, restricted operation that records the fact of the deletion in the audit trail, even once the content is gone.
The distinction worth holding is between removing data and removing the record that it existed. The first is occasionally obligatory. The second almost never is, and it is what leaves nobody able to answer the customer.
Common questions
Should records be hard deleted or soft deleted?
In a system holding payroll, bookings or payments, most deletes are really state changes — a departed employee or cancelled booking still matters for reports and disputes. Model the state with a status or deletion timestamp rather than removing the row.
What goes wrong with soft delete?
Unique constraints still count deleted rows, so a deleted row holds an email address; counts vary by whoever wrote the query; foreign keys point at invisible parents; and joins through soft-deleted rows surprise everyone. Scope constraints to active rows and default the exclusion in one place.
What should an audit entry contain?
Who, when, what changed from and to, and the action that caused it. The actor must be a person, not the service account everything runs under — a trail attributing every change to the application has the answer removed.
Can the application be allowed to edit its own audit log?
No. Entries should be append-only, written by code with no path to modify them, and kept separate from the data. A trail the application can rewrite proves nothing in exactly the situation where it is needed.