Make a ledger safe under concurrent transfers

MediumConcept20 minSWEREPro outline

The question

Your bank ledger works in a single thread. Now many threads call transfer(src, dst, amount) at the same time.

What can go wrong, and how do you make it correct without making every transfer wait on one global lock?

What the interviewer is looking for

  • Names the race: read-check-write on balances
  • Explains deadlock when two transfers lock accounts in opposite orders
  • Fixes it with a consistent lock order
  • Weighs a global lock against per-account locks
  • Mentions testing concurrency

Your answer

Saved in this browser only. Nobody else sees it.

Why this question

Written by BlogLLM in the style of a publicly reported Anthropic question type: problems that stress data mutation, concurrency and multithreading.

Reported in: interviewing.io

Practice question written by BlogLLM based on publicly reported interview formats. Not an official Anthropic question.