As the time for placement season has started, there is a horde among the students to do something over the top to stand out in the interviews. Most of the students prepare for Data Structures and Algorithms and some take a taste of Development to spice up their resume.
Some put up some Internships whereas some people choose to do some certifications to validate their skills. But usually, students don’t look around one of the most important concepts that are required to be industry-ready, that is System Design. System Design Concepts are one of the most frequently asked questions in interviews.
What is System Design?
So for a formal definition, Systems Design is the process of defining elements of a system like modules, architecture, components and their interfaces and data for a system based on the specified requirements.
It is the process of defining, developing and designing systems that satisfies the specific needs and requirements of a business or organisation.
Why do we need System Design?
So here a big question arises: what is the need for System Design?
When we need to create systems that will cater to the needs of the masses, in that case, we need to think around and design the entire system in such a way that it’s modular and scalable. The system, on the whole, can be scalable if and only if the entire module structure of the system is scalable itself.
Now here another question arises: why make a scalable system?
So, as time passes and our system gets popular, more and more people will use the system concurrently and on a regular basis. As the load on the server increases the chances of a system failure increases as the load on the server will bottleneck the traffic and cause the CPU utilisation to increase many folds and reach a peak causing the server to crash under load and in return causes the entire system to fail.
But system design concepts helps us to design our system in such a way that the system scales itself but up and down according to the demand and load. If the load is less then the system should halt the excess resources to save the operational costs and if the load exceeds the current maximum capacity, then the system should be able to scale up and spin up some extra resources to cater for the increased load.
The next question arises: why a modular system?
Now suppose that today we need a feature that requires any ‘A’ amount of resources but after a certain amount of time we get a requirement to create another feature that needs the resources of another feature as well as ‘A’ amount of features.
So if our system will not be modular and will be coupled closely, it will be difficult to introduce such a feature and will need a lot of refactoring. So each and everything is kept as modular as possible for producing a high quality, robust and reusable codebase.
High Level Design
The high-Level Design of a System is more of a generic design of a system. A High-Level Design of a System usually contains:
- Requirement Documentation: A comprehensive documentation that contains all the requirements that our system needs to achieve.
- Unified Modelling Language: It is used to describe a system both behaviorally and structurally.
- Flow Charts: Used to describe the flow as well as define the conditions on different types of user inputs and system outputs.
- Data Flow Diagrams: Used to describe how the data flows in and out of the system. As well as defines how the system will use the data to interact with different parts within the system.
The High-Level Design of a System is essentially used by Solution Architects, Business Analysts and Developers. The output of a High Level Design is Functional Design, Database Design and Review Records.
Low-Level Design of a System is an elaborated design of a High-Level Design and it signifies the process of a component-level design. Low-Level Design is complicated, lengthy and highly elaborated.
The Low-Level Design is used to define a system at a component level, basically in other words we can say that it is a High-Level Design of the components of a system.
The Low-Level Design of a System usually contains:
- Business Process Modelling Notation
- Systems Model
The Low-Level Design of a system is essentially used by DevOps teams, Developers and Designers. The output of a Low-Level Design is the unit test plan and program specification.
Important Concepts of System Design
If we see System Design from an interview point of view, this round is generally open-ended, which means that there is no one answer to any question. It is usually more of a discussion around where you are tested on how you can think of a system.
How well you can identify different elements of a system and how well you can couple these elements to create a robust and resilient system.
One can always tell the Class Diagram, the Database Design or the Entity-Relationship Diagram but the interviewer will always try to find an extra plus point in you if you tell him something out of the box and discuss some in-depth points regarding System Design.
Each and every concept of System Design is as important as the rest but there are some frequently asked concepts that would prove beneficial if you know them.
Some of those frequently asked concepts are:
Caching means storing frequently and highly accessed data in a fast read location so that this data can be fetched indirectly from the server to reduce the read load on the server.
Many large scalable systems store frequently accessed data like website images, multi-user details, commonly used business logic and frequently queried data in Cached locations to reduce the read time and optimise the run time of their systems.
Let’s understand the concept of Caching with an example. Suppose there is a professional kitchen where there are multiple chefs working on a single station, multiple busboys and multiple servers serving the food to the guest.
All the essential things used for cooking like pans, ladles, spices and frequently used ingredients are kept near cooking stations in such a way that the chefs don’t have to roam about in the kitchen to collect the ingredients for the dish.
Similarly, all the used utensils are kept in a different place so that all the wash boys can collect the used utensils without interfering with the work. Then all the plated dishes are kept at a single counter for servants to serve to the guests.
In this way, the system runs smoothly without any lags and issues. Each and every person has a different role and each thing is placed at a designated place according to its usage and user.
Similarly, all the static data that a user has to access from a system can be cached so that it can be accessed without any latency and burden on the system.
So commonly used caching systems are MemCache and Redis.
Databases are one of the most important parts of a system. It contains all the data that can be critical to the system. Each and every data element has a priority and based on that priority that data element is stored and saved.
For example, a user’s personal information is very sensitive data that should be protected at all times. Similarly, the data regarding money transactions is very critical for a business so it must be resilient.
On the other hand, a weblog is very important for debugging purposes for developers so must be stored keeping that in mind.
When we talk about databases, the modern system uses different database concepts like:
- Data Warehouses: It is a database construct where all the historical data is saved. Data Warehousing is important from an analytical point of view. To know how a user shops and suggests new products according to his previous buying history is where such kinds of data warehouses come into play.
- Data Lakes: In a system, there can be multiple organisations that are working under the same roof. These orgs can be working together or separately or together but will be needing different kinds of data. So for each organisation, a Data Lake is made to store their data and these data lakes are combined to make a data warehouse. This way we can achieve loose coupling.
There are rules that we should keep in mind while designing databases and making Data Models and those are:
- The Tables should be normalised.
- Normalisation is used to minimise the redundancy from a relation or set of relations. It is also used to eliminate undesirable characteristics like Insertion, Update and Deletion Anomalies.
- There are four levels of normalisation:
- 1NF: To remove multiple data entries and make the data atomic.
- 2NF: All the non-functional data should be dependent on the primary key.
- 3NF: To remove the partial dependency.
- BCNF: To remove the multivalued dependency.
- The Database should follow ACID properties. ACID stands for:
- Atomicity: The data should remain atomic, i.e. any transaction on the data should either be completed fully or should not be executed at all.
- Consistency: It means that the data should be retained, that is any transaction that occurs on the database, should be retained in the system. It is important to maintain the integrity of a database before and after the transaction.
- Isolation: It means that one transaction should not be affected by any other transaction. One transaction should start only when one transaction has ended. If two or more transactions are occurring simultaneously then those should be on different databases so that they don’t interfere with each other.
- Durability: This is to ensure that any change that happens on the database should remain permanent. The durability of the data should be so perfect that even if the system fails or leads to a crash, the database still survives.
Load Balancing means distributing the incoming traffic on our system across multiple servers. To cater to the needs of the masses, modern-day systems run on multiple servers. But if we put all the traffic on a single server.
It will create a bottleneck and will cause our system to break eventually. So, to reduce such problems we need to balance the load across the servers.
There are two types of load balancing:
- Horizontal Load Balancing: The incoming traffic is equally distributed across all the servers. This way all the servers get an equal load hence provides an optimal performance all the time. But this can lead to high operational costs to run multiple servers all the time.
- Vertical Load Balancing: The incoming traffic is sent to a single server until its performance reaches the maximum limit. This ensures low operational cost as only a few servers run at a single time. But this can cause the system to crash under unprecedented loads as the servers may take time to spin up.
As time is changing more and more companies are creating their systems as web applications. But the question here arises why web applications when there were desktop applications.
The answer is simple: the web applications are cross-platform. That is only a single code base has to be generated to run the application over different operating systems.
If you have to create a system as a desktop application, you need to write code for different types of operating systems. Windows will have a separate code and MacOS will support a different code.
But when we talk about web applications, only a single code has to be written to run our application on different types of systems.
This saves a lot of time, line of code and developing cost. This cost can in return be invested to scale our system and develop more and more complicated and extensive systems.
Servers are another important part of a system. Servers play a very vital role in executing the business logic and handling user requests.
But not every kind of server can cater to every need. A server is like a computer only but on a cloud which we can control remotely but we have no control over it physically.
Servers take up the cost to run. There are many cloud services like Amazon Web Services and Google Cloud Platform which provide cloud as a service. They have servers installed in their data centres for which we pay for use per minute.
We cannot keep all the servers running at the same time. So for that, we use a Scaling Group which terminates and creates servers according to the current load on the running servers.
Security is one of the most asked System Design concepts, one can easily encounter a question on How to make our system Secure in a placement interview.
Security concepts can be applied to any part of a system, be it user credentials or data. There are two commonly used constructs in security:
- Authentication: This ensures that the user is a valid user to access the system. The system is not a new user and has been allowed to enter the system.
- Authorisation: This ensures that a user is allowed to perform a certain function on the system.
For example, we have a school management system. Where we have different types of users like Students, Teachers, IT staff, Administrators and Executives. All are the users of the system but all of them will have different types of roles and responsibilities.
A student can change his details and view his marks, add his assignments and view them. Whereas a teacher can edit student details as well as his marks but cannot edit a student’s submission but remark it.
This is where Authorisation comes into play to differentiate which user is allowed to perform which function on the system.
When we have created such an extensive system, we don’t want users to face any delay, downtime or slow read times on the system.
For this the Optimisation comes into play where we try to remove the redundancy from a system’s design.
Optimisation can be of any form from reducing size of images to reducing the data fetched in a query to indexing the data to reduce read times.
Some ways for optimising the system:
- Add read replicas for the database.
- Introduce caching for static content.
- Apply indexing to database tables.
- Try to reduce the size of queried data.
- Use columnar formats.
Most Frequently Asked System Design Questions in Interviews
There can be multiple concepts that can be asked in a System Design Interview but there are some questions that are interview favourites and you are likely to encounter them very frequently in an interview. Some of them are:
- Implementation of an LRU (Least Recently Used) Cache.
- What are ACID properties in DBMS?
- Difference between Load Balancing and Scaling.
- Create Entity Relationship Diagram for a School/University.
- How to normalise a database?
- Different types of normalisation.
- What is database indexing?
- How is Indexing implemented?
- Pros and cons of Indexing.
- Database Partitioning Vs Database Sharding.
- What is database replication?
- What are different kinds of RAID(Redundant Array of Independent Disks)? Explain with examples.
- How to optimise a pre-existing system?
- How to distribute incoming traffic on a system?
- Create a data model or class diagram of any pre-existing system like Whatsapp, Twitter or Amazon.
Frequently Asked Questions
An Interview in which you are asked about different system design concepts like caching, databases and security to test how well in-depth you can imagine a system as well as how modular we can make a system.
Systems Design Interviews can be both smooth and bouncy depending on what things are asked in the interview. One can always prepare for System Design Interviews by studying some basic concepts like Data Modelling, Optimisation, OOPS (Object Oriented Programming Structure) and Class Diagrams.
You can always start by taking up any pre-existing system and try to make a model for it. Or you can read about different concepts of System Design. You can also take up a course on system design like Coding Ninjas has to offer one on the topic.
It is a totally subjective question. The hardness of a topic generally depends on the person who is learning it. But for a general answer if you are a fresher you might need some time to sink into the topics and might have to look around multiple resources. But for a working professional, it might not be that difficult.
Systems Design Interviews are known to be lengthy and full of discussion. These interviews are open-ended as there cannot be a single right answer to a question. One can always expect a rebuttal round where the interviewer can ask about the design and architectural reliability of the solution you proposed.
To summarise the entire discussion on System Design Concepts, I will just say that there are numerous things that could be asked in a systems design interview. One should always try to stick to the approach that one has started with and should always try to add more and more components in the system than he can think of.
Try to learn about more and more concepts but don’t use the concepts which you are unaware of or know very little about. Try to visualise the approach, make flowcharts, class diagrams and data flow models to get the best out of a System Design.