Implement scheduled payments and cancel
Company: Meta
Role: Software Engineer
Category: System Design
Difficulty: medium
Interview Round: Take-home Project
Add scheduled payments and cancellation: schedulePayment(timestamp, sourceAccountId, targetAccountId, amount, delay) -> String returns a paymentId. When current time reaches timestamp + delay, execute debits/credits in chronological order for that tick. Provide an API (e.g., runDue(timestamp) -> String) that returns a string summarizing the execution order, such as a concatenation of affected accountIds in the order executed. Implement cancel(paymentId) -> boolean to prevent execution if not yet processed. Scheduled payments count as outgoing spend and must update the top-N payers structure. Specify clock/concurrency assumptions, idempotency, and choose efficient data structures (e.g., maps for lookup, a min-heap by dueTime). Analyze complexities.
Quick Answer: This question evaluates skills in designing a reliable scheduled payments system with emphasis on API design, concurrency control, deterministic ordering, idempotency, cancellation semantics, leaderboard (top‑N) maintenance, data structures, and complexity trade-offs.