Design an ATM
Intermediate · 22 min read · Low-Level Design, Case Studies: Advanced
State machine, cash dispensing chain and bank integration.
The ATM combines two classic patterns cleanly: a state machine for the session (card → PIN → transaction → eject) and a chain of responsibility for dispensing cash in denominations. It also tests how you handle failures that involve money and hardware.
What the interviewer expects
The full design in this lesson is longer than anything you'd write in one round. It's there so you understand the edge cases and can answer follow-up questions. In the round itself, aim for this:
1. Requirements
2. Session states
3. Class design
4. Cash dispensing with Chain of Responsibility
Each handler takes as many notes of its denomination as it can, then passes the remainder down. Crucially, we plan first and only commit if the whole amount can be served.
5. Withdrawal flow — money safety first
Points interviewers look for:
6. PIN handling
7. Patterns used
Interview questions
- How do you make sure a customer is never debited without receiving cash?
- Why use Chain of Responsibility for the cash dispenser?
Further reading
Key takeaways
- Model the session as a state machine; invalid operations are rejected per state.
- Dispense via a chain of denomination handlers: plan first, commit only if the full amount works.
- Money safety: plan → idempotent debit → dispense → reverse on failure → reconcile.
- PINs are verified by the bank; lock out after repeated failures.
Previous: Design a Rate Limiter (LLD) · Next: Design a Pub-Sub Message Broker