Avoid naming series lock waits
When you save a document with an automatic number, such as a Sales Invoice or a Stock Entry, ERPNext takes the next number of its naming series. When hundreds of documents on one series are created at the same time, they wait for each other. This page explains why, and how to avoid it.
How numbering works
ERPNext keeps one counter for each naming series in a database table called tabSeries. To give the next number, ERPNext:
- locks the counter of the series,
- adds 1,
- unlocks the counter.
This takes a fraction of a second, so normally you do not notice it. Two documents never get the same number.
Why documents wait
Only one document at a time can hold the lock of a series. When many documents on the same series are created at the same time, the others wait in line. You then see:
- documents that take a long time to save,
- bulk imports or bulk submissions that are slow or get stuck,
- errors such as "Record has changed since last read in table 'tabSeries'", or database lock timeouts,
- background jobs that pile up.
It gets worse in busy periods, at month end, and when more background workers run, because more documents compete for the same counter. A customization that forces many transactions into one series makes that counter the bottleneck for the whole operation.
The fix: use more than one series
The lock is per series. Give groups of transactions their own naming series, so that they use different counters and do not wait for each other.
| Split by | Example series |
|---|---|
| Branch | SINV-MUM-.YYYY.-.####, SINV-DEL-.YYYY.-.#### |
| Project | SINV-PROJ-A-.####, SINV-PROJ-B-.#### |
| Cost center | SINV-CC01-.####, SINV-CC02-.#### |
| Department | SINV-SALES-.####, SINV-SUPPORT-.#### |
Transactions that are created at the same time should not all use the same counter.
More tips for large volumes
- Spread a large import across several series instead of one.
- Give the name yourself in imports and API calls where you can. A document that already has a name skips the counter. For example, a Customer can be named by the customer name.
- Review custom naming logic, so that it does not force all transactions into one series.
- Start very large jobs a little apart, not all at the same moment.