Crediting Deposits Safely When the Chain Reorganizes
Last updated: November 29, 2026
Quick Overview
Implement a deposit tracker that consumes blocks one at a time, credits a deposit once it has k confirmations, and correctly handles chain reorganizations by rolling back orphaned blocks and flagging any deposit that was already credited.
BitGo
November 29, 20260
0
0 solved
Implement a deposit tracker that consumes blocks one at a time, credits a deposit once it has k confirmations, and correctly handles chain reorganizations by rolling back orphaned blocks and flagging any deposit that was already credited.
BitGo detects incoming deposits across many chains and notifies clients when funds are confirmed; reorgs mean a transaction seen in one block can vanish or move. The interviewer wants a correct state machine and a clear policy for the rare case where credited funds disappear.
What the Interviewer Expects
- Detects a reorg by a parent-hash mismatch, not by height alone
- Walks back to the common ancestor and reverts deposits in orphaned blocks
- Counts confirmations as tip height minus block height plus one
- Emits a distinct event when credited funds are reversed
- Handles a deposit that reappears in the new branch without double crediting the ledger
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
- What if the parent is a block you have never seen?
- How do you choose k per chain?
- How does finality on proof-of-stake chains change this design?
- How should clients be told about a reversal?
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
Blocks arrive with height, hash, parent hash and the deposits to our addresses. Deposit states: seen, credited, pending (back in mempool or gone). Credit at k confirmations. On reorg, roll back ...
High-Level Design
Keep the recent chain as a list plus a hash index. If the new block's parent is not our tip, pop blocks until the tip is the parent. Every deposit in a popped block goes back to pending; if it had b...