BaryoDev / BaryoDev/barakoCMS

Accounting: NumberSequence is one row under optimistic concurrency, so throughput falls as writes rise

Open
#551 0 comments 0 reactions 1 assignee Claimed by @arnelirobles View on GitHub
enhancement module
Dominant language
C#
Stars
6
Forks
7
Avg merge
4h 42m
Merged PRs (30d)
307

Description

`BarakoCMS.Accounting/Domain/NumberSequence.cs` keeps one row per named sequence and increments it under Marten optimistic concurrency. Its own comment says the loser retries.

That is correct for two editors touching the same record. It is the wrong shape for a counter that every write must increment: the abort rate climbs with concurrency, so throughput falls exactly when load rises.

Three known fixes, in order of how much they cost to adopt:

1. A Postgres sequence. Fast, and it gaps on rollback.
2. Hi/lo batch allocation per instance. Fast, and it gaps between instances.
3. Allocate the number in a serial worker at confirmation time. Gapless, and it serializes.

Gapless numbering is a business requirement in some jurisdictions and it costs serialization. Decide which is wanted before changing the code.

Not urgent at current volumes. Filed so the choice is made deliberately rather than during an incident.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.