← System Design

Design a Real-time Chat UI

hard

Problem statement

Design a full-featured chat interface with WebSocket lifecycle management, optimistic message sends, typing indicators, read receipts, and history loading.

Asked In

SlackDiscordMeta (Messenger)WhatsAppIntercomZoom

Key Challenges

  • ·WebSocket lifecycle management (connect, reconnect, heartbeat)
  • ·Optimistic message sends with reliable rollback on failure
  • ·Typing indicators that don't spam the server
  • ·Read receipts delivered without blocking the read UI
  • ·Message ordering under concurrent sends and network jitter
★

2-Minute Answer — High-Level TL;DR

Read this before your interview

HLD Interview Focus

Model chat as a message log with stable client IDs and pending, accepted, delivered, read, and failed states. Show a pending bubble immediately, then reconcile the server acknowledgement without changing its UI identity. Server acceptance does not prove recipient delivery or reading. Retry with an idempotency key supported by the server. Reconnect with backoff and resume from a cursor, deduplicating events and fetching gaps. Load older history without moving the scroll anchor; follow new messages only when the reader is already at the bottom.

→

My Approach: Building the Solution

How to think about this problem

Start with a send whose acknowledgement is lost. Define retry identity, delivery-state meaning, and reconnect recovery before choosing transport and rendering history.

Why This Approach?

Optimistic UI improves perceived speed but requires reconciliation. Replayed events need deduplication; a socket connection alone cannot guarantee no message loss. Durable messages and ephemeral typing indicators need different lifecycles.

A chat send is like handing a numbered note to a courier. You already show the note on your desk (optimistic), the courier stamps an official number (server id), and if the courier never returns you still have the note with a retry stamp — you do not burn it.

R

Requirements: What Makes a Great Solution?

Clarify scope before designing anything

Requirements Exploration Questions

Ask your interviewer these questions to refine requirements

What chat model — 1:1 DMs, group channels, or threads?

  • ·1:1 DMs (simpler presence) vs group channels (N-user typing indicators)
  • ·Threaded replies vs flat message list
  • ·Maximum participants per channel (affects typing indicator design)

What persistence model is required?

  • ·Full message history (scroll back indefinitely) vs last N messages
  • ·Search across history
  • ·Message deletion / edit support

What real-time features beyond messages?

  • ·Typing indicators (who is typing)
  • ·Read receipts (seen by whom)
  • ·Online/offline presence indicators
  • ·Reactions / emoji responses

What are the reliability requirements?

  • ·Guaranteed delivery vs best-effort
  • ·Offline message queueing
  • ·Multi-device sync

Functional Requirements

Must Have — MVP

  • ✓Real-time message delivery via WebSocket
  • ✓Optimistic message send with status feedback (sending/sent/failed)
  • ✓Message list with scroll-to-bottom and jump-to-latest
  • ✓Typing indicator (debounced, auto-expires)
  • ✓Read receipts (mark as read when visible)
  • ✓Reconnection with gap-fill (fetch missed messages)
  • ✓Skeleton loading for initial channel load

Advanced (If Time Permits)

  • +Message reactions and threaded replies
  • +File/image attachments with upload progress
  • +End-to-end encryption key exchange
  • +Push notifications when tab is not active

Non-Functional Requirements

Performance

  • ·Message appears in < 50ms (optimistic, local)
  • ·Server round-trip ack < 200ms p95
  • ·Virtual list handles 10,000+ message history at 60fps

Reliability

  • ·Reconnect with exponential backoff and jitter
  • ·Resume from a cursor, deduplicate replayed events, and surface unrecoverable gaps
  • ·Server-supported idempotent sends using a stable client request ID

Scalability

  • ·Channels with up to 10,000 members
  • ·Typing indicators suppressed for channels > 50 members

Accessibility

  • ·New message announced via aria-live='polite'
  • ·Keyboard-navigable message list and input
  • ·Focus management on send (stay in input)
Premium

The full solution is part of HelloFrontend Pro

The question above is free to read in full. Upgrade to unlock the interactive workspace and the senior-level walkthrough that go with it.

  • Full RADIO-framework walkthrough with architecture diagrams
  • Data model, API design, and rendering strategy trade-offs
  • Performance, accessibility, and offline sections plus a model answer
Unlock the full solution →

Already a member? Log in to open the workspace.

More System Design questions

View all System Design →