Wednesday, December 20, 2023

Important Key Concepts and Terminologies

 System Design is the core concept behind the design of any distributed systems. System Design is defined as a process of creating an architecture for different components, interfaces, and modules of the system and providing corresponding data helpful in implementing such elements in systems.

the standard terms and key concepts of system design and performance, such as:

·       Latency, 

·       Throughput, 

·       Availability,

·       Redundancy,

·       Time

·       CAP Theorem

·       Lamport’s Logical Clock Theorem. 

Latency:

Latency is defined as the amount of time required for a single data to be delivered successfully. Latency is measured in milliseconds (ms).

There is a certain amount of time required for user input over the website and there is a certain amount of time for the response from the web application to the user. So the delay between user input and web application response to the same input is known as latency

Reasons for high Latency

Now you must be wondering about the factors that are responsible for delays. So high latency mainly depends on 2 factors:

  1. Network Delays 
  2. Mathematical Calculation Process Delays 

 In monolithic architecture, as we know there is only a single block and all network calls are local within hence network delay is zero and hence latency equals computational delays only (which if not latency equals zero in monolithic systems).

Latency = Mathematic Calculation Delays

In distributed systems, there is a networks over which signals are passed to and fro hence there will for sure be network delay.

Latency = Mathematic Calculation Delays + Network Delays 

How to Reduce latency:

  1. Use a content delivery network (CDN): CDNs help to cut down on latency. In order to shorten the distance between users and reduce the amount of time that data must travel over great distances, CDN servers are situated at various locations.
  2. Upgrading computer hardware/software: Improving or fine-tuning mechanical, software, or hardware components can help cut down on computational lag, which in turn helps cut down on latency.
  3. Cache: A cache is a high-speed data storage layer used in computers that temporarily store large amounts of transient data. By caching this data, subsequent requests for it can be fulfilled more quickly than if the data were requested directly from its original storage location. This lessens latency as well.

 Throughput:

Throughput is defined as the measure of amount of data transmitted successfully in a system, in a certain amount of time. In simple terms, throughput is considered as how much data is transmitted successfully over a period of time. The unit of measure for throughput is bits per second or bps.

 Availability:

Availability is the percentage of time the system is up and working for the needs. 

How to increase Availability?

  1. Eliminate SPOF(major and important)
  2. Verify Automatic Failover
  3. Use Geographic Redundancy
  4. Continue upgrading and improving.

 

From the above understanding, we can land up with two conclusions:

  1. Availability is low in monolithic architecture due to SPOF.
  2. Availability is high in distributed architecture due to redundancy.

 Redundancy:

Redundancy is defined as a concept where certain entities are duplicated with aim to scale up the system and reduce over all down-time

 Consistency:

Consistency is referred to as data uniformity in systems

When a user requests data, the system always returns the same data, regardless of the user’s location, time, etc. Before a user receives data from any node, the server at which the data is updated or changed should successfully replicate the new data to all the nodes.  

Time:

Time is a measure of sequences of events happening which is measured here in seconds in its SI unit. 

It is measured using a clock which is of two types:

  1. Physical Clock: responsible for the time between systems.  
  2. Logical Clock: responsible for the time within a system. 

 CAP Theorem:

Three desirable characteristics of distributed systems with replicated data are referred to as CAP: partition tolerance, availability, and consistency.

 Lamport’s Logical Clock Theorem:

Lamport’s Logical Clock is a process to ascertain the sequence in which events take place. It acts as the foundation for the more complex Vector Clock Algorithm. A logical clock is required because a distributed operating system (Lamport) lacks a global clock.

 

Software Design Concepts


Software Architect key Concepts

Core System Design Principles

OOPS Design Principles




The below are the system design concepts which involve in end to end system.

Important Key Concepts and Terminologies

Functional vs Non Functional Requirements

What are the components of System Design?

What is High Level Design?

What is Low Level Design or LLD?

What are Microservices?

What is Scalability and How to achieve it?

Analysis of Monolithic and Distributed Systems



Design Interview Questions:






















Analysis of Monolithic and Distributed Systems

System analysis is the process of gathering the requirements of the system prior to the designing system in order to study the design of our system better so as to decompose the components to work efficiently so that they interact better which is very crucial for our systems.

System design is a systematic process involving phases such as planning, analysis, designing, deploying, and testing phases. Now the first most question would be why do analyze the system when we are well versed in the designing of systems. 

Generally, the systems can be categorized into two broad categories:

  1. Monolithic Systems
  2. Distributed Systems built with help of Microservices

 Monolithic Systems

If all the functionalities of a project exist in a single codebase, then that application is known as a monolithic application

As the name suggests monolithic means a formation with large single blocks only.  Henceforth with monolithic systems, we refer to a system where the whole web application is deployed as a single unit.

Architecture of Monolithic systems

