Opening a Pizza Restaurant

Questions to be asked are in bold letters. 

How to scale this restaurant step by step ?

Initially, we have only one chef. But, how do you handle more orders? 

We can ask the chef to work harder and can pay more to her. Hence, we can optimise the processes and increase throughput with the same resource. This is called vertical scaling. 

The chef has to prepare the pizza base at the non-peak hours. So that more customer orders can be handled. This is called preprocessing and cron job. 



How can we make the system more resilient(recovering from failure quickly)?

When chef goes on sick leave, then orders can't be taken on this day. So, here the chef is a single point of failure. 

To overcome this issue, hire a backup part-time chef, if the primary chef is on leave, backup chef will work on these days and will get per-day salary. So, the chance of losing the business is very low. This is called Master & Slave Architecture. 

How do we handle more than 2x pizza orders?

Hiring more backup chefs as full-time will solve this issue. Hiring more resources/chefs is called Horizontal Scaling. 

How do we assign it to specific chef based on their skills?

Now, the chefs are specialised in either Garlic Bread or Pizza. For example, Chef 1 is specialised in Pizza and Chef 2 is specialised in Garlic Bread.  Randomly routing the orders will not build their strength, so to make the system simpler, we need to notify it to specific person. This system will also be useful if we need to change the recipe of the Garlic Bread, or if we need to get the status of the Garlic Bread, it will only be routed to Chef2.

All the chefs specialised in Garlic bread will be put in a team. All the chefs specialised in Pizza will be put into other team. 

Scaling the 'Garlic Bread' team at different rate compared to 'Pizza' team and divide responsibilities is crucial. This is called Microservices Architecture. 

At this point, this business is scalable to large extent. 

What if the electricity outage/losing a license in the pizza shop?

We can open another pizza restaurant in another place. Distribute the orders to multiple shops because we don't want to drop all the eggs in the basket. It might take more time to respond the request or process the order or might have less chefs, but it will be a backup shop when one shop couldn't active on a day. This is called a distributed system (Partitioning)

A distributed system, also known as distributed computing, is a system with multiple components located on different machines that communicate and coordinate actions in order to appear as a single coherent system to the end-user.

There are two general ways that distributed systems function:

  1. Each machine works toward a common goal and the end-user views results as one cohesive unit.
  2. Each machine has its own end-user and the distributed system facilitates sharing resources or communication services.
For example, the customers in location A will order to the pizza shop in location A.

On a large scale, FB gets requests from all around the world. In order to get a quick response time, you need to have local servers everywhere. 

Advantages: 

1. Quicker response time
2. Fault Tolerance

How the customer will decide to which shop he has to send a request to ?


We can have a central component where all the customer requests will be received. From there, all the requests will be routed to either shop 1 or shop 2 or etc., based on certain parameter. 

The parameter would be how long it would take for the customer to get the pizza if the request is sent to shop 1. This central authority will take intelligent business decisions until it gets the regular updates from the shops. This central authority is called Load Balancer. 

Though the system is fault tolerant, how can we make it flexible to change ? Can it be future proof? 

Delivery agent is not only assigned to pizza shop, he/she would also deliver a burger. His only job it to deliver the order as quickly as possible to the customer. 

Delivery Agent will not be under the Pizza shop, so separating the system would be efficient. 
This is called decoupling. 

How can we stop the churning rate going down?

When the shop encounters a problem with oven or if the delivery agent bike is broke down, the churning rate might go low. 

These problems can be resolved by logging these events and what is the next event on this. 
We can also condense these events and find the sense out of these events using the following. 

1. Analytics
2. Auditing
3. Reporting 
4. Machine Learning

This is called Logging and Metrics.

How to make the system extensible ?

When you want to open another shop or adding a different machine into a system, you don't want to write the code again. So decoupling is necessary. Delivery agent doesn't want to know what the shop processes. In this way, a system can be more extensible. 

























Comments