Fundamentals - Basics Of System Design

Fundamentals - Basics Of System Design

In this blog we are going to learn about the basic things knowledge required to build a particular software application in this we will cover the topics that are following.

  1. Horizontal vs vertical scaling

  2. Monolithic vs Microservice architecture

  3. Load Balancing

  4. Database Sharding

  5. Content Delivery Network (CDN)

Horizontal vs Vertical Scaling

Maybe you have learned about big definitions of that, but I will not waste your time by writing that.

Vertical Scaling: Buying Big Machine

Horizontal Scaling: Buying More Machines

That's it

Although both of them have their advantages and disadvantages let's discuss

Advantages

Vertical Scaling: It is more consistent and requires no overhead of server management.

Horizontal Scaling: It is Resilient (if one machine fails you can redirect to other machines) and Provides Better Scalability.

Disadvantages

Vertical Scaling: Hardware limited (Can go up to some sort of hardware unit only) and single point of failure if the machine fails your app goes down.

Horizontal Scaling: A load balancer is required and this type of scaling can lead to data inconsistency.

Monolithic vs Microservice architecture

Monolithic: In this whole application logic is bundled together to form an application. for example, A completed E-commerce application.

Microservices: In this, we break the system into different small microservices. for example, WhatsApp creates microservices like profile service, chat service, and calling service all of these services combined form a complete application.

which architecture to be used at which time all depends on application complexity if it is small monolithic will be fine otherwise you can choose microservices architecture.

Load Balancing

In horizontal scaling we have multiple machines running but when a client request to our machine for something which machine is going to serve the request will be decided by the load balancer.

So basically in simple terms load balancer is used to route the request of a client to a server but which server depends on the algorithm the load balancer uses like Round Robin, Weighted Round Robin, Least connection, etc.

Database Sharding

Sharding is the process of dividing a large database into smaller, more manageable pieces, called shards. Each shard is a separate database that contains a portion of the data, which helps distribute the load and makes query fetching faster by reducing the amount of data each query has to process.

In this above image example, we are sharding the user database by user-id so that whenever a client requests data for user-id 1001 rather than searching in the whole database we will search in the sharded database which is 2nd in the image

We can shard database depending on key or something for example sharding the user database on basis of their region like India,Usa,Japan etc

Content Delivery Network (CDN)

CDN is a geographically based server that helps load your website quickly for clients. But how does it do that? It caches assets like images, videos, JavaScript, or HTML to speed up site loading.