Part 7 of 7 · 3 min read
Exercises
Easy
Easy 1: Order the 2PC steps (20 minutes)
Put in order: coordinator logs the decision; participants vote; application runs work on each node; coordinator sends commit; participants write data to disk.
Done when: a numbered list and the two points of no return marked.
Hint
The decision is written before anyone is told.
Easy 2: Commit or abort (20 minutes)
Participants vote: yes, yes, no. Then yes, yes, yes. Then yes, yes, and no reply before the timeout. What does the coordinator decide in each case?
Done when: three decisions.
Hint
One no, or a missing vote, means abort.
Easy 3: Saga steps (20 minutes)
Write the compensating step for: charge a card; reserve a seat; send a welcome email; create a shipment.
Done when: four steps, noting which cannot be undone cleanly.
Hint
A sent email cannot be unsent, so the compensation is a correction email.
Medium
Medium 1: In-doubt timeline (30 minutes)
Coordinator C, participants P1 and P2. All vote yes at second 5. C logs commit at second 6, sends commit to P2 at second 7 and crashes before sending to P1. P1's locks cover 10 rows. What does P1 do? What does P2 hold? When does it end?
Done when: a timeline and a description of recovery.
Hint
P1 cannot decide alone. It waits for C to restart and read its log.
Medium 2: Saga for a trip (30 minutes)
Design a saga for flight, hotel and car. List the steps, the compensations, the saga state stored at each step and the idempotency key for each request.
Done when: a table of three steps with compensation, state and key.
Hint
The idempotency key can be the saga id plus the step name.
Medium 3: Outbox trace (30 minutes)
Show the table rows and messages for an order service using an outbox when the relay crashes after publishing but before marking. What does the consumer see, and how does it cope?
Done when: a step list with rows and a de-duplication rule.
Hint
The consumer sees the same event id twice.
Hard
Hard 1: 2PC or saga (45 minutes)
A bank transfer between two shards of one database, and a refund spanning an order service, a payment provider and an email service. Choose 2PC or a saga for each and defend it with blocking, isolation and failure cases.
Done when: two decisions with three arguments each.
Hint
One database can run 2PC internally. Third parties will not join one.
Hard 2: Failure matrix (45 minutes)
For 2PC, list a crash of each participant and the coordinator at four moments (before prepare, after yes, after decision, after commit sent). State the outcome and whether anything blocks.
Done when: a table with at least eight cells.
Hint
Only the cases after "yes" and before the decision reaches everyone cause blocking.
Hard 3: Design checkout (50 minutes)
Design checkout for an online shop with services for stock, payment, orders and shipping. Pick sagas, outbox and idempotency keys. Show the happy path, a payment failure and a duplicate event, plus what the user sees while a refund is pending.
Done when: a design with three traces and the user-visible states.
Hint
Compensate in reverse order and make every step safe to repeat.