Invoice numbers for a small business bookkeeping app
Your task
Your bookkeeping app is used by 8,000 small businesses to send invoices. Tax rules in their countries say each business's invoice numbers must run in order with no gaps and no repeats. The series starts again each year: 2026-0001, 2026-0002, and so on. An auditor who finds a missing number asks what happened to it.
Staff write invoices as drafts, which can be edited or thrown away. An invoice gets its number when someone issues it, and an issued invoice can never be deleted. To cancel one, the business issues a credit note, which has its own numbered series. The busiest business issues about 500 invoices a day, sometimes from 3 or 4 staff at once.
What happens when someone presses Issue, and why can no number be skipped or given out twice?
It covers
- Gapless numbering
- Row locks
- Transactions