System Design: Scheduled Payments Execution
Context
You are building a balance-transfer service (e.g., an internal wallet). Users can schedule a payment to move funds from a source account to a destination account at a future timestamp.
Requirements
Design a feature that supports the following:
-
A user can schedule a payment at a future UTC timestamp.
-
The system executes the payment at the scheduled time.
-
On execution, the system updates the involved account balances atomically.
-
If the source balance is insufficient at execution time, the payment is skipped (no balance changes).
Assumptions (minimal to make the problem well-scoped)
-
Single region deployment; relational database available.
-
Timestamps are stored and compared in UTC with second-level precision.
-
Payments are in a single currency (multi-currency handling is out of scope).
-
“Execute at the scheduled time” means trigger at or immediately after the timestamp (sub-second jitter is acceptable in distributed systems).
What to Deliver
Provide a design that covers:
-
High-level architecture and components.
-
Data model and key constraints.
-
Execution flow (scheduling and run-time) and concurrency control.
-
Handling of insufficient funds, idempotency, and failure/retry.
-
Brief API sketch and operational considerations (monitoring, background jobs).