KatInterview

Real-Time Direct Messaging Plus Dormant-Customer Email Campaign

System DesignModel answer
MediumModel answerSystem Designwebsocketmessage-routingpresence

Last updated

Design a WebSocket-based one-to-one messaging service with presence and history, plus a scheduled pipeline that emails customers who have been dormant for ten days.

Context

You are building shared infrastructure for a ticketing and events marketplace. Two capabilities must live on the same platform:

  1. An internal direct-messaging tool for staff.
  2. A win-back email workflow aimed at customers who have gone quiet.

Part 1: Staff messaging

  • Two employees can exchange messages one-to-one, with delivery in real time.
  • Clients keep a long-lived WebSocket open.
  • Any client can land on any chat server, so the sender and the recipient will often be attached to different servers.
  • A recipient who is online should get the message right away. If they are offline, the message must be kept and handed over later.
  • Show whether a user is online, and provide a basic, paginated conversation history.
  • Describe how messages travel between servers in both directions over the sockets.

Part 2: Win-back emails

Add a process that emails every customer who has not logged in for 10 days.

What to cover

Walk through the high-level architecture, the client and server APIs, storage choices, cross-server routing, how inactivity is detected, scaling, reliability, and failure handling. State your assumptions about scale and justify the main trade-offs.

Hints

Hint 1

Treat the two features as separate subsystems that only share identity and an event stream. The chat side is stateful and latency-sensitive; the email side is a scheduled, high-volume batch with idempotency concerns.

Hint 2

For routing, keep a fast registry that maps each user to the server(s) holding their socket, and give each server its own inbound channel. Persist the message before acknowledging the sender, so a lost forward can be recovered through a reconnect sync.

Hint 3

For the email job, think about how to find 'inactive for 10 days' without scanning every customer, and how to make sure a retry or a re-run of the job never sends the same person two emails for the same dormancy period.