The Monolithic system architecture can be visualized by considering three sections or three layers:

  1. Client Tier or User Layer or Presentation Layer: It is the closest layer to the user and hence it can be either a webpage or a web application where the user gets things done. It takes input lead from the user, interacts with the server, and displays the user result. Hence we call it a front-end layer.
  2. Middle Tier or Service Layer: It compromises all the logic behind the application and is there in the application server. The application server includes the business logic, receives requests from the client, acts on them, and correspondingly stores the data.
  3. Data Tier or Persistence Layer: It includes a data persistence mechanism(DB) and communication with other applications. It includes databases, message queues, etc. Database server will be used by application server for the persistence of data.              

 Benefits of Monolithic Architecture

  1. Easy development: It is simply a traditional model and does not require hardcore developers to develop such a design because it can never be complex.  
  2. Easy deployment: As seen above all components are stored in a single block/repository so we just need to take care of that single repository while deploying.
  3. Easy testing: Because of closed encapsulation end to end testing via tools is pretty easy.  

 Disadvantages of Monolithic Architecture

  1. The codebase is stored in a single repository leading to difficulty in understanding. 
  2. Any changes in the codebase (updation) will require complete redeployment of the software application. 
  3. Less reusable.
  4. Less scalable because each element will be having different scalability requirements. 

 Microservices

Microservices is an architectural development style in which the application is made up of smaller services that handle a small portion of the functionality and data by communicating with each other directly using lightweight protocols like HTTP. According to Sam Newman, “Microservices are the small services that work together.” 

Microservices Architecture

The Microservice architecture has a significant impact on the relationship between the application and the database. 

  • Instead of sharing a single database with other microservices, each microservice has its own database. 
  • It often results in duplication of some data, but having a database per microservice is essential if you want to benefit from this architecture, as it ensures loose coupling. 
  • Another advantage of having a separate database per microservice is that each microservice can use the type of database best suited for its needs. 
  • Each service offers a secure module boundary so that different services can be written in different programming languages. 
  • There are many patterns involved in microservice architecture like service discovery & registry, caching, API gateway & communication, observability, security, etc.

Advantages

  • Scalability: Microservices architecture allows individual services to scale independently of each other, which helps in optimizing resource utilization and reducing infrastructure costs.
  • Flexibility: Since each service is a separate component, it can be developed, deployed, and updated independently of the others. This provides greater flexibility to the development team, allowing them to work on different parts of the application simultaneously.
  • Resilience: In case of failure of one service, other services can continue to operate without interruption, making the system more resilient.
  • Technology Heterogeneity: Microservices architecture allows for the use of different technologies and programming languages for different services, as long as they can communicate with each other.
  • Easy maintenance: As each service is independent, it is easier to maintain and update the system without affecting other services.

Disadvantages

  • Complexity: Microservices architecture involves the creation of a large number of small services, which can result in increased complexity in terms of development, deployment, and maintenance.
  • Increased overhead: Since each service is a separate component, there is an increased overhead in terms of network communication and data consistency.
  • Testing complexity: With multiple independent services, testing can become more complex, and there is a need to ensure that all services work together seamlessly.
  • Distributed systems: Microservices architecture creates a distributed system, which can lead to additional challenges in terms of monitoring and management.
  • Skillset: Developing microservices requires a different skill set than traditional monolithic application development, which can be a challenge for some development teams. 

Distributed Systems vs Microservices

If you are incorporating Microservices architecture or migrating from Monolithic to Microservices architecture, you cannot do all work on a single system (as it is against the modular feature of Microservices). This is where Distributed Systems were developed. 

Distributed Systems not only provide modularity to architecture but also gives you the advantage to use Microservice architecture easily to utilize all its benefits.

Distributed Systems

distributive system is a collection of multiple individual systems connected through a network sharing resources so as to achieve common goals. 

It is more likely seen in the real world as it has huge advantages over monolithic architecture making it highly scalable and at the same time with multiple systems sharing the same resource solves our SPOF problem. (Single Point Of Failure)

Advantages of Distributed Systems

  1. Scalable: As it contains a collection of independent machines horizontal scaling can be done to achieve scalability.  
  2. Reliable: The distributed system solves SPOF while the monolithic does not because even if an individual unit fails to work rest are operational making it more efficient to work most of the time and hence reliable. 
  3. Low latency: Because of multiple servers and more likely spread to get closer to the user to resolve a query, hence takes very less time to resolve a user query. 

Disadvantages of Distributed Systems

  1. Complexity: Because of high scalability the number of network points and hardware makes the system quite complex and challenging. 
  2. Consistency: Higher number of devices makes it difficult to integrate the data as it gets complex to synchronous application states. 
  3. Network Failure:  Communication and coordination between systems in distributed systems is carried via network calls. In a network failure, conflicting information is passed or sometimes communication failure occurs leading to poor overall system performance.   

Note: Management is also a disadvantage here out because of load balancing functionality(It is a process of distributing the load to the nodes), logging, caching and monitoring is required to manage the system to prevent failures.