YAGNI Principle
You Aren't Gonna Need It (YAGNI) says implement only what requirements demand today — not speculative features 'we might need multi-currency someday' without evidence.
Introduction
You Aren't Gonna Need It (YAGNI) says implement only what requirements demand today — not speculative features 'we might need multi-currency someday' without evidence.
In LLD interviews, YAGNI keeps you inside time limits. Build parking for cars and trucks given; add motorcycles when interviewer asks. Speculative plugin frameworks waste precious minutes.
YAGNI fights gold-plating while still leaving clean extension points at real variation axes.
Understanding the topic
Key concepts
- No code for hypothetical future requirements.
- Extension points at known variation, not every axis.
- Interview scope = given requirements + explicit extensions.
- YAGNI vs OCP: prepare to extend, don't implement unused variants.
- Document deferred features explicitly.
- Refactor when new requirement arrives — acceptable cost.
Step-by-step explanation
- List must-have use cases only.
- Park 'nice-to-have' on board edge labeled future.
- Implement hooks only when second variant requested.
- Avoid empty strategy interfaces with one impl.
- When extension asked, add minimally.
- Explain trade-off: speed now vs cost of later refactor.
Informative example
ATM without speculative crypto wallet until required:
public interface WithdrawHandler {Result withdraw(Account account, Money amount);}public final class CashWithdrawHandler implements WithdrawHandler {private final CashDispenser dispenser;public CashWithdrawHandler(CashDispenser dispenser) {this.dispenser = dispenser;}@Overridepublic Result withdraw(Account account, Money amount) {if (!account.debit(amount)) return Result.failed("insufficient");return dispenser.dispense(amount) ? Result.ok() : Result.failed("hardware");}}public final class Atm {private final WithdrawHandler withdrawHandler;public Atm(WithdrawHandler withdrawHandler) {this.withdrawHandler = withdrawHandler;}public Result withdraw(Account account, Money amount) {return withdrawHandler.withdraw(account, amount);}}
WithdrawHandler allows future check dispenser — but only CashWithdrawHandler exists until interviewer requests checks.
Real-world use
Real-world applications
- Scoping interview design to given actors.
- Sprint planning against backlog only.
- Avoiding unused admin APIs in MVP.
Best practices
- Clarify scope before building speculative modules.
- Write TODO on board, not in code, for deferred items.
- Clean seams without unused implementations.
- Revisit YAGNI when requirements change — then implement.
- Pair with KISS for interview pacing.
Common mistakes
- Building payment providers not in prompt.
- Generic metadata framework for fixed attributes.
- Multi-tenant design for single-tenant problem.
- Rejecting all abstractions — YAGNI is not no interfaces.
Advanced interview questions
Q1BeginnerWhat is YAGNI?
Q2BeginnerYAGNI vs planning for extension?
Q3IntermediateYAGNI in a 45-minute interview?
Q4IntermediateWhen does YAGNI hurt?
Q5AdvancedInterviewer asks 'make it extensible' without specifics.
Summary
Build only what requirements need now. Defer speculative features explicitly. Extension seams yes, unused code no. Interview time favors focused core design. Refactor when real new requirements land.