HomeChallengesRepsProblemsLeaderboardTake a challenge

All Or Nothing

The debit succeeded. The credit threw. The money is now nowhere. Build the thing that makes a sequence of writes either all happen or none of them.

Advanced25 min on the clock5 graded checks · 100 pointsThe Write Side
Graded by running your code against real cases.

What you build

  • runAll(state, steps) — apply each step in order to the result of the last
  • If any step throws, return the state exactly as it was handed to you
  • Report the error rather than swallowing it
  • runAll(state, steps, invariant) — a broken invariant also rolls back
  • transfer(accounts, fromId, toId, amount) built on runAll

Done means

A failed transfer leaves every balance exactly where it started.

How it is graded

Published in full, before you start — every point is one of these and there is nothing else. Each one runs your code; it is not a search for keywords.

  1. Every step applies, in order+20All or nothing
  2. A throwing step leaves the state untouched+30All or nothing
  3. The error is reported, not swallowed+15Error handling
  4. A broken invariant rolls back too+15All or nothing
  5. A failed transfer loses no money+20All or nothing

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.

The rest of The Write Side