Concurrency

Use when implementing optimistic locking (@Version), pessimistic locking (SELECT FOR UPDATE), isolation levels, and state transition concurrency protections.

SahilKhan30 Updated

File contents

Concurrency & Locking Controls Skill

Purpose

Protect financial domain state transitions against concurrent race conditions, lost updates, and double-spends.


1. Rules of Engagement

CONDITIONAL

  • Optimistic Locking (@Version): Apply JPA @Version optimistic locking fields on write-mutable domain entities subject to concurrent state updates (Transaction, AccountBalance, DisputeRecord). Non-mutated or append-only entities do not require @Version.
  • Pessimistic Locking (SELECT FOR UPDATE): Use PESSIMISTIC_WRITE for high-contention financial balance updates where optimistic lock retries cause high abort rates.

DOMAIN SEMANTIC LOCKING RULE

  • When OptimisticLockException or state conflict occurs:
    • Do NOT blindly retry mutation in a loop.
    • If the entity state was already transitioned to the desired final state by a concurrent worker, return the current state or 409 Conflict based on business rules.

SahilKhan30/claude-skill/tree/main/.claude/skills/platform/concurrency commit 4b22875acd

Frequently asked questions

npx skillmds@latest add sahilkhan30/concurrency