concurrency-control

Design conflict-safe mutation plans for shared resources with deterministic locking.

4|Updated May 16, 2026
One-click install
npx skills add https://github.com/machenjie/rd-skills --skill concurrency-control-machenjie
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: concurrency-control
Source: https://github.com/machenjie/rd-skills/tree/main/src/foundation/capabilities/concurrency-control
Command: npx skills add https://github.com/machenjie/rd-skills --skill concurrency-control-machenjie

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

Concurrency bugs cause lost updates, duplicate effects, deadlocks, and race-dependent invariant violations when multiple actors mutate shared resources at the same time.

Core Features & Use Cases

  • Invariant-first concurrency design: names the exact invariant that must survive overlap before selecting a mechanism.
  • Mechanism selection with explicit conflict behavior: chooses the narrowest control strategy (optimistic, pessimistic, atomic SQL/CAS, distributed lease with fencing, idempotency keys, queue partitioning, CRDTs, or sharded counters) and documents how conflicts are handled.
  • Deadlock and TOCTOU prevention: enforces deterministic lock ordering, bounded lock/lease duration, and atomic read-check-act patterns to eliminate race windows.
  • Safety for duplicates and events: specifies idempotency key storage for duplicate-submit risk and requires outbox/post-commit safety to avoid publish-before-commit.

Quick Start

Use concurrency-control to design a conflict-safe, deadlock-resistant mutation plan for a shared resource where duplicate submissions or parallel workers are possible.

Frequently Asked Questions about concurrency-control

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I prevent lost updates and race conditions when multiple workers mutate shared resources concurrently?

Prevent lost updates and race conditions by applying invariant-first concurrency design that selects the narrowest control strategy, such as optimistic locking, atomic SQL/CAS, or distributed leases with fencing, to ensure deterministic conflict behavior.

What's the best way to handle duplicate submissions and ensure idempotency in a distributed system?

Handle duplicate submissions by implementing idempotency key storage and deduplication, which ensures that duplicate-submit risks from parallel workers or network retries do not result in duplicate effects on shared resources.

How do I avoid deadlocks when using distributed locking or pessimistic locking mechanisms?

Avoid deadlocks by enforcing deterministic lock ordering and bounding lock or lease durations, which eliminates circular waits and prevents indefinite blocking when multiple actors acquire locks on shared resources.

When do I need the outbox pattern for event publishing in concurrent applications?

You need the outbox pattern or post-commit guarantees when publishing events concurrently to prevent publish-before-commit anomalies, ensuring event publish safety alongside database mutations.

Does queue partitioning work for achieving deterministic execution with at-least-once delivery?

Queue partitioning works for at-least-once delivery by sharding execution, ensuring parallel workers process partitioned queues deterministically while idempotency keys handle any duplicate processing.

How do I choose between optimistic locking and pessimistic locking for my concurrency control strategy?

Choose between optimistic and pessimistic locking by naming the exact invariant that must survive overlap, then selecting the narrowest mechanism with explicit conflict behavior documentation, such as atomic SQL/CAS for simple updates or distributed leases for cross-node coordination.