A customer can view all or individual order statuses in real time
A business can view all or individual order statuses in real time
A business or customer can view granular statuses from order placement to shipping and location estimates to delivery notices or issues.
The system should have the capacity to provide a mostly read service to ~1000's of companies, ~1M's of customers
High Availability and reliability - if real time information experiences latency or goes down, the user must be presented with 'as close to' real time data as possible. AP wins here over C
Users must be shown graceful updating UI if not real-time to retain trust in the user.
Businesses - ~1000-3000 DAU
Customers - ~100K to ~1M DAU (3M peak?)
A status snapshot - uncompressed - ~3KB x 3M = ~8.5 GB of egress network data. Compression techniques like GZip at CDN edges are a must to save on costs
A Redis DB can easily fit this footprint for fast lookups without having to hit the primary DB.
Realistic daily usage -> Daily order volume is ~50K-100K orders/day or more if e-commerce
Each order generate multiple status events (placed -> confirmed -> packed -> shipped -> out for delivery -> delivered, plus exceptions). With updates, that's 500K-1M status writes/day.
Concurrent websocket connections is ~10-20% of DAU -> 100K-200K concurrent connections and each connection holds ~10-20KB for buffers -> ~2-4 GB just for connection state.
orders @ ~1-2 KB ea, status history and notification logs. At 100K orders/day, that's ~100 GB/year for orders alone.
Peak loads (scalability) -> Horizontal Pod Autoscalling. Use a load balancer to distribute traffic.
POST /orders
Request: { "product_id": "prod_123", "details": "{...}", "quantity": 10, "price": 15, "ship_address": "", "customer_id": "cust_123" }
Response: { "status": "ordered", "order_time": "
PATCH /orders/{id} -> update an order
DELETE /orders/{id} -> cancel an order
GET /orders?cursor=# -> paginated -> get a designated list of orders per cursor position and size to select
GET /orders/{id}/track -> individual order status
Real time websocket
ws://api.orders/com/ws/tracking
subscribe: { "action": "subscribe", "order_ids": ["ord_123", "ord_456" ] }
event: { "event": "status_change", "order_id": "ord_123", "status": "OUT_FOR_DELIVERY", "timestamp": "
Event types: status_change, location_update, exception (delay/attempt, failed)
Heart Beat ~30s to detect dead connections
Reconnect and catch-up - on drop, client reconnects with backoff and re-subscribes, server response with latest status - never misses transition
Security (AuthN & AuthZ): An api gateway intercepts requests to validate JWTs. For WebSocket, the initial handshake must include a valid JWT ensuring the user_id inside the token has authZ to subscribe to that specific order_id
Exception handling -> if the API fails, return a 500 or 503 which triggers an exponential backoff retry. Use circuit breaker pattern to stop
sending requests to a degraded downstream service.
Single point of failure - if event publishing or event consumer fails, we need to mitigate this with multiple instances of consumers and use retry + at-least-once deliver).
Server-side fallbacks - Use a DLQ for Kafka events and a Multi-AZ replication for PostgreSQL so a DB node crash doesn't bring down
the write path.
In-flight updates - We need a robust retry algo if Redis write fails. Add a retry or DLQ on the consumer
Users
Orders
OrderItems
StatusEvents
WebSocket Notification Engine
Database Layer