Event-Driven & CQRS — Series 3

Preview — 3 of 10 questions

How should the boundary be drawn?

javascript
Order (header, lines, totals)  |  Customer (profile, credit limit)
A command must place an order and decrement the customer's credit.
AMerge them into one aggregate so both changes are transactional
BLet the order aggregate load and modify the customer directly
CKeep them separate: an aggregate is the unit of transactional consistency, and putting two independently-changing entities in one makes every order block every other change to that customer — so the credit decrement happens through a second command, with a process manager coordinating and a compensation if it fails
DUse a distributed transaction across the two aggregates

What does the expected version protect against?

javascript
await this.store.append(streamId, events, { expectedVersion: aggregate.version });
ATwo commands loading the same aggregate concurrently, each deciding against the same state, and both appending — the store rejects the second because the stream has moved on, so the command can reload and retry rather than writing a decision made against stale state
BEvents being appended out of order within one command
CA projection reading the stream while it is being written
DDuplicate events caused by a retried append

What makes the rebuild safe?

javascript
A bug in the projection produced wrong totals for three months.
The read model must be corrected.
APatching the read model in place with a corrective SQL script
BReplaying events into the existing projection, which overwrites the wrong values
CDeleting the read model and letting it rebuild on demand as queries arrive
DBuilding a new projection alongside the old one — a versioned table the fixed code writes to — replaying from the start of the stream, and switching reads over only once it has caught up; the old one stays available throughout and is the rollback if the new one is also wrong

Sign up free to play

Answer all 10 questions (7 more), see explanations for every answer, and track your score.