Bird
0
0
LLDsystem_design~7 mins

Requirements and use cases in LLD - System Design Guide

Choose your learning style9 modes available
Problem Statement
Without clear requirements and use cases, development teams often build features that do not meet user needs or business goals. This leads to wasted effort, missed deadlines, and software that users find confusing or unusable.
Solution
Gathering detailed requirements and defining use cases helps teams understand exactly what the system must do and how users will interact with it. Use cases describe specific scenarios of system usage, guiding design and testing to ensure the final product matches expectations.
Architecture
Stakeholders
Requirements
System Design

This diagram shows how stakeholders provide input to gather requirements, which then inform use cases. Use cases guide system design and test case creation.

Trade-offs
✓ Pros
Ensures development aligns with user needs and business goals.
Helps identify edge cases and exceptions early through use cases.
Improves communication among stakeholders, designers, and developers.
Facilitates better testing by defining clear scenarios.
✗ Cons
Requires time and effort upfront, which can delay initial development.
May lead to over-documentation if not managed carefully.
Changing requirements can cause rework if use cases are rigid.
Use when building new systems or features where user interaction and business goals must be clearly understood, especially for projects with multiple stakeholders or complex workflows.
Avoid heavy use when making trivial changes or bug fixes where requirements and use cases are obvious and well-known.
Real World Examples
Amazon
Uses detailed use cases to model customer shopping flows, ensuring features like one-click ordering and recommendations meet real user behaviors.
Uber
Defines use cases for rider and driver interactions to handle complex scenarios like surge pricing and ride cancellations.
LinkedIn
Captures use cases for networking, messaging, and job applications to align features with professional user needs.
Code Example
The before code shows a simple class without clear steps or separation of concerns. The after code models a use case with explicit steps, making the flow clear and easier to maintain.
LLD
### Before: No clear use case structure
class Order:
    def __init__(self, items):
        self.items = items
    def process(self):
        # process order without clear steps
        pass


### After: Use case driven design
class UseCase:
    def execute(self):
        raise NotImplementedError

class PlaceOrderUseCase(UseCase):
    def __init__(self, order):
        self.order = order
    def execute(self):
        self.validate_order()
        self.process_payment()
        self.confirm_order()
    def validate_order(self):
        # validation logic
        pass
    def process_payment(self):
        # payment logic
        pass
    def confirm_order(self):
        # confirmation logic
        pass
OutputSuccess
Alternatives
User Stories
User stories are brief, informal descriptions of features from the user's perspective, focusing on value rather than detailed scenarios.
Use when: Choose user stories when agile, iterative development is preferred and detailed upfront documentation is less critical.
Prototyping
Prototyping involves creating early models of the system to gather feedback instead of relying solely on written requirements and use cases.
Use when: Choose prototyping when visual feedback and user interaction testing are more effective than textual descriptions.
Summary
Clear requirements and use cases prevent building the wrong features.
Use cases describe how users interact with the system in specific scenarios.
They improve communication, design, and testing throughout development.