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)