Offline Concurrency Strategy Selector
by @quochungto
Use when designing concurrency control for long-running edits where a business transaction spans multiple system transactions — user opens a record, edits fo...
Example 1: CMS Article Editor (low collision, low rework cost)
Scenario: A content management system where editors write articles. Typical edit session: 10–30 minutes. Team of 5 editors; each article usually has one assigned editor. Collisions rare but possible.
Trigger: "We sometimes lose edits when two people accidentally open the same draft. Should we add locking?"
Process:
Output: Add version INTEGER NOT NULL DEFAULT 0 + modified_by + modified_at to articles table. Abstract article mapper includes version in UPDATE WHERE clause. On row count 0 → show "This article was modified by [user] at [time]. Please copy your changes, reload, and re-apply." No lock table needed.
Example 2: Insurance Policy Underwriting (high rework cost)
Scenario: Underwriters edit complex insurance policies. Editing a policy takes 45–90 minutes (data gathering, actuarial calculations, document review). Two underwriters might be assigned the same policy. If an underwriter finishes after 90 minutes and their save is rejected, the work is genuinely lost — not a minor inconvenience.
Trigger: "Underwriters are furious about rejected saves. Is there a better approach?"
Process:
SELECT FOR UPDATE on policy table.Output: Database lock table + shared version on Policy aggregate + LockingMapper + HTTP session expiration listener. UX: "Policy 12345 is currently being edited by Bob Smith. It will be available after his session ends or at [timeout time]."
Example 3: E-commerce Order Management (aggregate integrity)
Scenario: Customer service agents edit orders. An order has LineItems, ShippingAddress, and PromoCodes. One agent might add a LineItem while another changes the ShippingAddress at the same time. Each object in isolation is low-risk, but the order must be consistent as a whole.
Trigger: "We have a bug where the order total is wrong — looks like two people edited it at the same time."
Process:
Output: Single version table row per order, referenced by all members. Abstract mapper update() calls order.getVersion().increment() before any member update. Conflict error: "Order 8834 was modified by [user] at [time]. Please reload to see current state."
clawhub install bookforge-offline-concurrency-strategy-selector