Low-Level Design Tutorial 0/42 lessons ~6 min read Lesson 29

    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.

    Course progress0%
    Focus
    9 guided sections
    Practice signal
    Examples included
    Career prep
    Interview Q&A included

    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

    1. List must-have use cases only.
    2. Park 'nice-to-have' on board edge labeled future.
    3. Implement hooks only when second variant requested.
    4. Avoid empty strategy interfaces with one impl.
    5. When extension asked, add minimally.
    6. Explain trade-off: speed now vs cost of later refactor.

    Informative example

    ATM without speculative crypto wallet until required:

    java
    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;
    }
    @Override
    public 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?
    Do not implement functionality until it is actually needed.
    Q2BeginnerYAGNI vs planning for extension?
    Design clear extension seams; implement extra variants only when required.
    Q3IntermediateYAGNI in a 45-minute interview?
    Core use cases only; defer extras unless interviewer adds them.
    Q4IntermediateWhen does YAGNI hurt?
    When ignoring known upcoming requirement confirmed by product — then implement.
    Q5AdvancedInterviewer asks 'make it extensible' without specifics.
    Identify likely axis (vehicle type), add interface + one impl, not five unused classes.

    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.

    Ready to mark this lesson complete?Track your journey across the entire course.