Last updated on August 21st, 2026 at 01:05 pm
The main lesson: keep a record’s position inside its group separate from its position in the full sequence.
This avoids a common bug where numbering restarts at 1 whenever a new section begins.
What I learned
Grouped data often needs two different identifiers:
- A group identifier that says which section owns the record.
- A global sequence number that keeps increasing across every section.
Trying to use one value for both jobs makes titles, URLs, exports, and rebuilds harder to reason about.
Why numbering accidentally restarts
The usual cause is normalizing every section to a local range. For example, each section may contain 20 records numbered 1 through 20. If that local number is also displayed publicly, section two incorrectly starts at 1 again.
Cause: the code subtracts the section offset before generating the public number.
Fix: preserve the local position for grouping, but calculate or store a separate global number for display and lookup.
A simple fixed-size formula
When every group has the same size, the global number can be calculated as:
global_number = ((group_number - 1) * group_size) + local_number
With 20 records per group:
- Group 1 contains global numbers 1–20.
- Group 2 contains global numbers 21–40.
- The first local record in Group 2 has global number 21.
If groups have different sizes, use the total number of records in all previous groups as the offset instead of multiplying by a fixed size.
Keep the data model explicit
A clear record can contain both values:
{
"group_id": 2,
"local_number": 1,
"global_number": 21
}
This makes each field’s purpose obvious. The group identifier supports grouping and navigation. The global number supports continuous titles, stable URLs, ordering, and external references.
Updating older stored data
Changing the numbering rule can affect previously captured or cached data. A safe update process is:
- Add or recognize a data-format version.
- Convert older records when they are read or rebuilt.
- Keep the original group identifier unchanged.
- Generate titles and URLs from the corrected global number.
- Test the boundary between two consecutive groups.
This compatibility step is important. Updating only new records can leave the system with two numbering rules at the same time.
Common mistakes
Mistake: overwriting the group identifier with the global number.
Fix: store both concepts separately.
Mistake: testing only the first group.
Fix: test the last record of one group and the first record of the next.
Mistake: changing displayed numbers without considering existing URLs or cached data.
Fix: add a compatibility conversion and rebuild dependent output.
Conclusion
Continuous numbering becomes simple once local position and global position are treated as different data. The concrete next action is to add a boundary test that confirms one group ends at 20 and the next begins at 21.
