How to approach System Design Interview questions step by step
System design is probably the last technical round question that you will face in any interview process. This type of question is for sure asked in top companies such as Amazon, Microsoft, Google, Uber etc. or any other start ups .
Anyhow system design questions are very interesting and fun to learn.
Today I will talk about some of the steps that you can follow while approaching a system design question.
Step 1: Requirements:
Interview will probably start with a very vague problem statement like how would design a website like amazon/airbnb/ twitter ?
This type of well known websites/systems gives both interviewer and interviewee a common ground talk about.
The very first step is to identify the different main use cases and write them down.
Since the system will be very broad and there will be many use cases so Interviewer will ask you to probably delve into one or two specific part.
For example, let’s say the question was to design Twitter.
Use cases:
1. Allow users to tweet
2. Allow users to follow other users
3. Present user with a news feed of their interest
4. Allow users to search and discover news / users / tweets
5. allow advertiser to show adds to users
Here you will probably asked to address the first three use cases and discard the rest.
Step 2: High Level Scale:
In many system design tutorials you will see that it is suggested to come up with some mathematics regaring the system such as :
a. how many qps
b. storage requirements
c. how much computing power will be required
Although in my opinion starting doing the math at the very begining of interview is little bit counter intuitive and does not add much value.
All it tells the interviewer is that you have studied few system design interview tutorial.
Rather at this stage just convey that you undersatnd the scale of the problem and you are going to consider it in your design.
If the scale is not clear in the begining then feel free to ask the questions.
For example if you are asked to design a restaurant reservation management system clarify whether he is looking for a system such as Yelp/Zomato or is he looking for design of a software that a particular restaurant will use to manage their table reservations internally.
So coming back to the twitter design use case you probably can state that twitter has 1 billion toSo coming back to the twitter design use case you probably can state that twitter has 1 billion total users and probably 30% of them are actively engaged.
Step 3: Identify System Components:
At this step on a high level just point down the different modules/components that you will need to support the functionality of the overall system.
Dont yet bother to start designing the db model.
Few modules will be self explanatory and common to all system design problems . For example:
a. login service
b. user/customer service
c. payment-service
d. notification service
Next identify the components you will need to support the specific use cases that you are asked to support. These components you can identify by going through the use cases /requirements.
Taking the twitter example again :
1. Allow users to tweet
a. tweet-service — — this will probably have an API: postTweet(tweet)
2. Allow users to follow other users
Here you will probably need some components like :
a. user-discovery-service — — this will probably have an API: List<Users> searchUser(Username)
b. recommend-user-to-fllow-service — — this will probably have an API: List<Users> recommendUsersToFollow(Cuurent User)
c. follow-other-user-service — — — — this will probably have an API: followUser(current User, user To follow)
3. Present user with a news feed of their interest
a. user-feed-generation service
b. user-feed-retrieval service
Step 4: Design the Data model
Now its time to design how the data model will look like.
Suggestion , design the data model component by component.
Consider the CAP Theorem for each components :
identify what is most important Consistency or Availability.
Is latency ok ? or does the system has to be realtime ?
Again consider it for each component separately.
For example ,
In the tweet-service think what is the simple and best way to store a simple tweet.
You probably can have a simple table named tweet with user name and tweet information.
When you come to user-feed-retrieval-service think what is the best way to have the data that would be optimal for this service.
It would be best if you dont have to find all the tweets from all the people you follow by joining multiple tables. It would be better to assume that you already have the Feed prepared at one place.
Step 5: Connect the Components:
At this step start connecting the different components.
Best approach here is to start going by the use cases and as you go connect the different components . While connecting the components you can add more components if needed.
In the twitter use case you probably have identified that the tweet-service would probably need to feed some data to user-feed-generation service which would in turn prepare the data for user-feed-retrieval service .
Step 6: Production Readiness
Till now you have designed a basic system. Now you need to make it ready for production.
You need to consider :
1. Caching — can it help to reduce latency
2. SQL/NoSQL — make a choice and be ready to explain why
3. Scale — explain how each component can scale.
do you need sharding ? master-slave architecture ? read-replicas ?
how to scale your computing and storage capability ?
Possibally this is the step where you can show off the mathematical calculations and come up with the numbers that prove your design supports the scale.
4. System failovers ? Reliability ? Redundancy ? Rate limiting ? Consistent Hashing ?
5. Concurrency handling ? Security concerns?
6. monitoring? logging ? Observability ?
Step 7: Are there any special cases
Identify if you need to do something for some special use cases .
In the twitter you may need to do something different when Donald Trump tweets something.
My bookmarks :
Scope of System design interview can be very broad. To do well in such interviews it helps to have some familiariaty with some of the such questions as well as in general some idea about how some of the well known systems works. Here are some of the resources that I founnd really nice.
Interview Questions:
https://www.interviewbit.com/courses/system-design/
https://www.educative.io/courses/grokking-the-system-design-interview
http://blog.gainlo.co/index.php/category/system-design-interview-questions/
https://www.hiredintech.com/courses/system-design
https://www.youtube.com/playlist?list=PLMCXHnjXnTnvo6alSjVkgxV-VH6EPyvoX
Have in depth knowedge of one NoSQL db :
Couch base DB architecture :https://www.youtube.com/playlist?list=PLuCXhs7wKJuVz2RB_kJlsUPz2iLBZI8MJ
Dynamo DB: https://www.allthingsdistributed.com/2007/10/amazons_dynamo.html
How Kafka works :
https://www.confluent.io/resources
System Architecture in general:
https://www.developertoarchitect.com/lessons/
https://www.infoq.com/architecture-design/
http://highscalability.com/
https://highlyscalable.wordpress.com/2012/03/01/nosql-data-modeling-techniques/
https://microservices.io/patterns/index.html
https://martinfowler.com/architecture/
Most of the companies have their own developer bolgs where they share their architecture , success and failure stories.
Have fun and good luck :)