HomeChallengesRepsProblemsLeaderboardTake a challenge

Where the transaction ends

An order, an outbox message and a ledger entry, written by two SaveChanges calls with a crash-shaped gap between them. Decide where the unit of work actually ends and make the gap impossible.

Advanced20 min on the clock4 graded checks · 100 pointsPersistence with EF CorePro

AssumesAll Or NothingThe same all-or-nothing problem with no ORM in the way. Worth fifteen minutes before this one.

Graded by reading your code against the checklist below.

What you build

  • An explicit transaction spanning both saves
  • Commit only once both have succeeded
  • Roll back on any failure, and rethrow
  • The outbox row written in the same transaction as the order
  • The transaction disposed asynchronously

Done means

Either all three rows exist or none of them do, whatever moment the process dies at.

How it is graded

Published in full, before you start — every point is one of these and there is nothing else.

  1. Both saves sit inside one transaction+30All or nothing
  2. Commit happens once, after both saves+25All or nothing
  3. A failure rolls back and rethrows+25All or nothing
  4. The outbox row commits with the order+20Safe to repeat

What it teaches

All or nothingadvanced

A sequence of writes has to either all happen or none of them, because the state in between is one where the money has left one account and not arrived at the other.

Safe to repeatintermediate

A request that times out has not necessarily failed — you just did not hear back — so the client retries, and unless the write recognises that it has already happened the customer is charged twice.

The rest of Persistence with EF Core