Shared counters (like-counts, stock quantities, view counters) lose updates under concurrent writes when the application reads, increments in memory, and writes back. The classic read-modify-write race.
This module should reproduce lost updates on a shared counter, then fix them using compare-and-swap at the SQL level (UPDATE ... SET count = count + 1 or CAS with expected-value checks) — no explicit row locking needed.
What to build:
- Baseline test showing lost updates with naive read-modify-write
- At least 3 strategies: naive (buggy), SQL-level atomic increment, CAS with retry
- k6 benchmarks comparing throughput under contention
- Correctness invariant: final counter value == number of successful increments
Satisfies AC-1 through AC-5 from the PRD. Module follows the standard structure: docs/, compose.yml, integration tests extending AbstractIntegrationTest.
Shared counters (like-counts, stock quantities, view counters) lose updates under concurrent writes when the application reads, increments in memory, and writes back. The classic read-modify-write race.
This module should reproduce lost updates on a shared counter, then fix them using compare-and-swap at the SQL level (
UPDATE ... SET count = count + 1or CAS with expected-value checks) — no explicit row locking needed.What to build:
Satisfies AC-1 through AC-5 from the PRD. Module follows the standard structure:
docs/,compose.yml, integration tests extendingAbstractIntegrationTest.