System design interviews are used to check your thought process and how well you respond to the uncertain nature of an open-ended question in the given amount of time. So remember you are not expected to provide with a complete solution say in 1 hour but a working solution with limited functionality.
You need to keep in mind these 3 things while giving a system design interview.
Any system which includes multiple components residing on multiple machines coordinating through some sort of mechanism like sending messages to achieve a common goal is a distributed system.
This is a 5 step procedure which will help you tackle any system design question.
Let’s design a simple Reader/Writer system using the 5 step guide.
1. Requirement Analysis
The problem statement is that we have to design a reader/writer system which saves and retrieves employee data.
Functional requirements
Non-Functional requirements.
2. API design
We need the following APIs to save and read employee data. These APIs suffice the basic functional requirements.
3. Define data model
Let us now define the data model. We will have 2 tables Employee and Department. Department table will have deptId and deptName columns. Employee will have empId, name and deptId columns. DeptId column in both tables will define the relation between the tables. We are using SQL db to save the data as it is relational data.
4. High level design
The first diagram below shows a basic high level design we have come up with. There is a read/write server which reads the data from and writes the data to the database.
Now, as you know we must follow the single responsibility principle in our design. Thus, we separate the server according to the functionality. The second diagram below shows two separate servers as well as load-balancer for efficient distribution of load on the servers.
5. Scale the design
We have non functional requirements of our system as high availability and scalability.
For highly available system, there should not be any single point of failure, as it will result in downtime. For scalability, system should not have bottlenecks so that it can process huge amounts of data. Now lets improve our system with these principles.
Refer below diagrams to see how we improved our system from a simple to a highly scalable and available system using the 3 principles of distributed system.