Have you ever wondered what happens behind the scenes when you order food on apps like Zomato or Swiggy?
Several microservices work together β some talk synchronously, others asynchronously β to ensure your biryani gets delivered hot and fast! π
Let's dive into the entire journey. π
π Step 1: User Browses Restaurants and Selects Food
π₯ Services involved:
- Restaurant Service
- Menu Service
- Search Service
- User Profile Service
π Communication:
- User App β Search Service: (Sync, REST API) to search restaurants.
- User App β Menu Service: (Sync, REST API) to fetch restaurant menus.
- User App β User Profile Service: (Sync, REST API) to fetch saved addresses.
β Why synchronous?
- User expects immediate search results and menu listing.
- UX needs to be fast and smooth.
π§Ί Step 2: Add Food Items to Cart
π₯ Services involved:
- Cart Service
π Communication:
- User App β Cart Service: (Sync, REST API) to add items or view cart.
β Why synchronous?
- Real-time feedback needed when user adds/removes dishes.
π³ Step 3: Place Order and Make Payment
π₯ Services involved:
- Order Service
- Payment Service
- Coupon/Discount Service
π Communication:
- User App β Coupon Service: (Sync, REST API) to validate discounts.
- User App β Payment Service: (Sync, REST API) to process payment.
- User App β Order Service: (Sync, REST API) to place the order.
β Why synchronous?
- Payments and coupons must be validated instantly to complete order.
π³ Step 4: Restaurant Accepts the Order
π₯ Services involved:
- Restaurant Management Service
- Order Service
- Notification Service
π© Communication:
Order Service β Restaurant Management Service: (Async, Kafka event
NEW_ORDER_PLACED) to notify restaurant.Restaurant Management Service β Notification Service: (Async, Kafka event
ORDER_ACCEPTED/REJECTED) to send push notifications.
β Why asynchronous?
- Restaurant may take time (few seconds) to accept.
- System should not block the user; instead show "Waiting for confirmation".
π΄ Step 5: Assign Delivery Partner
π₯ Services involved:
- Delivery Assignment Service
- Delivery Partner Service
π© Communication:
-
Restaurant Service β Delivery Assignment Service: (Async, Kafka event
ORDER_READY) to request pickup. -
Delivery Assignment Service β Delivery Partner Service: (Async, Kafka event
ASSIGN_RIDER) to allocate a delivery person.
β Why asynchronous?
- Finding the nearest available rider can take a few seconds.
- Needs retries if rider not available.
π Step 6: Live Tracking of Order
π₯ Services involved:
- Tracking Service
- User Notification Service
π Communication:
- User App β Tracking Service: (Sync, REST API or WebSocket) to get live order location.
- Delivery Partner App β Tracking Service: (Async, updates every few seconds) to send GPS location.
β Why mixed?
- Delivery boy's app sends async updates in the background.
- User app polls or uses WebSocket for real-time experience.
π΄ Step 7: Order Delivered and Feedback
π₯ Services involved:
- Order Service
- Rating and Review Service
π© Communication:
-
Delivery Partner App β Order Service: (Async, Kafka event
ORDER_DELIVERED) to mark order delivered. - User App β Rating Service: (Sync, REST API) to submit rating/review.
β Why mixed?
- Delivery marking can be async.
- User rating needs quick feedback after submitting.
π§© Full Service Map (with communication type)
| Service | Talks to | Communication | Why |
|---|---|---|---|
| User App β Search Service | Sync (REST) | Instant restaurant search | |
| User App β Menu Service | Sync (REST) | Instant menu loading | |
| User App β Cart Service | Sync (REST) | Real-time cart update | |
| User App β Coupon/Payment Service | Sync (REST) | Real-time payment validation | |
| Order Service β Restaurant Service | Async (Kafka) | Restaurant confirmation | |
| Restaurant Service β Delivery Assignment | Async (Kafka) | Schedule delivery | |
| Delivery Partner App β Tracking Service | Async | Background GPS updates | |
| User App β Tracking Service | Sync (REST/WebSocket) | Live order tracking | |
| Delivery Partner App β Order Service | Async (Kafka) | Mark order delivered | |
| User App β Rating Service | Sync (REST) | Instant rating feedback |
π― Why Sync vs Async in Food Delivery?
| Synchronous (REST/WebSocket) | Asynchronous (Kafka/Event Bus) |
|---|---|
| Searching restaurants | Order confirmation from restaurant |
| Adding to cart | Assigning delivery partner |
| Making payment | Updating live delivery status |
| Submitting rating | Marking delivery completed |
π₯ Key Observations:
- User-facing actions = mostly synchronous.
- Internal system-to-system actions = mostly asynchronous.
- Kafka, RabbitMQ, or Pub/Sub used for decoupled communication.
- REST APIs or WebSockets used for real-time interactions.
- Scalability, resiliency, and user experience are balanced by picking right communication strategy.
π Real-World Example:
- Swiggy uses gRPC between internal services, Kafka for events, and REST/WebSockets for user interactions.
- Zomato heavily uses Kafka for order and delivery workflows.
βοΈ Final Thought
Building a food delivery platform is not just about delivering food.
It's about designing a resilient, fast, and fault-tolerant system using the right combination of synchronous and asynchronous communication patterns! ππ
Top comments (0)