GST invoice number rules in a billing app's code
GST Rule 46(b) read against a live billing app's code: one locked counter per shop, ten bills at once numbered 1 to 10, and the April restart question.
Ridam Agrawal
- 6 min
On this page
What are the rules for a GST invoice number?
Rule 46(b) of the CGST Rules, 2017 asks for a consecutive serial number of at most 16 characters, using letters, numbers, hyphens and slashes, in one or several series, unique for a financial year. Easinvy Retail numbers bills with one locked counter per shop, so two bills at once never share a number.
Easinvy Retail, our billing and inventory product for shops in India, gives every bill a number. Under GST that number is not free-form: Rule 46(b) of the CGST Rules, 2017 says what a tax invoice's serial number must be. This note reads the rule's words one at a time against Easinvy Retail's code, database and tests as they stood on 15 November 2026. It says where the code meets the rule, and the one place it runs differently from CBIC's FAQ. It reads only the number; Rule 46 lists many other things a tax invoice must carry.
Rule 46(b), clause by clause, against Easinvy Retail
Rule 46(b) asks for "a consecutive serial number not exceeding sixteen characters, in one or multiple series, containing alphabets or numerals or special characters- hyphen or dash and slash", "unique for a financial year". Easinvy Retail's answer to each part:
| Rule 46(b) | Easinvy Retail |
|---|---|
| A consecutive serial number | One counter per shop, claimed inside the bill's own transaction |
| At most sixteen characters | A whole number; the column stops at 2,147,483,647, ten digits |
| One or multiple series | One series per shop for sales bills |
| Letters, numbers, "-" and "/" | Numbers only, no prefix |
| Unique for a financial year | A unique index on shop and number; the series never restarts, so no number repeats in any year |
Why a PostgreSQL sequence cannot number GST invoices
A database sequence is the obvious tool for invoice numbers and the wrong one. PostgreSQL's CREATE SEQUENCE documentation says so directly: "Because nextval and setval calls are never rolled back, sequence objects cannot be used if 'gapless' assignment of sequence numbers is needed." A bill that fails after taking a number from a sequence leaves a hole in the series. A sequence is also one counter for a whole table, and Easinvy Retail needs one series per shop. Reading the highest bill number and adding one is worse: two bills read the same maximum and race for the same number. The same page names the alternative: gapless numbering can be built "by using exclusive locking of a table containing a counter".
One counter row per shop, locked inside the bill's transaction
Easinvy Retail keeps one row per shop in a document_counters table and claims
the next bill number with a single statement, run inside the same transaction
that writes the bill:
insert into document_counters (tenant_id, kind, next_value)
values ($1, 'bill', 2)
on conflict (tenant_id, kind)
do update set next_value = document_counters.next_value + 1
returning next_value - 1 as claimed
A shop's first bill needs no setup: the insert creates the row and claims
number 1. Every later bill increments it. PostgreSQL locks the row when
ON CONFLICT DO UPDATE acts on it, and
row-level locks are released at transaction end,
so a second bill for the same shop waits at this statement until the first one
commits, then claims the next number. A bill for another shop touches another
row and never waits. Every shop table in Easinvy Retail already carries the
shop's id, as described in
Multi-tenancy in Drizzle, from a shipped product,
and a unique index on shop and bill number stands behind the counter: if
anything ever tried to write the same number twice for one shop, the database
would refuse it.
Ten bills for one shop at the same moment
Easinvy Retail's concurrency test sends ten bills for one shop at once, each on its own database connection, so the transactions really overlap rather than running one after another. It checks two things about the numbers: "bill numbers are unique" and "bill numbers are gapless 1..10". The ten bills queue on the shop's counter row and leave it in order. The test runs on a scratch shop it creates and removes. We cite it as written; it was not re-run for this note.
A failed bill gives its number back; a cancelled bill keeps it
Easinvy Retail treats the two ways a bill can leave the series in opposite ways. A bill that fails while it is being saved never existed, so its number must not exist either. Because the counter is claimed inside the bill's transaction, a rollback takes the increment with it. The same test makes one bill, fails a second on purpose, and checks that "the next successful bill is number 2, not 3".
A cancelled bill did exist: it was printed, and perhaps handed to a customer. Easinvy Retail never deletes it. Cancelling changes its status inside one transaction, returns its stock, and keeps the bill and its number, and a reprint shows "Status: CANCELLED" with its number and date. For e-invoices the government portal's FAQ is explicit: "Once an IRN is cancelled, the concerned Invoice number cannot be used again to generate another e-Invoice/IRN." We found no official text on reusing a cancelled number outside e-invoicing, and Easinvy Retail never reuses one.
Does a GST invoice series have to restart every April?
Rule 46(b) asks for a number "unique for a financial year" and does not say the series must restart. CBIC's sectoral FAQ says single or multiple series are fine "as long as such invoice numbers are unique for a financial year". A second answer there, to a supplier billing from several locations, adds that "a supplier can have multiple series for the same year, so long as the same series is not used across financial years." The e-invoice system takes the financial year from the invoice date, in the words of NIC's API documentation: "The financial year is derived from the date of invoice." Most businesses read these together as a new series every April, often with the year in the number.
Easinvy Retail runs one series per shop that never restarts. No number repeats
in any year, so the rule's own words are met, but the series does run across
financial years, which CBIC's second answer does not expect. A series per year
needs three things: a counter kept per shop and per financial year, the year
taken from the bill's date, and the year printed in the number, such as
25-26/1042. A prefix of six characters leaves ten digits within the sixteen.
That is the change we would make for a shop that wants it; Easinvy Retail does
not have it today. A shop unsure which reading its auditor takes should ask its
chartered accountant.
The one way Easinvy Retail can repeat a bill number
Easinvy's admin panel can clear a shop's bills, for example to remove test bills before the shop starts billing for real. Clearing them also removes the shop's counter row, so the next bill is number 1 again. Before the first real bill, that is the point of the tool. After real bills in the same financial year, it would issue numbers already printed on bills that customers hold, which is exactly what "unique for a financial year" rules out. It is a setup tool, and only Easinvy's administrators can run it.
A checklist for GST invoice numbers in code
- Never number invoices with a database sequence: a sequence leaves gaps by design.
- Keep one counter row per series, and claim it inside the invoice's own transaction.
- Put a unique index on the series and the number behind the counter.
- Cancel invoices, never delete them, and print the cancellation on the invoice.
- Decide the financial-year rule before the first invoice: a counter per year and a year prefix if the business starts a new series each April.
- Keep any tool that resets numbering for setup only.
- Test with genuinely concurrent transactions, not calls made one after another.
Easinvy builds SaaS products with rules like this one in their data model.
Questions people ask
- How many characters can a GST invoice number have?
- At most sixteen. Rule 46(b) of the CGST Rules, 2017 allows letters, numbers and two special characters, the hyphen and the slash, in any combination. The e-invoice system also asks that a document number does not start with a zero, a slash or a hyphen.
- Does a GST invoice number have to restart every financial year?
- Rule 46(b) only requires the number to be unique for a financial year. CBIC's FAQ allows several series as long as the same series is not used across financial years, so most businesses start a new series each April, often with the year written into the number.
- Can a cancelled GST invoice number be used again?
- For e-invoices, no: once an IRN is cancelled, that invoice number cannot be used to generate another. We found no official text on reuse outside e-invoicing, so the safe practice is to keep the cancelled invoice and its number, which is what Easinvy Retail does.
- Why can't a database sequence generate GST invoice numbers?
- A sequence never takes a number back when a transaction fails, so a failed save leaves a gap in the series. PostgreSQL's documentation says sequences cannot be used when gapless numbering is needed, and suggests a locked counter table instead, which is what Easinvy Retail uses for each shop.
Sources
- CGST Rules, 2017 — Rule 46, Tax invoice (CBIC tax repository)
- CBIC — GST Sectoral FAQs (questions 14 and 22, invoice series)
- NIC — e-Invoice API, Generate IRN (the financial year from the invoice date)
- GST e-Invoice portal — FAQs (a cancelled IRN's invoice number)
- PostgreSQL — CREATE SEQUENCE
- PostgreSQL — Explicit locking: row-level locks
Ridam Agrawal
Founder and engineer at Easinvy. Writes up the parts of building and running a multi-tenant product that were expensive to get wrong. More about the studio →
Related
Drizzle migrations not applied in production
Why Drizzle migrations are skipped or fail in production, read from Drizzle's own code, with an ERP whose every login failed and the fix that stopped it.
Neon free tier compute hours and a health check
A five-minute uptime check kept Easinvy Retail's Neon database awake: 19.4 CU-hours in 78 hours, and the free allowance gone on 30 September 2026.
SaaS Product Development
Multi-tenancy, billing, and the parts founders discover too late.
All notes
Write-ups from building and running our own product.