Frontend

Designing a Chat System in Frontend System Design

Chat systems are one of the most common real-time frontend challenges, used in messaging apps, support systems, and collaborative tools. The goal is to build a responsive UI that can send, receive, and display messages in real time while handling network delays, ordering, and state consistency. This problem tests your understanding of real-time data flow, optimistic updates, and UI synchronization.

ByteAndBites·Jul 06, 2026
Designing a Chat System in Frontend System Design
Design a chat interface similar to WhatsApp, Slack, or a support chat.

Core requirements:
  • Send and receive messages in real time
  • Display messages in correct order
  • Show message status (sending, sent, failed)
  • Handle loading and reconnection
  • Maintain smooth scrolling experience
Follow-ups:
  • How do you handle real-time updates?
  • What happens if messages arrive out of order?
  • How do you handle offline users?
  • How do you optimize rendering for large chats?
  • How do you handle retries on failure?

How to Think About It (Framework)
  1. UI Layer
  2. Communication Layer
  3. State Management
  4. Message Lifecycle
  5. Caching / Persistence
  6. Performance
  7. Edge Cases

UI Layer
Main components:
  • Chat list (messages)
  • Input box
  • Send button
  • Status indicators

Behavior:
  • Messages aligned left/right (incoming/outgoing)
  • Auto-scroll to latest message
  • Preserve scroll when loading older messages

Communication Layer
Two approaches:
1. Polling (basic)
  • Client requests new messages periodically
  • Not efficient
2. WebSockets (preferred)
  • Persistent connection
  • Server pushes messages in real time
Flow:
  • Client connects via WebSocket
  • Server emits new messages
  • Client updates UI instantly
Basic Architecture
Basic Architecture

State Management
We need to manage:
  • messages: array of chat messages
  • sendingQueue: messages not yet confirmed
  • connectionStatus: connected / disconnected
  • loading: for older messages
  • error: failed messages
Important:
  • Separate server messages vs local temporary messages

Message Data Structure

Each message typically has:
id
text
senderId
timestamp
status (sending, sent, failed)
Data Layer
Data Layer

Message Lifecycle
  • User sends message
  • Message added locally (optimistic update)
  • UI shows "sending"
  • Server acknowledges
  • Update status → "sent"
In case of failure:
  • Show retry option
Optimistic UI
Key concept:
  • Show message immediately without waiting for server
  • Improves perceived performance
But:
  • Must handle failure cases
Blog image
Ordering & Consistency
Challenges:
  • Messages arriving out of order
  • Duplicate messages
Solutions:
  • Use timestamps or server sequence IDs
  • Deduplicate using message IDs
  • Always sort messages before rendering

Caching / Persistence
Basic:
  • Keep messages in memory
Advanced:
  • Store messages in localStorage / IndexedDB
  • Load previous messages on reload
Benefits:
  • Faster load
  • Offline support

Performance Optimization
  1. Virtualized List: Render only visible messages
  2. Pagination: Load older messages on scroll up
  3. Batching Updates: Avoid frequent re-renders
  4. Memoization: Optimize message components

Scroll Behavior
Key requirements:
  • Auto-scroll when new message arrives
  • Do NOT auto-scroll if user is reading old messages
  • Load older messages when scrolling up
Blog image

Error Handling
  • Failed message send
  • Connection loss
  • Retry mechanism
      
      Error UI:
  • Retry button
  • Error indicator
Blog image

Simple Flow
  1. User sends message
  2. Add message locally (optimistic)
  3. Send via WebSocket
  4. Server responds
  5. Update message status
  6. New messages pushed from server
  7. UI updates

What Interviewer is Testing
  • Understanding of real-time systems
  • Handling async flows
  • Optimistic UI design
  • State consistency
  • Performance awareness
System DesignJavascriptGoogleInterviewChat
Frontend System Design Playbook
Series
Frontend System Design Playbook
View series
A hands-on series focused on cracking frontend system design interviews at companies like Google, Atlassian, and Uber. Instead of theory-heavy discussions, this series breaks down real UI systems—like infinite scroll, autocomplete, caching, and complex state management—into clear, practical approaches with implementation-focused thinking.