Skip to main content

Merge Strategy

Controls how the system handles concurrent commands when sequence numbers don't match expectations. This is Angzarr's approach to optimistic concurrency.

Strategies

StrategyBehaviorUse Case
MERGE_COMMUTATIVEAllow if mutations don't overlapIndependent field updates
MERGE_STRICTReject on any mismatchFinancial transactions
MERGE_AGGREGATE_HANDLESAggregate decidesComplex business rules
MERGE_MANUALRoute to DLQHuman review needed

Default: MERGE_COMMUTATIVE

Most commands use commutative merge. Two concurrent commands succeed if they modify different parts of state:

Current state: { balance: 100, name: "Alice" }

Command A (seq 5): SetName("Bob") → OK, modifies name
Command B (seq 5): Deposit(50) → OK, modifies balance

MERGE_STRICT

For operations that must be serialized:

Current state: { balance: 100 }

Command A (seq 5): Withdraw(50) → OK, balance = 50
Command B (seq 5): Withdraw(75) → REJECTED, sequence mismatch

MERGE_AGGREGATE_HANDLES

The aggregate's command handler receives both the command and conflict context, deciding how to proceed.

MERGE_MANUAL

Routes to Dead Letter Queue for human review when automatic resolution isn't appropriate.