System Design - Design Delayed/Scheduled Payment System
[ OK ]00194445-2e84-47f0-9ecc-4793b464b0fa — full content available
[ INFO ]category: System Design difficulty: unknown freq: first seen: 2026-05-28
[UNKNOWN][SYSTEM DESIGN]High Frequency
$catproblem.md
Design Delayed/Scheduled Payment System
Problem Statement
Design a delayed or scheduled payment system. A user or internal service can create a payment that should execute at a future time, cancel it before execution, and later inspect its status. The system should handle payments efficiently and ensure that payments are executed at the scheduled time.
Constraints
Scalability: The system should be able to handle a large number of scheduled payments.
Reliability: Ensure that payments are executed at the scheduled time, even in the case of system failures.
Consistency: The system should maintain accurate records of payment status and history.
Security: Protect sensitive payment information and prevent unauthorized access.
Examples
Creating a Scheduled Payment:
A user schedules a payment of $100 to be executed on a specific date.
The system records the payment details and schedules it for execution.
Canceling a Scheduled Payment:
Before the scheduled execution date, the user decides to cancel the payment.
The system cancels the payment and updates its status accordingly.
Inspecting Payment Status:
The user wants to check the status of a scheduled payment.
The system provides the current status of the payment, such as "scheduled", "executed", or "canceled".
Hints
Database Design: Consider how to store payment information, including scheduled execution time, status, and any other relevant details.
Scheduling Mechanism: Implement a mechanism to trigger payment execution at the scheduled time, such as using cron jobs or a task queue.
Concurrency Handling: Ensure that the system can handle multiple users creating, canceling, and inspecting payments simultaneously.
Fault Tolerance: Design the system to handle failures, such as database outages or network issues, without losing scheduled payments.
status can have values like "scheduled", "executed", or "canceled".
Scheduling Mechanism:
Use a task queue (e.g., RabbitMQ, AWS SQS) to manage scheduled tasks.
Implement a worker service that polls the queue and executes payments at the scheduled time.
API Endpoints:
POST /payments: Create a new scheduled payment.
GET /payments/:id: Retrieve the status of a specific payment.
DELETE /payments/:id: Cancel a scheduled payment.
Concurrency Control:
Use database transactions to ensure atomicity when updating payment status.
Implement rate limiting to prevent abuse of the system.
Fault Tolerance:
Use a distributed database system with replication to ensure data availability.
Implement retry mechanisms in the worker service to handle transient failures.
By following these guidelines, you can design a robust and efficient delayed/scheduled payment system that meets the requirements outlined in the problem statement.