Design a Direct Messaging System for an E-commerce Marketplace
WhatnotSoftware Engineer · Technical ScreenLast updated
Design a scalable 1:1 direct messaging platform for an e-commerce marketplace that supports real-time chat, message ordering, read receipts, and offline push notifications across multiple devices.
Scenario
In a live and social e-commerce marketplace, buyers and sellers frequently communicate directly to ask questions about product listings, negotiate prices, coordinate shipping, and resolve disputes. You are tasked with designing the 1:1 Direct Messaging (DM) platform to support this interaction.
Requirements
Functional Requirements
- 1:1 Messaging: Users can initiate chats and exchange text messages (up to 2,000 characters) in real time.
- Message Status & Ordering: Messages must display delivery status (
sent,delivered,read) and be presented to both parties in strict chronological order. - Offline Handling & Push Notifications: If a recipient is offline or disconnected, messages must be stored reliably, and a push notification must be triggered.
- Multi-Device Sync: A user logged in on multiple devices (e.g., mobile app and web browser) must see an up-to-date conversation state and synchronized read receipts.
- Listing Context: Messages can optionally be tied to a specific listing ID or order ID for context.
Non-Functional Requirements
- Low Latency: Real-time delivery latency should be under 200 ms for online users.
- High Availability & Durability: Zero message loss once acknowledged by the server (
at-least-oncedelivery semantics to the client with deduplication). - Scale Assumptions:
- 20 million Daily Active Users (DAU).
- Average of 50 million messages sent per day.
- Peak message generation rate: ~2,000 messages/second.
- 5 million concurrent WebSocket connections at peak.
What Your Design Should Cover
- High-Level Architecture: Protocol choices (WebSockets, HTTP/2, push services), connection management, and routing layers.
- Data Model & Storage: Database schema for conversations, messages, and delivery states, including storage engine selection for high-write chat workloads.
- Message Lifecycle & Delivery Semantics: Step-by-step flow from sender client to recipient client, handling ACKs, retries, and sequence numbering.
- Reconnection & Catch-Up: How clients sync unread messages and missed updates after disconnects or network switches.
- Trade-offs: Latency vs. strong ordering consistency, long-lived connection resource usage, and storage partitioning strategies.
Hints
Hint 1
Consider decoupling connection handling (stateful gateway servers) from business logic and message persistence (stateless services) using a message broker or distributed pub/sub.
Hint 2
To guarantee strict message ordering within a conversation, assign monotonically increasing sequence numbers or IDs scoped per conversation rather than relying purely on client or wall-clock timestamps.
Hint 3
For multi-device sync and reconnects, design a pull-based cursor or sequence-based sync endpoint that retrieves all events after the client's last acknowledged sequence ID.
Follow-up questions
- How would you extend this design to support rich media (images and short video clips) without saturating the real-time WebSocket connection layer?
- If a popular seller receives thousands of inquiries during a live auction stream, how do you prevent fan-in bottlenecks on that seller's connection and inbox?
- How would you implement end-to-end spam and fraud detection (e.g., detecting phone numbers or off-platform payment links) in real time without increasing delivery latency significantly?
Solution walkthrough is for members
Get the full walkthrough with reference code and complexity analysis, plus Kitty Coach at 300 messages a day. Hints, the code runner and community answers stay free.