KatInterview

Design a 1:1 Chat System for a Buyer-Seller Marketplace

System DesignModel answer
MediumModel answerSystem Designwebsocketsmessagingdistributed-systems

Last updated

Design a real-time direct messaging platform supporting message ordering, delivery receipts, offline notifications, and multi-device sync at marketplace scale.

Context

A social commerce marketplace lets buyers and sellers communicate directly — to clarify product details, agree on pricing, coordinate delivery, and settle disputes. You've been asked to design the 1:1 messaging feature that powers these conversations.

Functional Requirements

  • Direct messaging: Any two users can start a conversation and exchange text messages up to 2,000 characters in real time.
  • Message ordering and status: Both participants must see messages in strict chronological order. Each message progresses through three states: sent, delivered, and read.
  • Offline storage and push notifications: If the intended recipient is offline, the message must be durably stored and a push notification must be sent to their device.
  • Multi-device synchronization: A user signed in on both a mobile app and a browser must see a consistent conversation state — including read receipts — across all their devices.
  • Commerce context: A message may optionally reference a listing ID or order ID to give it context.

Non-Functional Requirements

  • Latency: End-to-end delivery to an online recipient should stay under 200 ms.
  • Durability: No message should be lost after the server has acknowledged receipt. Delivery semantics are at-least-once, with client-side deduplication.
  • Scale targets:
    • 20 million daily active users
    • 50 million messages sent per day
    • Peak send rate: ~2,000 messages/second
    • Peak concurrent WebSocket connections: 5 million

What to Cover

Your design should address:

  1. Architecture overview — protocol choices, connection management, and how traffic is routed between components.
  2. Data model and storage — schema for conversations, messages, and delivery state; choice of storage engine and rationale.
  3. End-to-end message flow — trace a single message from the sender hitting send to the recipient seeing it, including acknowledgements, retries, and deduplication.
  4. Reconnection and catch-up — how a client recovers missed messages after a disconnect or a device switch.
  5. Trade-offs — where you made deliberate choices and what you gave up: ordering guarantees vs. latency, connection memory overhead, storage partitioning, and so on.

Hints

Hint 1

Start by separating the stateful problem (holding open connections) from the stateless problem (processing and storing messages). Ask yourself: what does each tier actually need to know?

Hint 2

Message status (delivered, read) doesn't have to be stored per message. Think about what a watermark — a single high-water-mark sequence number per user per conversation — buys you compared to a status column on every row.

Hint 3

Reconnect and multi-device sync are really the same problem: a client needs everything that happened after a cursor it already holds. Design your API and data model so that a fresh connection and a returning device use the exact same code path.