(Note · · 5 min read)

Undoing a transaction without rewriting history

A sale is cancelled, goods come back, a payment is refunded. The tempting implementation is to remove or edit the original record so the numbers look right again. That restates every report that already included it, and removes the evidence that it ever happened.

By Md. Habibur Rahman Shohel, full-stack & AI product engineer in Dhaka

Reverse forward, never backward

A reversal is a new transaction that undoes the effect of an earlier one, dated when the reversal happened, referencing what it reverses. Both exist afterwards. That is what keeps a closed period closed and an already-sent report true.

Editing the original moves an effect into the past. Somebody acted on last month's figures, and silently changing them means the decisions and the data no longer agree, with nothing recording the change.

One event, several consequences

A return is not one reversal. Stock comes back in, revenue reverses, cost of sale reverses at the original cost, tax reverses, and money leaves. Handle them as a set, in one transaction, so a partial failure cannot leave the stock returned and the refund unrecorded.

Each consequence references the original, which is what makes the pair auditable later rather than two unrelated entries that happen to be about the same amount.

Partial is the normal case

Three of five items come back. Half the amount is refunded. A reversal model that only handles the whole transaction gets worked around by hand, and hand-worked reversals are where discrepancies come from.

Track the remaining reversible quantity and amount on the original, and refuse to exceed it. Without that check, two partial returns processed concurrently can return more than was ever sold.

Not everything comes back saleable

Goods returned damaged should not re-enter available stock. Model the condition — return to stock, quarantine, write off — because quietly adding a broken item back to availability means selling it again.

A write-off is its own entry with its own reason, which keeps the loss visible instead of folded into a stock discrepancy nobody can explain.

The refund is a separate failure domain

Refunding through a payment provider is a network call that can time out after succeeding. Treat it with the same care as a charge: an idempotency key so a retry cannot refund twice, and a recorded state for in-flight refunds.

Never record a refund as complete because the request was sent. Record what the provider confirms, and reconcile against its settlement reports — a refund that failed silently leaves a customer waiting for money your system believes it sent.

Make the chain visible

Show the original, its reversals and their net effect in one place, for support staff as much as for auditors. Most disputes are resolved by someone being able to read the sequence of what happened.

Recording who authorised each reversal matters too. Reversals move money and stock, which makes them exactly the operation that should carry a permission check and an audit entry naming a person.

Common questions

Should a cancelled transaction be deleted?

No. Write a reversal dated when it happened, referencing the original, so both exist. Editing or deleting the original restates reports that have already been acted on and removes the evidence that the transaction occurred.

What does a return actually involve?

Several consequences from one event: stock back in, revenue reversed, cost of sale reversed at the original cost, tax reversed, money out. Handle them in one transaction so a partial failure cannot leave stock returned and the refund unrecorded.

How do I handle partial returns?

Track the remaining reversible quantity and amount on the original and refuse to exceed it. Partial is the normal case, and a model that only reverses whole transactions gets worked around by hand — which is where discrepancies come from.

Can a refund be marked complete when sent?

No. A provider call can time out after succeeding, so use an idempotency key, record in-flight refunds as their own state, mark complete only on confirmation, and reconcile against settlement reports.

Need something like this built?