Practice Hub /
Real-Time & CollaborationHard~40 min interview roundWhatsAppSlackDiscord

Real-Time Chat & Messaging App (WhatsApp Web)

Architect a desktop web messenger with IndexedDB offline outbox, WebSocket exponential backoff reconnect, virtualized scroll-from-bottom history, and read receipts.

1. Interactive System Architecture Diagram

Click any architecture component below to inspect its exact responsibilities and trace connected data flows.

Send / Scroll Outbox / Cache WS + Sync Upload Attachment Chat Pane UI Bottom Virtualizer Chat Store Normalized Threads IndexedDB Store Local History + Outbox Realtime Gateway WS + Exponential Backoff Media & Presigned Upload Encrypted Attachments
Selected ComponentChat Pane UI — Bottom Virtualizer
  • Maintains scroll-anchor pinning: auto-scrolls on new messages ONLY if user is near bottom.
  • Shows "2 new messages ↓" pill if user scrolled up reading older chat history.
  • Displays deterministic status ticks: `sending (clock) -> sent (1) -> delivered (2) -> read (blue)`.

2. Interactive Trade-Off Simulator

Toggle between real architectural options to compare Pros, Cons, and exactly when to pick each choice in interviews.

Client Persistence Layer

Where should thousands of cached chat messages and an offline outbox live?

Pros

  • Asynchronous non-blocking API handling hundreds of MBs + compound indexes `(chatId, timestamp)`.
  • Safe across tab refreshes without blocking the main UI thread.

Cons & Pitfalls

  • More verbose API (wrap with tiny helper or `idb`).
Interview Rule of Thumb: Pick IndexedDB for offline chat history, media caches, and durable outboxes.
Socket Reconnection

How should 100k clients reconnect when the chat server restarts?

Pros

  • Spreads reconnect load (`min(30s, 2^attempt * 1000) + rand(0..1000ms)`) so servers recover smoothly.
  • Immediately retries on browser `window.online` event for snappy user feel.

Cons & Pitfalls

  • Slightly longer wait after 4+ consecutive outages unless user clicks "Retry now".
Interview Rule of Thumb: Always use Jittered Exponential Backoff for WebSocket / SSE clients.

3. RADIO Framework Breakdown & Interview Checklist

Review each RADIO pillar cleanly and check off sections as you master them.

0 / 5 Sections Reviewed
R

Requirements & Scope

  • Functional: 1:1 & group chats, delivery/read receipts, offline compose, attachments, typing indicator.
  • Non-Functional: < 100ms optimistic render, ordered delivery (zero duplicates), resilient reconnect.
A

Architecture Components

  • WebSocket Manager (heartbeat + backoff) feeds Message Reducer & IndexedDB Outbox.
  • Reverse Virtualized Scroller preserves scroll position when prepending older history.
D

Client Data Model

  • `Message: { clientMsgId, serverSeq?, chatId, body, status: "sending"|"sent"|"delivered"|"read" }`
  • `ChatThread: { id, lastMsgId, unreadCount, typingUserIds[] }`
I

Interface & API Contracts

  • `GET /api/v1/chats/:id/messages?beforeSeq=500&limit=40` -> backward cursor paging.
  • WS Frames: `msg.send`, `msg.ack`, `msg.read` (debounced per visible batch), `typing`.
O

Performance & Optimizations

  • Compress photos inside Web Worker before uploading via presigned CDN links.
  • Debounce typing indicators (emit max once every 2s) and batch read-receipt ACKs.
  • Maintain scroll height delta `(newScrollHeight - prevScrollHeight)` on upward pagination.