A Node wallet service lets customers spend the same balance twice under parallel requests and duplicates ledger rows when the payment SDK retries. Make the transfer path safe under concurrency, retries and bad input.
This is the practice version. Assessments always use a variant you have never seen.
/transferOur wallet service (Node.js) is losing money in production.
Idempotency-Key header, and finance sees
duplicate ledger rows.Make transfer() in src/transfer.js safe for production:
idempotencyKey must debit once and return the original ledger row.The public suite (npm test) covers the happy path only. A hidden suite runs after you submit. It
checks concurrency, retries and edge cases.
You may use the AI Copilot and your own agents. You will explain every line you keep in the Viva.