Design an ATM System

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

Problem Statement

Design the Low-Level Design (LLD) of an ATM (Automated Teller Machine) system.


The system should simulate how a customer interacts with an ATM to perform banking operations such as cash withdrawal, deposit, and balance inquiry.


Your goal is to define the core classes, relationships, and workflows that model how the ATM functions internally — focusing on object-oriented design principles like abstraction, encapsulation, and polymorphism.


🧠 Functional Requirements

Card Authentication

•A user inserts a debit/credit card.
•The system validates the card details (card number, PIN, account linkage, and status).

Account Operations

•Once authenticated, the user can:

Check Balance

Withdraw Cash

Deposit Cash

Transfer Funds (optional extension)

Change PIN (optional)

Cash Withdrawal


•Verify:
•Sufficient account balance
•Sufficient ATM cash availability
•Dispense appropriate denominations (e.g., ₹2000, ₹500, ₹100 notes).
•Update the account balance and ATM cash inventory.

Deposit Cash


•User can insert cash into the deposit slot.
•System validates and credits it to the user’s account.


Balance Inquiry


•Display current available balance from linked bank account.


Session Management


•Each card session has a timeout and is terminated after a fixed duration or after the transaction completes.


Error Handling


•Handle invalid PINs, insufficient balance, ATM cash exhaustion, or invalid card.


🚫 Non-Functional Requirements


•Secure card and PIN handling (no plain-text storage).
•Transaction atomicity — rollback on failure.
•Modular and extensible design (e.g., add new transaction types easily).
•Support multiple ATMs connected to the same bank system.


🧱 Suggested Classes


ClassResponsibility


ATM


Represents the physical ATM machine — interacts with hardware (card reader, cash dispenser).


Card


Represents a user’s debit/credit card (card number, expiry, PIN, linked account).


BankAccount


Represents the user’s account (balance, account number, type).


User


Represents the account holder.


Transaction


Abstract base class for different transaction types.


WithdrawTransaction, DepositTransaction, BalanceInquiryTransaction


Concrete classes extending Transaction for specific operations.


CashDispenser


Handles dispensing of notes based on available denominations.


CashDepositSlot


Handles cash deposits and validations.


ATMState (Enum or Interface)


Represents the current state of ATM (Idle, CardInserted, Authenticated, Processing, etc.).


BankServer / BankService


Simulates backend communication for balance checks, fund transfers, etc.


🔄 Example Flow


Insert Card


•User inserts the card.
•ATM validates the card and prompts for PIN.


Enter PIN


•System verifies PIN against the bank server.
•On success, user is authenticated.


Select Operation


•Options displayed: Withdraw, Deposit, Balance Inquiry, Exit.


Withdraw Cash


•User enters amount (e.g., ₹2500).
•ATM checks:
•Account balance ≥ ₹2500
•ATM has enough cash in required denominations
•Dispenses ₹2000 + ₹500
•Updates account balance and ATM inventory.
•Prints receipt.


Eject Card


•Session ends; card is returned.


🧪 Example Input / Output


Input:

1 2Card Inserted: 1234-5678-9012-3456 3Enter PIN: 1234 4Select Option: Withdraw 5Enter Amount: 2500


Output:

1 2Dispensed: ₹2000 + ₹500 3Remaining Balance: ₹7500 4Transaction Successful. 5Card Ejected.


⚙️ Constraints


•ATM cash capacity: ≤ ₹10,00,000
•ATM should support denominations: [₹2000, ₹500, ₹100]
•Card attempts: 3 tries before blocking
•Session timeout: 60 seconds of inactivity


🎯 Goals


Your design should:


•Clearly separate ATM logic, bank interaction, and transaction handling.
•Follow OOP best practices — use abstract classes and interfaces where necessary.
•Ensure the system can easily integrate:
•Multiple transaction types
•Different ATM models
•External services (e.g., Bank API)


✅ In short:


Design a modular, object-oriented ATM system that supports card authentication, cash withdrawal, deposits, and balance checks — ensuring clean separation between ATM operations and backend banking logic.

Solution

Comments