Context
You are tasked with building a minimal bank-transfer payment orchestration service (e.g., ACH/SEPA) that schedules and executes outgoing payments. The system must persist all state and expose a simple HTTP API. Payments will move through a defined state machine (e.g., SCHEDULED → QUEUED → PROCESSING → SENT → SETTLED/FAILED), and their execution will be handled by background workers.
Requirements
Design and implement the following features:
- Cancel Payment
- Add an operation to cancel a previously scheduled payment.
- Only payments that have not been irreversibly sent downstream can be canceled.
- Define idempotent behavior, allowed states for cancellation, and race-condition handling for this operation.
- Extend Schedule Payment
- Ensure the
schedulePaymentoperation reports and persists both success and failure results. This applies to both the scheduling action itself and any subsequent downstream execution attempts. - Include idempotency for client retries and durable audit logs for all results.
- Ensure the
- Remove Obsolete Payment Cases
- Identify and remove any legacy or obsolete payment states or code paths within the system.
- Propose a safe data and code migration plan to ensure production data remains consistent throughout this process.
- Reporting
- Produce a report of outgoing transactions, sorted by total loss amount.
- Define "loss" precisely, including factors like returns/chargebacks and fees, and how recoveries/refunds affect this calculation.
- Provide a query or computation plan that aggregates and sorts transactions by the defined loss metric.
Deliverables
- API design for
schedulePaymentandcancelPayment(including request/response formats, status codes, and idempotency semantics). - The complete payment state machine and its associated concurrency rules.
- A detailed data model (tables/entities) for payments, attempts, events/audit logs, and financial adjustments like fees/returns.
- A clear reporting definition, accompanied by a query that generates the loss-sorted report.
- Identification of edge cases and a strategy for validation.
AI interview prep
Core dilemma
Ensuring strong consistency, idempotency, and fault tolerance for financial transactions across distributed systems, while maintaining auditability and supporting complex reporting requirements under high concurrency.
3 tradeoffs and 3 stress tests locked
Interview prep
Unlock the interviewer X-Ray rubric, tradeoff matrix, stress tests, clarifying questions, and key concepts.
Context
You are tasked with building a minimal bank-transfer payment orchestration service (e.g., ACH/SEPA) that schedules and executes outgoing payments. The system must persist all state and expose a simple HTTP API. Payments will move through a defined state machine (e.g., SCHEDULED → QUEUED → PROCESSING → SENT → SETTLED/FAILED), and their execution will be handled by background workers.
Requirements
Design and implement the following features:
- Cancel Payment
- Add an operation to cancel a previously scheduled payment.
- Only payments that have not been irreversibly sent downstream can be canceled.
- Define idempotent behavior, allowed states for cancellation, and race-condition handling for this operation.
- Extend Schedule Payment
- Ensure the
schedulePaymentoperation reports and persists both success and failure results. This applies to both the scheduling action itself and any subsequent downstream execution attempts. - Include idempotency for client retries and durable audit logs for all results.
- Ensure the
- Remove Obsolete Payment Cases
- Identify and remove any legacy or obsolete payment states or code paths within the system.
- Propose a safe data and code migration plan to ensure production data remains consistent throughout this process.
- Reporting
- Produce a report of outgoing transactions, sorted by total loss amount.
- Define "loss" precisely, including factors like returns/chargebacks and fees, and how recoveries/refunds affect this calculation.
- Provide a query or computation plan that aggregates and sorts transactions by the defined loss metric.
Deliverables
- API design for
schedulePaymentandcancelPayment(including request/response formats, status codes, and idempotency semantics). - The complete payment state machine and its associated concurrency rules.
- A detailed data model (tables/entities) for payments, attempts, events/audit logs, and financial adjustments like fees/returns.
- A clear reporting definition, accompanied by a query that generates the loss-sorted report.
- Identification of edge cases and a strategy for validation.