Design a basic bank system API
Company: Meta
Role: Software Engineer
Category: System Design
Difficulty: hard
Interview Round: Take-home Project
Design and implement an in-memory bank system. Provide an interface/class BankSystem with methods: bool createAccount(long timestamp, String customerId); int deposit(long timestamp, String customerId, int amount); int pay(long timestamp, String sourceAccountId, String targetAccountId, int amount). Define the data model, invariants (e.g., no negative balances), return semantics (e.g., new balance vs. error codes), and time/space complexity. Use hash maps (not lists) for constant-time account and transaction lookups. Address edge cases: duplicate or out-of-order timestamps, insufficient funds, unknown accounts, idempotency of retries, and basic concurrency assumptions.
Quick Answer: This question evaluates a candidate's ability to design and implement an in-memory banking API, focusing on data modeling, API semantics, invariants (such as monotonic timestamps and non-negative balances), idempotency, and basic concurrency control.