How to do system design
How to do system design
It is a common interview question to design a system. In this article, I will share a useful approach to system design interviews. This approach includes four steps:
- Confirm the requirements of the question.
- Complete the overall design of the system.
- Deepen into the modules of the system.
- Consider the trade-offs and extentions of the system.
Step 1: Clarify the Requirements
Before designing a system, confirm what the interviewer expects. Do not start with the architecture immediately.
You should clarify four areas:
- Functional requirements: What are the system’s main features?
- Traffic: How many users and requests should it support?
- Performance: What response time and throughput are expected?
- Reliability: What availability, consistency and fault tolerance are required?
For example, if the interviewer asks you to design a “reliable system”, ask what reliability means in this scenario:
- Does the system require 99.9% or 99.99% availability?
- Can it tolerate temporary data inconsistency?
- Is any data loss acceptable?
- How quickly should it recover from a failure?
You should also estimate the expected QPS.
QPS, or Queries Per Second, measures how many requests a system processes each second. For example, if a system receives 10 million requests per day:
However, traffic is rarely evenly distributed. If peak traffic is five times the average, the system should support approximately 580 QPS.
Avoid assuming that a web server or database can always handle a fixed number of requests. Actual capacity depends on hardware, request complexity, database queries, caching, network latency and other factors.
As a rough reference:
| Component | Approximate throughput |
|---|---|
| Application server | Hundreds to tens of thousands of QPS |
| Relational database | Hundreds to tens of thousands of operations per second |
| Distributed NoSQL database | Thousands to hundreds of thousands of operations per second |
| Redis or Memcached | Tens of thousands to millions of operations per second |
These figures are only starting assumptions. In a real system, capacity should be verified through benchmarking and load testing.
A good way to begin a system design interview is:
Before designing the architecture, I would like to clarify the core features, expected traffic, performance targets and reliability requirements.
Step 2: Overall Design
After clarifying the requirements, you can start designing the system architecture. A common approach is to use a layered architecture, which includes the following layers:
- Client Layer: The user interface
- Application Layer: The business logic and application services
- Data Layer: The database and data storage
Step 3: Deep Dive into Modules
After completing the overall design, you can dive deeper into each module. For example, if you are designing a social media system, you can discuss the design of the user module, post module, comment module, and notification module. For each module, consider the following aspects:
- Data model: What are the main entities and their relationships?
- API design: What are the main APIs and their request/response formats?
- Database design: What database schema and indexes are needed?
For instance, when you design a short link system, you may need to consider:
What is the purpose of designing this short link system?
The main purpose is to convert a long URL into a short and easy-to-share URL, then redirect users to the original URL. It may also support tracking, expiry, custom aliases, and analytics.
Estimate the scale:
Estimate how many short links are created per day, how many redirect requests happen per second, the read/write ratio, and how much storage is required. A short link system is usually read-heavy.
Define the core APIs:
For example, POST /shorten to create a short URL and GET /{shortCode} to redirect users to the original URL.
Design the data model:
Store the mapping between shortCode and originalURL, together with fields such as creation time, expiry time, and user ID.
Decide how to generate the short code:
You can use Base62 encoding, random strings, or a distributed unique ID plus Base62. The key concern is avoiding duplicate short codes and handling collisions.
Choose the database:
The database needs to efficiently support shortCode -> originalURL lookups. You should also consider indexing, replication, and sharding when the data grows.
Add caching:
Since redirect traffic is much higher than link-creation traffic, popular short links can be cached in Redis to reduce database load and improve response time.
Decide the redirect strategy:
Consider whether to use HTTP 301 or 302. 301 can reduce server traffic because browsers may cache the redirect, while 302 gives the system more control and is usually better for analytics.
Consider scalability:
Use stateless application servers, load balancers, Redis clusters, database replication, and sharding to support large traffic volumes.
Consider analytics:
If you need to record clicks, device information, location, or campaign data, analytics should usually be processed asynchronously through something like Kafka so it does not slow down redirects.
Consider reliability and failure handling:
Think about what happens when Redis is unavailable, the database fails, a link expires, or a short code does not exist.
Consider security and abuse prevention:
Add rate limiting, malicious URL detection, access control, and possibly link expiration to prevent the service from being abused.
Step 4: Trade-offs and Extensions
Finally, consider the trade-offs and extensions of the system. For example, if you are designing a social media system, you can discuss how to handle high traffic, how to ensure data consistency, and how to add new features in the future.






