Architecture and Design Principles for Online Food Delivery System

Sandesh Deshmane
9 min readAug 12, 2020

--

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:

  • Scaling to meet the demand, but they are not sure when and how the demand will grow — they are very concerned about buying too much infrastructure too soon or not enough too late!
  • Effective distribution of load
  • The ability for Service Providers to send notifications to consumer
  • configurable database/s and data access layer to yield high performance and throughput
  • Allocate food delivery personal efficiently
  • Design for easy onboarding and searchability of restaurants
  • Prediction of the food delivery time for order

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

  • Delivery partners are provided with devices that have inbuilt GPS. This will help to locate their current location accurately.
  • Integration with map provider is there and we get details about routes, traffic and commute time

Proposed Architecture Diagram

Possible Tech Stack

Solution Details

Core Features of Customer App

  • Searching menu: Allow your users to search for different restaurants, cafes by location, and cuisines. Using the search filter, users can easily find their favorite eating places, list menu, offers, etc.
  • Order placement: The user can place an order of selected dishes and food. They just need to cross-verify their preferred dish, delivery time, and proceed check-out.
  • Tracking Delivery Partners: With real-time tracking features, it becomes easy for users to track delivery drivers and know their real-time location information. Users can check the time taken by the food delivery executive to deliver their parcel.
  • Payment gateway integration: You provide the users with multiple payment options like credit/debit cards, different wallets like Google Pay, Paytm, Phonepe, UPI, etc

Core Features of Delivery Partner

  • Delivery Partner’s profile: Through this feature, a driver can keep his profile update. It contains his full name, address, email, contact number, photo, and other personal information.
  • Notification for orders: Through push notifications, drivers can get constant updates & alerts for new orders. It will help in the accurate delivery service of your restaurant.
  • Map for the delivery route: Integrate Google Map or other providers and allow drivers to choose the shortest and fastest routes to reach the location.

Core Features of Food Partners/ Restaurants

  • Restaurant Profile/Menu: Through this feature, a restaurant owner can add their restaurant details, menu and its availability, price, preparation times, etc
  • Notification for orders: Through push notifications, Restaurants can get constant updates & alerts for new orders. It will help in the accurate delivery service of your restaurant.
  • Notifications for Pickup Partners: They will get alerts about delivery partners, their location when they will pick up, etc.
  • Payment Details: Information about the payment received from the food delivery system for their orders

Core Features for Food Ordering System Admin

  • Restaurant management: Being on the admin panel, one can directly manage all the restaurants by adding, updating, and removing any eating joint from the list. He can also check active restaurant status.
  • Analytics & report generation: Using analysis and report features, you can get real-time insights of reports and other accounting information which helps you to identify the growth and opportunities to expand reach.
  • Monitoring every action: Monitor all the food orders, delivery partners, deliveries, reviews & ratings of delivery partners, canceled orders, and other important data related to the driver’s performance.

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?

Delivery time = max[ (1+2) OR 3] + 4

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.

--

--

Sandesh Deshmane
Sandesh Deshmane

Written by Sandesh Deshmane

Software Architect at Alphasense

Responses (3)