In modern e-commerce systems (like Amazon, Flipkart), when a user buys an item and it gets delivered, many microservices work together.
These services communicate using a mix of synchronous and asynchronous interactions to make the system fast, scalable, and reliable.
Let's walk through the full journey! 🚀
🛒 Step 1: User Selects an Item and Places Order
🔥 Services involved:
- Product Catalog Service
- Cart Service
- Order Service
- User Service
📞 Communication:
- User App → Product Catalog Service: (Sync, REST API) to fetch item list.
- User App → Cart Service: (Sync, REST API) to add item to cart.
- User App → Order Service: (Sync, REST API) to create an order.
✅ Why synchronous here?
- User expects instant response: "Show me the items", "Add to cart", "Order placed successfully."
- Immediate success/failure feedback.
💳 Step 2: Payment Processing
🔥 Services involved:
- Payment Service
- Order Service
📞 Communication:
- Order Service → Payment Service: (Sync, REST API or gRPC) to process the payment.
✅ Why synchronous here?
- Payment must succeed or fail instantly.
- User must see "Payment Successful" or "Payment Failed" immediately.
📬 Step 3: Order Confirmation & Inventory Management
🔥 Services involved:
- Order Service
- Inventory Service
- Notification Service
📩 Communication:
-
Order Service → Inventory Service: (Async, via Kafka event
ORDER_CONFIRMED
) to reduce stock. -
Order Service → Notification Service: (Async, via Kafka event
ORDER_PLACED
) to send email/SMS.
✅ Why asynchronous here?
- Reducing stock or sending email is background work.
- It shouldn't delay the "Order placed" response to the user.
- If inventory update or notification fails, it can be retried separately.
🚚 Step 4: Delivery Arrangement
🔥 Services involved:
- Delivery Service
- Order Service
- Inventory Service
📩 Communication:
-
Inventory Service → Delivery Service: (Async, Kafka event like
STOCK_RESERVED
) to schedule pickup. -
Delivery Service → Order Service: (Async, Kafka event like
DELIVERY_ASSIGNED
) to update delivery status.
✅ Why asynchronous?
- Delivery scheduling can take some time.
- If assigning a delivery boy or a delivery slot takes 2-5 seconds, the user shouldn’t be blocked waiting.
📦 Step 5: Shipment and Delivery Tracking
🔥 Services involved:
- Delivery Service
- Tracking Service
- Notification Service
📞 Communication:
User App → Tracking Service: (Sync, REST API) to get live delivery updates.
Delivery Service → Tracking Service: (Async, Kafka event
DELIVERY_STARTED
,OUT_FOR_DELIVERY
).Tracking Service → Notification Service: (Async, Kafka event
DELIVERY_UPDATE
) to send SMS/email.
✅ Why mixed?
- User polls tracking info synchronously for real-time updates.
- Internal updates like "out for delivery" are sent asynchronously.
🧩 Full Service Map (with communication type)
Service | Talks to | Communication | Why |
---|---|---|---|
User App → Product Service | Sync (REST) | Instant item list | |
User App → Cart Service | Sync (REST) | Add to cart feedback | |
User App → Order Service | Sync (REST) | Order placement feedback | |
Order Service → Payment Service | Sync (REST/gRPC) | Payment success/failure immediately | |
Order Service → Inventory Service | Async (Kafka) | Background stock update | |
Order Service → Notification Service | Async (Kafka) | Background email/SMS | |
Inventory Service → Delivery Service | Async (Kafka) | Delivery scheduling | |
Delivery Service → Tracking Service | Async (Kafka) | Background tracking updates | |
User App → Tracking Service | Sync (REST) | User polls for live updates |
🎯 Why do we use Sync vs Async?
Synchronous (REST/gRPC) | Asynchronous (Kafka/Event Bus) |
---|---|
User waits for result | No waiting needed |
Immediate feedback needed | Background process |
Critical: payment, add to cart | Non-critical: notifications, delivery |
Suitable for small, quick interactions | Suitable for heavy, long operations |
🔥 Key Takeaways
- Use Sync when user interaction is happening.
- Use Async when background services communicate.
- Kafka, RabbitMQ, or EventBridge are used for async.
- REST APIs or gRPC are used for synchronous needs.
- Scalability and resiliency are achieved by decoupling services via events.
📚 Real-World Example:
- Amazon uses a heavy combination of synchronous APIs and asynchronous event-driven microservices.
- Payments, Search, Cart = Mostly synchronous.
- Inventory, Delivery, Notification, Fraud Check = Mostly asynchronous via events.
✍️ Final Thought
Building a robust e-commerce platform involves understanding where to synchronize and where to decouple with asynchronous messaging.
Balancing these two wisely is the real art of microservice system design!