Implement held transfers with accept/cancel
Company: Meta
Role: Software Engineer
Category: System Design
Difficulty: hard
Interview Round: Take-home Project
Add a two-phase transfer flow with holds: transfer(timestamp, targetAccountId, amount) -> String returns transferId and places a hold on the source account’s funds; accept(timestamp, accountId, transferId) -> boolean finalizes the transfer to the target; cancel(transferId) -> boolean releases the hold and restores availability. Define available vs. ledger balance semantics, duplicate/expired requests, idempotency, error handling for invalid transferIds, and atomicity. Use hash maps to track all transfers and pending transfers (avoid list scans). Provide time/space complexity for each operation.
Quick Answer: This question evaluates system-design and concurrent-systems competencies, including two-phase fund transfer semantics, holds and TTLs, idempotency, atomicity, error handling, efficient hash-map data structures, and time/space complexity reasoning, and it belongs to the System Design domain.