Effect Optimistic Lock with Retry
Version-column concurrency for the workload where conflicts are rare and locks are waste: every row carries a version, the write is one atomic compare-and-set (the same shape as UPDATE ... WHERE version = ?), and a write that lost the race surfaces as a typed VersionConflict carrying both versions instead of silently clobbering. The optimistic loop re-reads before every attempt so it never replays a stale computation, retries with jittered exponential backoff a bounded number of times, and exhaustion on a genuine hot spot is a typed RetriesExhausted you can route to a queue. The demo shows 50 unguarded concurrent increments landing as 1 (49 silent lost updates) versus the versioned loop landing all 50 through 286 retried conflicts. Pinned to effect 4.0.0-beta.98.
npx shadcn@latest add https://ui.aryank.space/r/effect-optimistic-lock-retry.jsonInstalls from ui.aryank.space. To add it by hand, copy the files in Files below, or register the @compronents namespace via the docs.
Two handlers read stock=10, both compute 9, both write 9. Fifty concurrent sales landed as one: the demo measures 49 lost updates and not a single error anywhere. The odometer flashes red on the second write, the one that silently erased a sale.