We’ll design for:
| Principle | Purpose |
|---|---|
| Microservices | Separate concerns: search, cart, orders, etc. |
| Event-Driven | Decouple checkout, payments, notifications |
| CQRS | Use separate read/write models for scalability |
| Geo-Sharded | Data and traffic split by region |
| Eventually Consistent | Allow eventual sync where strict ACID is not needed |
| High Availability | Fault-tolerant, replicated services and storage |
Major domains:
| Platform | Function |
|---|---|
| Web, iOS, Android | Browse, search, add to cart, checkout |
| Admin Panels | Seller portals, inventory mgmt, order tracking |
| Service | Description |
|---|---|
| User Service | User profiles, addresses, preferences |
| Product Service | Product metadata, categories, variations |
| Inventory Service | Tracks real-time stock availability |
| Cart Service | Add/update/remove items |
| Checkout Service | Validates cart, reserves stock, creates order |
| Order Service | Tracks order state (placed → shipped → delivered) |
| Payment Service | Handles card/wallet/EMI integrations |
| Shipment Service | Assigns carriers, tracks deliveries |
| Review Service | Stores reviews, verifies purchases |
| Seller Service | Merchant data, pricing, offers, compliance |
| Promotion Service | Coupons, lightning deals, Prime offers |
| Component | Description |
|---|---|
| Catalog DB | Stores product metadata (title, description, price, images) |
| Inventory DB | Real-time stock per SKU/warehouse |
| Image CDN | Optimized image delivery via CloudFront/S3 |
| Versioned Index | Supports rollback during updates |
| Subsystem | Technology |
|---|---|
| Search Engine | Elasticsearch / OpenSearch |
| Auto-suggest Engine | Trie or ML-based on history |
| Recommendation Engine | Collaborative filtering + ML |
| Trending Engine | Real-time + batch analytics |
| Personalization | Vector embeddings of user-product context |
Cart Checkout →
- Validate inventory
- Create Order
- Reserve stock
- Process payment
- Trigger fulfillment
| Stage | Tool/Tech |
|---|---|
| Event Bus | Kafka (order_placed, payment_confirmed) |
| Fulfillment Service | Assigns warehouse, prints label |
| Packing & Dispatch | Tracks via carrier API |
| Order Lifecycle | Updates customer, triggers notifications |
| Return/Refund | Reverse transaction + inventory sync |
| Service | Description |
|---|---|
| Payment Gateway | Card, wallet, EMI, UPI, etc. |
| Tokenization | Secure vault for card details |
| Fraud Detection | Heuristics + ML models (e.g. location mismatch, bulk orders) |
| Ledger Service | Tracks debit/credit per transaction |
| Billing Service | Generates invoices, tax calculations |
| Data Type | Storage |
|---|---|
| Product Catalog | MySQL / Spanner |
| Inventory | Redis (real-time) + DB (durable) |
| Orders | Cassandra (append-only), or DynamoDB |
| Payments | SQL + secure vault |
| Reviews | MongoDB / Document DB |
| Search Index | Elasticsearch |
| Cache | Redis / Memcached |
| Image/Media | S3 + CDN (CloudFront) |
1. User browses → Product Service
2. Search suggestions → Search Service
3. Adds to cart → Cart Service (stored in Redis)
4. Checkout:
a. Cart validated
b. Inventory reserved
c. Order created
d. Payment processed
5. Kafka → Fulfillment Service assigns warehouse
6. Shipping scheduled, user notified
7. Kafka → Notification + Analytics + Recommendations
| Component | Strategy |
|---|---|
| Product Catalog | Sharded by product ID prefix |
| Order Services | Sharded by region & order ID |
| Kafka | Topic-per-domain, regional clusters |
| Payment | Global ledger + regional gateways |
| Search | Global index per region, merged for cross-border search |
| Inventory | Stored per-warehouse, synced globally |
| CDN | Edge caches for images, videos, and product pages |
| Concern | Approach |
|---|---|
| PII/PCI Security | Tokenization, encryption at rest, SOC2 compliant vault |
| Rate Limiting | IP/User based limits on sensitive APIs |
| KYC for Sellers | Required by Seller Service |
| Audit Logs | Append-only event store per user/session |
| Data Retention | Configurable per region (GDPR, CCPA) |
+-----------------+ +-------------------+ +---------------------------+
| Client (Web) | <---> | API Gateway | <---> | Core Microservices |
+-----------------+ +-------------------+ |---------------------------|
| - User Service |
| - Product Service |
| - Cart Service |
| - Inventory Service |
| - Order Service |
| - Checkout Service |
| - Payment Service |
| - Review Service |
| - Notification Service |
+------------+-------------+
|
+------------------ Kafka ------------------------------+
| | | |
v v v v
+------------------+ +------------------+ +-----------------+ +-----------------+
| Fulfillment Svc | | Analytics Engine | | Notification Svc| | Recommendation |
+------------------+ +------------------+ +-----------------+ +-----------------+
+-----------+ +--------------------+
| Elasticsearch | Redis (Inventory, Carts)|
+-----------+ +--------------------+
+--------------------------------------------+
| S3 + CloudFront (images/media/CDN) |
+--------------------------------------------+
| Feature | Note |
|---|---|
| Prime System | Different shipping rules, filters, seller eligibility |
| Lightning Deals | Queued inventory slots, auto-start/stop |
| Currency & Locale | Prices, languages, units localized |
| Multi-vendor Orders | Split order across multiple sellers/warehouses |
| Retry Logic | Payment, email failures handled via retries |