Implement a Transfer Lifecycle State Machine With Safe Replays
Last updated: November 29, 2026
Quick Overview
Model a money transfer that moves through created, funding, funded, compliance hold, sent to partner, paid out, failed, refunding, refunded, and cancelled, rejecting illegal transitions and safely ignoring replayed events.
Remitly
November 29, 20260
0
0 solved
Model a money transfer that moves through created, funding, funded, compliance hold, sent to partner, paid out, failed, refunding, refunded, and cancelled, rejecting illegal transitions and safely ignoring replayed events.
A Remitly transfer is driven by events from card processors, compliance screening and payout partners, and those events can arrive twice or out of order. The interviewer checks that you make legal transitions explicit, keep an audit trail, and make event handling idempotent.
What the Interviewer Expects
- Encodes allowed transitions as data rather than scattered if statements
- Rejects illegal transitions with a clear error
- Makes event application idempotent using event ids
- Keeps an append-only history for audit and support
- Discusses persistence with optimistic concurrency
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
- A payout partner reports PAID after you already marked the transfer FAILED and started a refund. What do you do?
- How would you persist this so two workers cannot apply conflicting transitions?
- Where would you put side effects like sending a push notification?
- How do you add a new state without breaking existing transfers?
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
Terminal states are paid out, refunded, cancelled. Funds can only be refunded after they were captured, compliance holds can release back to funded or go to refund, and partner failures lead to refund...
High-Level Design
An enum of states plus a transition table. A Transfer aggregate holds state, a version number, applied event ids and a history list. apply checks idempotency, validates the transition, then record...