Shipmind Labs

A missing invoice number is not a cosmetic bug. It is a gap an auditor will ask you to explain, and "our sequence skipped" does not count as an explanation.

Most teams hit this the same way. The number gets produced inside the request that renders the document, a count plus one, or a max plus one. Two checkouts land in the same second, both read the same value, and you ship either a duplicate number or, once one transaction rolls back, a hole in the series.

The reflex fix is a database auto-increment sequence. It solves the duplicates and keeps the hole: sequences are deliberately non-transactional, so every rolled back attempt burns a number.

What holds up is a counter that lives in the store as a row, scoped per series and per period, locked for the moment of allocation. And allocated when the document becomes final, not while a draft is still being edited. You serialize issuance inside one series, which is affordable, because nobody issues invoices at request-per-millisecond rates.

The split we keep coming back to: the VAT regime decides what lines appear on the document. The sequence decides whether the document is legal at all. Two different concerns, and mixing them is how numbering ends up in the template layer.

So it is worth checking where your invoice number gets assigned, at draft creation or at the moment the invoice is issued.

We wrote the full breakdown here: https://shipmindlabs.com/c/4a83d145

Was this useful?

Building something similar?

or email hello@shipmindlabs.com