How to Approach System Design
System design interviews can be daunting. This guide provides a structured framework to help you navigate through the process effectively.
1. List Functional and Non-functional Requirements
The first step is to clarify the scope of the problem.
Functional Requirements
- Focus on 2-3 main features at the beginning.
- Add more detailed requirements as the discussion progresses.
- Example: For a URL shortener, functional requirements would be shortening a URL and redirecting.
Non-functional Requirements
- Clearly state details like Read/Write ratio.
- Discuss Consistency vs Availability (CAP Theorem).
- Define Latency and Throughput targets.
2. Back-of-the-envelope Calculation
Estimating the scale helps in making architectural decisions.
Common Formulas
- QPS (Queries Per Second):
DAU * Avg Requests/User / 86400 seconds - (Remember to mention the peak time and the average time QPS if necessary)
- Storage:
DAU * Avg Item Size * Retention Period - Unit Conversion:
1 PB = 1,000 TB1 TB = 1,000 GB1 GB = 1,000 MB1 MB = 1,000 KB1 KB = 1,000 B1 B = 8 bits
Key Principles
- Order of magnitude first: Give a rough estimate first, then refine it if necessary.
- Focus on scale: The goal is to understand the system’s scale, not to be mathematically perfect.
3. High-level Design
Once the requirements and scale are clear, move to the architecture.
- Draw a high-level architecture diagram: Identify the main components (Load Balancer, Web Servers, Database, Cache, etc.).
- Basic solution first: Ensure the “happy path” is working before addressing edge cases.
4. Design Deep Dive
The interviewer will usually pick one or two areas for a more detailed discussion.
- Identify interest: Find what the interviewer is interested in (e.g., database sharding, caching strategy, or message queues).
- Concept focus: Focus on high-level concepts and let the interviewer drive the depth.
- Clarify assumptions: Always ask clarifying questions and state your assumptions explicitly.
- Trade-offs: Always talk about trade-offs (e.g., why choose SQL over NoSQL).
5. Tips for Success
- Don’t memorize solutions: Understand the principles instead.
- Collaboration is key: Chat with your interviewer like discussing a project with a partner.
- Avoid over-engineering: Start simple and scale as needed.
- Stay positive: Don’t argue with your interviewer; listen to their hints.