Basics of System Design
For entry-level job System Design might not be a must, but it is always a plus to have knowledge of it. But if you are preparing for SDE2/SDE3 roles, then it plays a crucial role in the interview.
System Design: It can be described as the designing of the architecture, components, and interfaces of a system meeting the needs of a product or service.
While designing a system, one should make sure the system is
1. reliable meeting of the customer’s need
2. available i.e, the system is up and functioning well
3. scalable which means it can withstand the increasing load and can be scaled easily.
4. consistent data delivered by the system is accurate.
We cannot achieve 100% of reliability, availability, scalability, and consistency together. There is always a trade-off, we will see more about this in the CAP theorem article. So, the preference is to be given based on system requirements. For instance banking system would have consistency as the highest priority.
Reliability In System Design
In simple words, if a system works as per the user’s requirement then the system is reliable. Reliability can also be defined as the probability of a system performing correctly at a given time.
So could you think about what reliability could depend on?
The system’s reliability depends on the reliability of individual components and on how they are connected to each other.
In an extreme case, components can either be connected in a series or parallel fashion. From general observation, we could say if any one of the series components fails then the entire system would malfunction. In a parallel system, the working of a single component is sufficient for the system to operate satisfactorily. Of course, there could be a system that is a combination of parallel and series systems.
One of the essential requirements for a system to be reliable is Fault tolerant.
The fault-tolerant system is reliant on the failure of elements within the system.
The fault-tolerant system may have one or more of the following features:
1. No single point of failure – Say if one of the components fails, we have a backup
component to serve the purpose. For instance, having a battery backup if a power
cut is seen.
2. Fault isolation or identification – The faulty elements are to be identified and
isolated. So that it does not impact other components of a system.
Similarly, there could be more such factors that make the system fault-tolerant.
Availability In System Design
Availability can be defined as the percentage of the time system is up i.e, the system is working satisfactorily. Lower the downtime more the availability. For instance, sometimes many people around the globe experienced Instagram downtime i.e, they could not refresh to see new posts or send messages.
How is the system’s availability measured?
Availability = uptime / (downtime + uptime)
We understood what availability means, but how do we achieve high Availability in a system?
A system has high availability if it is operational despite of failure in the elements of a system. We could enhance availability by adding redundancy i.e, using additional hardware (server or storage) components. For illustration, if one server is down, the load balancer will redirect requests to another server.
- Passive Redundancy: Only one component is active, in case of failure backup component becomes active.
- Active Redundancy: All the components perform simultaneously. In case of a failure of a component, another component takes up the load and ensures availability.
Availability can be ensured by not just adding redundancy(hardware approach) but also by software approach. There could be many ways for software approach, one of them being regular interval checking of components functioning of a system. So that non-functioning components are identified and corrective steps are taken.
Will there be a trade-off between the availability and performance of a system?
The answer is yes, to achieve high availability we would add backup components(servers, storage devices, etc) which can impact performance(higher latency or lower throughput).
For instance, the read/write operation over the database and its backup database can take additional time, thereby increasing latency.
Scalability In System Design
A scalable system is one that can handle an increase in user requests and demand. Scalability estimates how well the system responds to modifications, by adding or removing resources to meet customer demands.
For example, a well-designed online booking website should work fine with an increase in traffic during holidays.
How to Make a System Scalable?
One can build a system with a scalability pattern, which can be achieved by having a proper architectural pattern. I.e, they are a set of development and programming techniques that have been tested and proven to work fine under major circumstances, which solves problems in system development.
There can be various Scalability Patterns, which are to be chosen as per System requirements. Some of the Scalability Patterns are AKF scale cube(X, Y, and Z axis scaling), Vertical and Horizontal scaling. We will be seeing these in detail in the article Horizontal and vertical scaling.