0
0
LLDsystem_design~7 mins

YAGNI (You Aren't Gonna Need It) in LLD - System Design Guide

Choose your learning style9 modes available
Problem Statement
Developers often add features or code for future needs that never happen. This leads to bloated, complex code that is hard to maintain and slows down development.
Solution
YAGNI advises to only build what is needed right now. By focusing on current requirements, the code stays simple and easier to understand. Future features are added only when they become necessary.
Architecture
Current Need
Build Feature
Future Assumptions
─────────┘

This diagram shows that only current needs trigger feature development, while future assumptions are ignored until they become real needs.

Trade-offs
✓ Pros
Keeps codebase simple and easier to maintain.
Reduces wasted development time on unused features.
Improves focus on delivering immediate value.
✗ Cons
May require refactoring when future needs arise.
Can cause repeated work if assumptions change frequently.
Some upfront design for extensibility might be missed.
Use when requirements are unclear or likely to change, and when rapid delivery of core features is critical.
Avoid when building safety-critical systems where anticipating future needs is essential to prevent failures.
Real World Examples
Basecamp
Basecamp emphasizes YAGNI to keep their project management tool simple and avoid feature bloat that confuses users.
Spotify
Spotify uses YAGNI to focus on core music streaming features first, adding new capabilities only when user demand is proven.
Code Example
The before code adds address and phone fields anticipating future needs, increasing complexity. The after code keeps only the current requirement, making the class simpler and easier to maintain.
LLD
### Before applying YAGNI (violating) ###
class UserProfile:
    def __init__(self, name):
        self.name = name
        self.address = None  # planned for future use
        self.phone = None    # planned for future use

    def set_address(self, address):
        self.address = address

    def set_phone(self, phone):
        self.phone = phone

### After applying YAGNI (applying) ###
class UserProfile:
    def __init__(self, name):
        self.name = name

# Add address and phone only when needed
OutputSuccess
Alternatives
Big Design Up Front (BDUF)
BDUF plans and designs all features before coding, unlike YAGNI which builds only what is needed now.
Use when: Choose BDUF when requirements are stable and system safety or compliance demands thorough upfront design.
Incremental Design
Incremental Design evolves the system step-by-step, balancing some upfront planning with YAGNI's minimal initial design.
Use when: Choose Incremental Design when some foresight is needed but flexibility is still important.
Summary
YAGNI prevents wasted effort by building only what is needed now.
It keeps code simple and focused on current requirements.
YAGNI requires balancing simplicity with readiness for future changes.