Skip to the page

Classic case studies · senior

Case study: chat app (WhatsApp Web / Slack)

A strong chat design uses one WebSocket with heartbeats and backoff, a message state machine keyed by a client id, server sequence numbers for ordering and catch-up, an outbox for offline sends, a bottom-anchored virtualised thread, and ephemeral typing and presence.

The notes

What you must know

  • Confirm 1:1 and groups, history, typing, read receipts, media, offline send, several tabs and devices. Transport: one WebSocket per client, multiplexed by conversation; heartbeat and reconnect with backoff + jitter; REST for history pages; media uploaded separately (pre-signed URL), then the message references it.
  • Message: { id, clientId, conversationId, senderId, seq, body, status, createdAt }; status pending → sent → delivered → read, or failed with Retry.
  • Ordering and catch-up: server seq per conversation; dedupe by clientId/id; after reconnect, GET messages?afterSeq=lastSeq; never sort by client clocks.
  • Store: conversations sorted by lastMessageAt; messages per conversation as ordered ids; unread counts from the server.
  • Offline: outbox in IndexedDB; the clientId doubles as the idempotency key so a resend can't duplicate.
  • Thread UI: virtualised and anchored to the bottom; load older on scroll up while keeping the scroll position (scroll anchoring); auto-scroll only if the user is already at the bottom, else show a 'new messages' pill.
  • Typing and presence: ephemeral, throttled (e.g. send 'typing' at most every 3 s), expire automatically; not stored with messages.
  • Notifications, safety and a11y: Push API via a service worker when the tab is hidden; BroadcastChannel keeps tabs in sync; render text safely and linkify carefully; a polite live region for incoming messages; focus stays in the composer. (Slack's client keeps a store per workspace and assumes data is loaded lazily.)

The red pen

Common traps: mistake → fix

  • Mistake: Order by client timestamps

    Fix: clocks differ between devices.

  • Mistake: No dedupe on reconnect

    Fix: messages appear twice.

  • Mistake: Re-render the whole thread for every new message or keystroke

    Fix: jank at 10k messages.

  • Mistake: Jump the scroll when older history loads

    Fix: the user loses their place.

Easy to hard

Questions interviewers ask, easy to hard

  1. Design WhatsApp Web's frontend: conversation list, thread, typing, receipts.
  2. The socket drops for 30 seconds. What happens?
  3. The user sends while offline. Walk me through it.
  4. A thread has 10,000 messages. How do you render and paginate it?
  5. How do two open tabs stay consistent?

Practise

Practise with these questions

Your first interview is free

Sign up and start with a 15-minute interview with the full report, and an English conversation. No card needed.

Start your free interview