Design Food Delivery App Mobile System Design

mobile-system-design Sep 07, 2024
Food Delivery App Mobile System Design

Building a food ordering and delivery app like Uber Eats, DoorDash, Swiggy and Zomato requires a clear understanding of the problem space, a well-defined set of requirements, and a thoughtful architectural design.

Below, we have explained the system design of building such app in a structured format, covering all the key aspects necessary to build a robust foundation.

Problem Statement

The goal is to design an iOS app that allows users to browse, order, and track food deliveries from local restaurants. The app should provide a seamless user experience, efficient backend operations, and real-time order tracking, while ensuring security and scalability.

In system design interviews, the interviewer may focus on specific features of a food delivery app, such as real-time order tracking or search functionality based on distance and delivery time.

In this article we will focus on features like user services, order services, Payment, Notification services all together.

 

Functional Requirements

- User Registration and Authentication: Users should be able to register, log in, and manage their profiles. support some third party login integration like goole login, apple login and facebook login.
- User Type Management: Users Type like User Premium and Standard User. Premium user by paiying some membership or subscription ties with access to additional benefits and exclusive features.
- Restaurant Browsing: Users should be able to browse and search for restaurants based on various criteria (e.g., location, cuisine, ratings).
- Menu Viewing: Users should be able to view restaurant menus, including item descriptions, prices, and images.
- Cart Management: Users should be able to add items to a cart, modify quantities, and remove items before checkout.
- Order Placement: Users should be able to place orders and receive confirmation.
- Payment Processing: Users should be able to securely pay for their orders using various payment methods like Netbanking, card payment, UPI and Apple Pay.
- Order Tracking: Users should be able to track their orders in real-time, from preparation to delivery. Use latest feature like Live Activities to track delivery.
- Notifications: Users should receive notifications about order status, promotions, and updates. Use Push Notification implement APNS.
- Rating and Reviews: Users should be able to rate restaurants and delivery services, as well as leave reviews.
- Coupons and Discounts: Users should should be able to get coupons and can get discounts provided by Merchant, Bank and Restaurants.
- Filters like Veg, Top Rated, Meal Type: Users should be able filter based on given categories and apply multiple filter also.
- Sorting like nearest, most discounted, fastest delivery: Users should be able to sort given item based on sorting type given like nearest, most discounted, fastest delivery.

 

Non-Functional Requirements

- Scalability: The app should handle a large number of concurrent users and orders.
- Performance: The app should have low latency, with fast loading times and smooth interactions.
- Security: User data, particularly payment information, must be securely handled and stored.
- Reliability: The app should have high availability, with minimal downtime and robust error handling.
- Usability: The app should be user-friendly, with an intuitive interface and easy navigation.
- Compliance: The app must comply with relevant regulations (e.g., PCI-DSS for payment processing).

 

Assumptions or Constraints

- Geographical Limitation: The app will initially target a specific geographical area or country.
- Restaurant Integration: Restaurants must be onboarded and maintain their menus and availability within the app.
- Payment Gateway: The app will rely on third-party payment gateways for processing payments.
- Third-Party APIs: The app will use third-party services for geolocation, mapping, and push notifications.
- Device Support: The app will be designed specifically for iOS devices, with support for iPhone and iPad.

 

API Design

APIs will facilitate communication between the client app and the backend services. Below are the key API endpoints:

- User APIs
- `POST /register`: Register a new user.
- `POST /login`: Authenticate a user.
- `GET /profile`: Retrieve user profile details.
- `PUT /profile`: Update user profile information.

- Restaurant APIs
- `GET /restaurants`: Retrieve a list of restaurants based on location and filters.
- `GET /restaurants/{id}`: Retrieve details of a specific restaurant, including the menu.

- Order APIs
- `POST /orders`: Place a new order.
- `GET /orders/{id}`: Retrieve the status of a specific order.
- `GET /orders`: Retrieve a list of past orders for a user.

- Payment APIs
- `POST /payments`: Process a payment for an order.

- Notification APIs
- `POST /notifications`: Send notifications to users about order status or promotions.

 

Data Schema

The data schema represents the structure of the database, defining the relationships between various entities.

- Users Table
- `id`: Unique identifier for the user.
- `name`: User’s full name.
- `email`: User’s email address.
- `password_hash`: Encrypted password.
- `address`: User’s delivery address.
- `phone_number`: User’s contact number.
- `user_type` : User's Type (e.g. premium or standard).
- `payment_method`: Preferred payment method (e.g. card details, digital wallet).

