High level system design basics with an example story
Imagine a person named Achraf having a pizza shop in Morroco. He started the shop with one chef only. As the days passed, more customers started buying pizza from Achraf's shop. Now which solutions can Achraf try to meet this business requirement?
Vertical scaling
In this kind of approach, Achraf will increase the salary of the only available chef and tell him to work extra hours. That means here the process is optimized and throughput is increased with the same available resource. This is an example for vertical scaling.
Preprocessing and cron job
Another way to tackle this business requirement is preparing some items at non peak hours. For, example preparing pizza dough at 4 am when there are no orders. So, the chef can use this pizza dough whenever the order comes at non peak hours.
Resilient
Imagine the chef falling sick one day, this will badly affect the business of Achraf's pizza shop on that day. This is an example of a single point of failure. So, Achraf decides to hire a backup chef for that day. So, keeping a backup will help to avoid any single point of failure. Resilient means recovering quickly from failures.
Horizontal scaling
Now the business requirement in Achraf's shop increases a lot. So, this time Achraf decides to hire more chefs. For example, he hires 3 main chefs and 7 backup chefs. This is an example for horizontal scaling.
Microservices
Now Achraf have a single shop with 10 chefs in total. Now out of the 3 main chefs imagine two are specialists in cooking pizza and the one remaining chef is specialist in cooking burger. So, Whenever an order comes this order should go exactly to the person who is specialized in that. This is an example for microservices architecture, where each one's role is defined.
Distributed system
Now imagine a power failure happening in Achraf's shop on a day. To avoid this kind of situation affecting his business, he decides to start another shop which is away from his first shop. In this way, some orders are managed by the second shop. This is an example of a distributed system where partition is done. This makes the system more fault tolerant and this will result in quicker response time.
Load balancer
Imagine a customer placing an order on Achraf's pizza shop website. Now a central system should decide out of the two shops which one receives the order. This will be decided based on different data provided.
From this diagram we can say that the load balancer will forward that order to the second pizza shop. This is an example of how load balancer works.
Decoupling
Here in this system, we can divide this based on concerns. The concern of the delivery agent is just delivering the package. It doesn't matter whether it's a burger or pizza. Decoupling is the process of separating the concerns and handling the system more efficiently.
Logics and metrics calculation
The delivery of the order is also dependent on other factors like unexpected accidents, other power failure issues, etc. To keep track of these issues, it is better to keep a log of each activity. Here activities such as analytics, auditing, reporting, and machine learning are carried out.
Reference: Gaurav Sen's YouTube channel