class Ship
def load_cargo(name)
apply :cargo_loaded, :name => name
end
def paint(color)
apply :painted, :color => color
end
private
def apply_cargo_loaded(e)
@cargo = e[:name]
end
def apply_painted(e)
@paint_color = e[:color]
end
end
- Two LoadCargo commands(C1, C2) for Ship aggregate "abc" come in at the same time.
- The command handlers(async) both load up the ship to the latest version (let's say 5).
- C1 completes before C2 (making the aggregate version 6 at persistence level).
- When C2 commits, a ConcurrencyException is thrown due to C2 only knowing about events up to version 5.
- The ship's event stream repopulates up to 6.
- The uncommitted events are compared against the newly loaded events. Is this comparison better as a blacklist or whitelist?
- If there is a conflict, throw ConflictException and C2 never completes, otherwise, attempt C2 again.