- Restaurants Table
- `id`: Unique identifier for the restaurant.
- `name`: Restaurant’s name.
- `location`: Geographical location (latitude and longitude).
- `cuisine_type`: Type of cuisine (e.g., Italian, Chinese).
- `rating`: Average rating based on user reviews.
- `menu_items`: List of menu items offered by the restaurant.

- Menu Items Table
- `id`: Unique identifier for the menu item.
- `restaurant_id`: Foreign key linking to the restaurant.
- `name`: Name of the menu item.
- `description`: Description of the menu item.
- `price`: Price of the menu item.
- `image_url`: URL of the image for the menu item.

- Orders Table
- `id`: Unique identifier for the order.
- `user_id`: Foreign key linking to the user.
- `restaurant_id`: Foreign key linking to the restaurant.
- `total_amount`: Total cost of the order.
- `order_status`: Current status of the order (e.g., pending, in-progress, delivered).
- `created_at`: Timestamp when the order was placed.

- Order Items Table
- `id`: Unique identifier for the order item.
- `order_id`: Foreign key linking to the order.
- `menu_item_id`: Foreign key linking to the menu item.
- `quantity`: Number of units of the menu item ordered.
- `Coupon` : Coupon code applied

 

High-Level Design

The high-level design outlines the overall architecture and interaction between various components of the system.

- Client Application (iOS App): The user interface and interaction layer, responsible for capturing user input and displaying data fetched from the server.
- API Gateway: Acts as the entry point for all client requests, routing them to the appropriate microservices.


- Microservices:
- User Service: Manages user registration, authentication, and profile management.
- Restaurant Service: Manages restaurant data, including menus and ratings.
- Order Service: Handles order placement, tracking, and history.
- Payment Service: Processes payments and manages transactions.
- Notification Service: Manages push notifications and real-time updates.
- Coupon Management: Admins should be able to create, update, and delete coupons in the system.
- Database: Stores all persistent data, including user profiles, restaurant details, orders, and payment information.


- Third-Party Services:
- Payment Gateway: Processes payments securely.
- Geolocation API: Provides mapping and location services.
- Push Notification Service: Sends notifications to users.

 

Low-Level Design

The low-level design provides more detailed information about the internal workings of specific components.

- Client-Side Components:
- Views: Manage the UI and user interactions for different screens (e.g., HomeView, RestaurantView, CartView etc.)
- ViewModels: Contain business logic and interact with services to fetch data and update the UI (e.g., HomeViewModel, OrderViewModel).
- Networking Layer: Handles API calls, including data fetching and error handling.
- Data Persistence: Use Core Data or Realm to store local data, such as order history or user preferences.

- Server-Side Components:
- Service Layer: Contains the business logic for handling requests and processing data (e.g., UserService, OrderService).
- Repository Layer: Interacts with the database to perform CRUD operations.
- Messaging System: Use a message broker (e.g., RabbitMQ) for asynchronous communication between microservices, particularly for order processing and notifications.
- Cache Layer: Use Redis for caching frequently accessed data, such as restaurant menus or user sessions.
- Coupon Management: Coupons should have configurable attributes, such as:
- Code: A unique identifier for the coupon (e.g., “SAVE20”).
- Discount Type: The type of discount (e.g., percentage-based, flat amount, free delivery).
- Value: The discount amount or percentage.
- Validity Period: Start and end dates for when the coupon is valid.
- Usage Limits: Maximum number of uses per user. Maximum number of uses overall.
- Eligibility Criteria: Conditions under which the coupon is valid (e.g., minimum order amount, specific restaurants, new users only).


- Reasoning for Choosing This Approach and Alternatives:
- MVVM on the Client-Side: Chosen for its separation of concerns and testability, with alternatives like MVC and MVP depending on project needs.
- Service and Repository Layers on the Server-Side: Provide clear separation between business logic and data access, leading to more modular, maintainable code.
- Messaging System with RabbitMQ: Enables asynchronous communication, improving resilience and scalability, with alternatives like synchronous HTTP calls or Kafka.
- Redis for Caching: Chosen for its performance and flexibility, with simpler alternatives like Memcached or relying on database-level caching for less complex needs.

 

Where to go next?

Congratulations, you have mastered the system design of Food Delivering App. The system design interviews are conducted to understand the approach and experience of the engineer. While formulating all the aspects of a given system design problem, keep sharing your thoughts with the interviewer because that's what will make you stand-out not only a plain solution that you'll write.

If you want to become better at designing systems, we recommend you to read this article Ultimate Guide to Mobile System Design

Signup now to get notified about our
FREE iOS Workshops!