Design ATM withdrawal system

Difficulty: MEDIUMCategory: LLDFrequency: 1Asked On 2025-05-15

Problem Statement

Design and implement an ATM withdrawal system that enables users to:


•Insert their card, authenticate with a PIN,
•Select withdrawal amount,
•Validate account balance and ATM cash availability,
•Dispense cash and generate a transaction receipt.


The design should focus primarily on the withdrawal operation, not on other ATM features like deposits or fund transfers.


✅ Functional Requirements


Card Authentication

•The user must insert a valid card and enter the correct PIN.
•System validates credentials with the bank server.

Withdrawal Request

•User selects an amount to withdraw.
•System checks if:
•The user’s account has sufficient funds.
•The ATM has enough cash in appropriate denominations.

Cash Dispensation

•Dispense the requested amount using available notes (e.g., 2000, 500, 100).
•Update ATM balance and user’s account balance.

Transaction Receipt

•Print or display the transaction details.

Error Handling

•Handle insufficient funds, invalid PIN, or ATM cash shortage gracefully.


⚙️ Non-Functional Requirements


Aspect with Description


Security

Mask PIN, validate card securely, prevent duplicate transactions.


Extensibility

Support additional operations later (deposit, transfer).


Maintainability

Each component (card reader, cash dispenser, bank service) should be modular.


Scalability

Should work with multiple bank integrations.


🧩 Key Components / Classes


Component with Responsibility


ATM

Entry point coordinating operations between components.


CardReader

Reads and validates the user’s card.


BankServer / AccountService

Validates PIN, checks balance, debits account.


CashDispenser

Handles physical cash distribution logic.


Transaction

Represents a withdrawal transaction with status.


ReceiptPrinter

Prints or displays transaction receipts.


UserSession

Tracks user state during ATM operations.


💡 Design Considerations


•Use State Design Pattern — ATM can be in states like Idle, HasCard, Authenticated, TransactionInProgress.
•Use Strategy Pattern for cash dispensing algorithms (e.g., optimal note combination).
•Use Observer Pattern for alerting when ATM cash runs low.


🧠 Discussion Points (for Interviews)


•How would you ensure thread-safety if multiple ATMs access the same account server concurrently?
•How would you handle network failures during withdrawal?
•How would the system sync balances between ATM and bank server?
•How can you extend this design to support deposits or balance inquiries?


🧾 Final Interview Prompt

Design a low-level system for ATM withdrawal.
The system should handle authentication, balance verification, cash dispensing, and transaction completion.
Your design must include appropriate classes, relationships, and interactions between hardware components (CardReader, CashDispenser) and software components (BankServer, Transaction).
Discuss possible design patterns, error handling, and extensibility.


Solution

Comments