HomeChallengesRepsProblemsLeaderboardTake a challenge

The concurrency token

Two people reserve the last unit of stock within a second of each other and both succeed. Give the row a version, let the second write fail, and turn that failure into something the caller can act on.

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

AssumesThe Lost UpdateThe lost update, taught in JavaScript first. This stage is the same race with a row version on it.

See also“Something went wrong”The JavaScript version: an error class with a code and a redacted context, graded by running it.

Graded by reading your code against the checklist below.

What you build

  • A row version on the entity
  • Configured as a concurrency token
  • DbUpdateConcurrencyException caught, not left to bubble
  • The stored values reloaded from the database
  • A deletion distinguished from a modification
  • A domain exception carrying what the value actually is now

Done means

The second writer fails loudly, and the failure says what the value is now.

How it is graded

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

  1. The row carries a version+25The lost update
  2. The concurrency failure is caught+25The lost update
  3. The stored values are read back+20The lost update
  4. A deleted row is told apart from a changed one+15Failing in a shape callers can read
  5. The caller gets a domain error, not an EF one+15Failing in a shape callers can read

What it teaches

The rest of Persistence with EF Core