Design a Transaction/Account component that supports deposits and withdrawals.
Assume you are building a backend library or service used by other parts of a financial application.
Requirements
-
Maintain an account
balance
.
-
Support operations:
-
deposit(amount)
-
withdraw(amount)
-
getBalance()
-
Record a
transaction history
(at minimum: id, type, amount, timestamp, status).
Constraints / edge cases to handle
-
Amount must be positive.
-
Prevent the balance from becoming negative (or clearly define overdraft rules).
-
Handle
concurrent requests
safely (e.g., two withdrawals at the same time).
-
Ensure operations are
atomic
and leave the account in a consistent state.
-
(Optional, if time) Support
idempotency
so retrying the same request doesn’t double-charge.
Explain your design choices, data structures, and how you would test it.