System design

System design

What is System Design ?

System design is defined as creating an architecture for different modules, interface and data for a system that satisfies specific requirements.

Let's understand with a real world scenario where you are the owner of a restaurant. You currently have only one chef. Do you think that this is a good idea? What if the chef gets sick on a particular day, will you shut your restaurant for that day or what if there are lots of people ordering food at a same time will the chef be fast enough to make all dishes at once. It's practically not possible. There are high changes of failure. Such type of failures are called single point of failure.

To avoid such failure, we can either keep more chefs (Backups), open another restaurant so that people can go there when the current one is full, preparing the food during the non-peak hours like the burger bun or the pizza bases and keep it ready (Preprocessing) and so on.

Scaling

Imagine you created a website and let's say in the beginning there were less audience who visited your website and they were in absolute love with it. With no time, it gained a lot of popularity and people around the world started visiting it and the website crashed due to traffic. This leads to a bad impression to the end users.

To avoid such scenarios, we need to scale our system so that it can handle load. There are two types of scaling mainly- Vertical scaling and Horizontal scaling.

Vertical Scaling: In this, we keep increasing the resources like the RAM or CPU in the existing system. This is easy as we don't have to write codes or anything but the same code will work. Instead, we just keep increasing the capacity.

Advantages:

  1. No load balancing required.

  2. Inter process communication is fast

  3. It is consistent

  4. Cost effective.

Disadvantages:

  1. Single Point of failure.

  2. Hardware limit.

Horizontal Scaling: In this, we buy more machines and distribute load. In simple term, we hire more people for the same piece of problem.

Advantages:

  1. No single point of failure.

  2. It is resilient.

  3. It scales well.

Disadvantages:

  1. Load balancing is required.

  2. Network calls (RPC) , therefore it is slow.

  3. There is inconsistency in data.

If you are wondering which one is better and which one to avoid... well both are used in real world depending on the requirements.