Design a BankSystem Class (Take‑home Project)
Goal
Design and document a BankSystem class that supports three operations:
-
createAccount(timestamp, customerId) -> bool
-
deposit(timestamp, customerId, amount) -> int
-
pay(timestamp, sourceAccountId, targetAccountId, amount) -> int
Assume this is an in-memory service intended for correctness and clarity (not persistence or distributed systems).
What to Produce
Provide a complete specification and design that covers:
-
Data Models
-
Define the core entities (e.g., Account, Transaction) and their fields.
-
Specify how balances and transaction records are stored and updated.
-
Identifier Semantics
-
Clarify what customerId and accountId represent and how they relate (e.g., 1:1 vs. 1:many).
-
Reconcile that deposit takes customerId while pay uses accountIds.
-
Validation Rules
-
Duplicate vs. nonexistent accounts.
-
Nonpositive amounts (zero or negative).
-
Insufficient funds for payments.
-
Any other constraints you deem important (e.g., overflow, same source/target).
-
Return Values
-
Define exactly what the bool and int returns mean in all cases (success and error).
-
If using error codes, enumerate them.
-
Data Structures
-
Describe the primary data structures (e.g., hash maps keyed by accountId) used to implement O(1) operations.
-
Operational Semantics
-
For each API, describe step-by-step how state changes and transaction records are appended.
-
Include how timestamps are used in records.
-
Complexity
-
Time and space complexity for each operation and overall storage.
-
Assumptions
-
State any reasonable assumptions you make (e.g., single-threaded, amounts in cents, integer timestamps).
You may include concise pseudocode to illustrate the implementation.