Make Direct Debit Collection Jobs Idempotent Under Retries
Last updated: November 29, 2026
Quick Overview
A nightly job submits Direct Debit collections for every bill due that day, and it sometimes crashes or is re-run. Explain how you would guarantee each bill is collected at most once, and sketch the code.
Fuse Energy
November 29, 20260
0
0 solved
A nightly job submits Direct Debit collections for every bill due that day, and it sometimes crashes or is re-run. Explain how you would guarantee each bill is collected at most once, and sketch the code.
Double-charging a customer is one of the fastest ways for an energy supplier to generate complaints and regulator attention, and Fuse's backend engineers have a fintech heritage where idempotency is table stakes. The interviewer checks that you reason about crash points between your database and the payment provider, not just about deduping rows.
What the Interviewer Expects
- Identify the crash windows: before submit, after submit but before recording, after recording
- Use a natural idempotency key such as (account, bill) with a unique constraint
- Pass the same key to the payment provider so it dedupes too
- Record intent before the external call, outcome after it
- Make reruns safe and observable
Key Topics to Cover
How to Approach This
- Apply SOLID principles. Single Responsibility makes code testable, Open/Closed makes it extensible.
- Choose data structures based on access patterns, not familiarity.
- Prefer immutable data and message passing over shared mutable state for concurrency.
- Design APIs with RESTful conventions, versioning, meaningful errors, and pagination from day one.
Possible Follow-up Questions
- The provider does not support idempotency keys. What do you do?
- How do you handle a collection that the bank later reports as failed?
- Two workers pick up the same account concurrently. What stops a double submit?
- How would you test this behaviour?
Sharpen Your Skills on Codemia
Practice similar problems with our interactive workspace, get AI feedback, and track your progress.
Practice System Design ProblemsSample Answer
Requirements
Every bill due today should result in exactly one collection request at the payment provider, even if the job crashes at any line and is rerun any number of times, or two job instances overlap. Collec...
High-Level Design
Three crash windows matter: (1) before any record, harmless; (2) after the provider accepted the request but before we stored the result, the dangerous one; (3) after storing, harmless if reruns check...