Problem Statement

Imagine you meet a small startup company planning to launch an Online Food Delivery System like Swiggy/Zomato that allows consumers & service providers to interact in real-time. They want to support both Mobile App and Web-based applications. Like many small start-ups, they are confident that they will be the next big thing and expect significant, rapid growth in the next few months. With this in mind, they are concerned about the following:

Proposed Solution

Proposed below is a high-level reference architecture for Online Food Delivery systems.

This proposed architecture is generic and it can be deployed to any of cloud provider like AWS/GCP/Azure

Assumptions

Proposed Architecture Diagram

Possible Tech Stack

Solution Details

Core Features of Customer App

Core Features of Delivery Partner

Core Features of Food Partners/ Restaurants

Core Features for Food Ordering System Admin

Application Flow

We are considering here microservices-based architecture. Different services are listed in the architecture diagram

  1. All requests made from a mobile app or UI will go to different services via the API gateway. API gateway will take care of load balancing and routing requests to services. This will authenticate and authorize the user and send back the token ID. This token is used for further communication
  2. Different services like, user registration and management service, order service, payment service will use transactional databases. We will use the Amazon Aurora relational database. This is a highly scalable database service to manage users and concurrent orders etc.
  3. Information about different restaurants, their menu, price, offers, etc will be stored in JSON document storage in ElasticSearch. We can use a multi-node cluster here. Whenever a customer searches for a menu/cuisines it will be fetched from elastic search. Elastic search provides fast scalable search options
  4. Once the user selects the dishes and quantity from the restaurant. He will go to the checkout option and then do payment. Different payment gateways and payment options are integration with the system and upon successful payments, the order is successfully placed
  5. Once the order is placed all the information is sent to the central message Queue like Kafka. The order processing unit reads the order info and then notifies the selected restaurant about the order. At the same time, it searches for available delivery partners to nearby locations to pick up the order. It also gets the information like preparation time from the restaurant and estimated pickup time from the delivery partner based on his location and other details. it will select the best available delivery partner and he is notified about order and restaurant details
  6. The user gets push notification about the order. The order processing and tracking service will work together and the user can track their order status, live location of the delivery person, etc
  7. Delivery person pickup order and deliver to customers. Customer is real-time notified with ETA for the order

Delivery Engine

This will read information like food preparation time, time for the delivery person to reach to restaurants, time to reach to the customer place, available delivery persons, historic data about last orders, delivery time and predict the delivery times for orders based on historical data and real-time data like maps data, current delivery person data, etc. This will also take care of assigning delivery persons for orders. This keeps on updating the pool of delivery persons for given locations.

Easy onboarding and Searchability of Restaurant

From the Admin panel, the admin can add the restaurant. Admin adds details like restaurant name, city, address, postal code, cuisine type, operational hours, owner details, payment shares, etc. All this information is stored in a relational database. We use Amazon Aurora here.

Once the restaurant is added we will generate a Unique ID for the restaurant. This unique ID will be used in Elastic search to store information like different menus, their price, preparation time, etc.

Restaurants have access to add /update/delete menu, price, preparation time, etc

So when a customer searches food options by dish name, restaurant name, location then ElasticSearch is queried. Elasticsearch is a highly available, scalable open-source full-text search and analytics engine. With elastic search, you can store, analyze, search large volumes of data quickly and in near realtime.

When a customer opens the app, the first call is made to the Inventory/Menu system to figure out:

  1. Nearby serviceable restaurants to customer locations. This can be done by customer location and restaurant location.
  2. The restaurants that are actually serviceable to the user/customer, those restaurants which can deliver food within some stipulated time ( say 45 minutes )
  3. The expected delivery time for your food order from a potential restaurant.

Prediction of the Delivery time

Delivery time is the time taken to deliver the order after it places with the restaurant. It depends on preparation time by the restaurant, time is taken for delivery personnel to reach the restaurant and pick up the order, and then the time to deliver it to the customer.

So it depends on below factors

  1. Assignment time: How long before we can find a Delivery Person who can fulfill this order?
  2. Time to reach Restaurant: Time to arrive at the Restaurant to pick up food
  3. Preparation Time: How much time is required for the Restaurant to prepare the food?
  4. Delivery: How much time is required for the Delivery Executive to reach the customer from the Restaurant?

The delivery system/tracking system finds out assignment time for the delivery person based on the location of the available delivery person, and location of restaurants. How to allocate/assign the delivery person is discussed in next point

Preparation time depends upon preparation time provided by the restaurant for the item, number of items in an order, current load on the restaurant. Based on this delivery engine will decide the best Preparation time for your order.

The time to reach the restaurant and delivery time can be calculated by checking information about traffic, the shortest route available for map integration. But sometimes this information is not that accurate so we might need to consider below aspects as well

  1. historical data: Keep track of old orders in that area and has a lot of data around how long delivery can take on a two-wheeler from a particular Restaurant to a Customer for a given time slot
  2. Enrich Historic data with real-time data: Keep track of other delivery persons who are providing order in that area.

Considering this delivery engine can do calculations and get the best time for your food delivery.

How to allocate delivery personnel efficiently

Normally if an order is assigned to the delivery person. He won’t be considered for assignment till delivery is done. But how to allocate delivery person efficiently so that we can deliver better and make use of delivery persons more efficiently

We need to keep track of busy hours for delivery. Normally delivery happens on breakfast, lunchtime, snacks time (4 pm to 6 pm), dinner time (7 pm to 10 pm)

Keep track of peak delivery hours and number delivery personal available during those time slot

Keep track of all the Delivery Persons and see their status. We can then estimate how long it will take for delivery persons to be available and start processing a new potential order.

We need to keep track of every single Delivery Executive, what they are doing, how long they will be delayed, and then see their eligibility to deliver an order from the list of hundreds of restaurants.

Keep track of historical order data and predict how many customers will order at any given time and whom we can provide service based on delivery personnel available.

Based on historical data, predict buffer time for delivery and use that in allocation.

So the assignment of the delivery person is dependent on all the above factors.

Few approaches can be considered to allocate delivery person more efficiently

  1. Group/Combine orders: A way to increase the efficiency of Delivery Person by delivering more than one order at a time. if a restaurant gets two orders at the same time from two customers located nearby, it makes perfect sense to dispatch a single Delivery Person to deliver both orders. Or if two restaurants which are nearby and customers are also nearby then combine orders to the same Delivery Person.
  2. Reduce wait time at Restaurant/ Delay Assignment: Expectation is a delivery person doesn’t need to wait at the restaurant collection point to pick up the order as its not ready. To assign the delivery executive just in time. Assign him just before the order is ready. Delay assignment of delivery executive until the order is ready. consider cooking time and time to reach and do assignments based on that decide the best assignment time for the delivery person. This way the best delivery person is chosen for the order.
  3. Next Order Assignment: Assign order to a delivery person just before his current delivery is over. Consider the delivery person eligible for an order just before he finishes his order. This way we can increase the available pool of delivery persons for orders.

Deployment

All the services, backend applications, APIs can be dockerized and deployed and scaled using any docker orchestrator like docker swarm, Mesos, or Kubernetes. We can use AWS ECS, EKS, or AWS Farget to manage dockerized application deployment.