HomeChallengesRepsProblemsLeaderboardTake a challenge

Orphans and Tombstones

A customer was deleted. Their orders are still in the revenue report, attached to a customer id that no longer resolves. Delete properly, and be able to undo it.

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

What you build

  • softDelete(rows, id, now) — mark it gone, do not remove it
  • Deleting something already deleted must not rewrite when it happened
  • active(rows) — everything not deleted
  • cascadeDelete(customers, orders, customerId, now) — their orders go too
  • restore(rows, id) — bring it back

Done means

Deleting a customer hides their orders and nobody else, and restoring works.

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. softDelete marks the row instead of removing it+20Deleting without losing
  2. Deleting twice does not move the timestamp+15Safe to repeat
  3. active hides what was deleted+15Deleting without losing
  4. Their orders go too, and nobody else's+30Deleting without losing
  5. restore brings it back+20Deleting without losing

What it teaches

Deleting without losingintermediate

Removing a row breaks everything pointing at it, so a delete usually marks the record instead — which keeps the references resolving, makes the action undoable, and forces every read path to remember to filter.

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 The Write Side