Introduction
A customer disputes an invoice. They say it was cancelled in March; your system shows it as paid. The invoices table has one status column with the value "paid" and an updated_at timestamp from last week. Somewhere between March and now, the status changed several times, and that history is gone.

Mutable status columns are convenient because they are easy to query and easy to update. They are also lossy. Every UPDATE overwrites the previous state, the reason for the change, and the person responsible. Logging tables added later are often incomplete because some code paths forget to write to them.

This article explains how to model business objects as explicit state machines, record every transition in an append-only ledger, keep a fast current-state view, and protect the ledger from tampering.

Why Mutable Status Columns Fail Audits
Auditors and enterprise customers ask the same questions: who changed this, when, from what, to what, and why? A status column can answer "What is it now?" and nothing else. It also allows invalid jumps. Nothing stops code from setting a draft invoice straight to "refunded" or a cancelled order back to "shipped," because the database has no idea which transitions make sense.

The result is a system where bugs and manual fixes leave no trail. When something looks wrong, engineers dig through application logs, if they still exist, to reconstruct history.

Designing the State Machine
Start by writing down the states and the allowed transitions between them. For an invoice: draft to issued, issued to paid or cancelled, paid to refunded. Each transition has a name, such as "issue" or "record_payment," and a list of roles allowed to perform it.

Store the allowed transitions as data so the database can enforce them and so the business can read them. Every transition attempt is checked against this table; anything not listed is rejected.

Building the Append-Only Ledger
Record each transition as a row in an events table that is only ever inserted into. Keep a current-state table for fast queries, updated in the same transaction as the insert.

`CREATE TABLE invoice_transitions (
from_state text, to_state text, action text,
PRIMARY KEY (from_state, action)
);

CREATE TABLE invoice_events (
id bigserial PRIMARY KEY,
invoice_id bigint NOT NULL,
action text NOT NULL,
from_state text NOT NULL,
to_state text NOT NULL,
actor_id bigint NOT NULL,
reason text,
occurred_at timestamptz NOT NULL DEFAULT now(),
FOREIGN KEY (from_state, action) REFERENCES invoice_transitions
);
CREATE FUNCTION forbid_change() RETURNS trigger LANGUAGE plpgsql AS $$
BEGIN RAISE EXCEPTION 'invoice_events is append-only'; END $$;
CREATE TRIGGER no_update_delete BEFORE UPDATE OR DELETE ON invoice_events
FOR EACH ROW EXECUTE FUNCTION forbid_change();`

The application transition function locks the invoice row with SELECT ... FOR UPDATE, checks the current state, inserts the event, and updates invoices. status in one transaction. The foreign key to invoice_transitions guarantees that only defined actions from a given state can be recorded. Revoke UPDATE and DELETE on the events table from the application role as a second layer of protection.

Querying History and Current State
Current-state queries stay as simple as before because the status column still exists, now maintained only by the transition function. History queries read the ledger: every change to an invoice in order, all actions by a given user, or how long invoices spend between issued and paid.

That last kind of question becomes a reporting feature rather than an engineering project. Cycle times, bottlenecks, and reversal rates come straight from the ledger.

Practical Examples: Real-World Use Cases
A B2B logistics company moved shipment status to a ledger after a customer dispute it could not resolve. Six months later, a similar dispute took five minutes: the ledger showed the delivery was marked complete by a driver app at a specific time and later reopened by a support agent with a recorded reason.

A procurement platform uses ledgers for purchase order approvals. Enterprise customers export the ledger for their annual audits, which removed a recurring request for custom reports.

A SaaS billing product reconstructs any invoice's state on any date from its events, which made revenue recognition reports straightforward.

Common Mistakes to Avoid

  • Updating the status column directly from scattered code paths. Route every change through one transition function.

  • Storing events without the actor and reason. The who and why are the points of an audit trail.

  • Letting the application role delete or update events.

  • Modelling every field change as an event. Use the ledger for meaningful state transitions; use a separate change log for field edits if needed.

  • Forgetting concurrency. Without a row lock, two simultaneous transitions can both pass validation.

Best Practices: Actionable Tips

  • Write the state diagram with the business before writing code, and keep it in the repository.

  • Give every transition a verb-style action name, and reference it in UI buttons and API endpoints.

  • Show the event history in the product, not only in the database.

  • Add tests that attempt every invalid transition and expect a rejection.

  • Archive old events to cheaper storage by date rather than deleting them.

Conclusion
A mutable status column tells you where something is; an append-only ledger tells you how it got there. Define states and transitions as data, record every transition with actor and reason in an insert-only table, and maintain the current state in the same transaction and block updates and deletes at the database level. The takeaway: make history impossible to lose, and audits become a query instead of an investigation.

Build Audit-Ready Systems With Parallaxis
Parallaxis builds custom B2B software for operations, finance, and logistics teams, with state machines and audit trails designed in from the start. If disputes or audits keep exposing gaps in your system's history, visit parallaxis.in to explore our custom software services or talk to us about your workflows.