FAANG System Design Interview: Design A Chat System (WhatsApp, Facebook Messenger, Discord, Slack)

· Source: ByteByteGo · Field: Technology & Digital — Software Development & Engineering, Cloud Computing & IT Infrastructure · Depth: Intermediate, medium

Summary

The article describes designing a chat system (like WhatsApp, Facebook Messenger, Discord, Slack) capable of handling real-time messaging for millions of users, supporting one-on-one and group chats up to 100 participants, guaranteeing message delivery, and showing online presence. It proposes a hybrid client-server communication approach using HTTP for sending messages and WebSockets for instant receiving. The system architecture is divided into three layers: stateless services (authentication, user profiles, message sending via REST APIs), stateful chat servers (handling persistent WebSocket connections), and third-party integrations (push notifications via APNS/FCM for offline users). Key mechanisms include the inbox pattern for guaranteed offline message delivery, service discovery and direct RPC for message routing between chat servers, and a fan-out pattern for group chats. Online presence is managed using 30-second WebSocket ping heartbeats, marking users offline after 60 seconds of no activity. Scaling challenges include connection bottlenecks, database limits, and cross-region routing complexity.

Key takeaway

For software engineers designing real-time chat applications, prioritizing a hybrid communication model with HTTP for sending and WebSockets for receiving is essential for balancing scalability and instant delivery. Implement an inbox pattern to guarantee message delivery for offline users, ensuring reliability. You should also integrate third-party push notification services like APNS or FCM to reach disconnected devices efficiently. For online presence, use 30-second WebSocket heartbeats, marking users offline after 60 seconds of inactivity to manage connection state effectively.

Key insights

Designing a scalable chat system requires a hybrid communication model, layered architecture, and robust mechanisms for message delivery and presence.

Principles

Method

The system design involves a hybrid HTTP/WebSocket communication, a three-layer architecture (stateless, stateful chat servers, third-party push notifications), an inbox pattern for guaranteed delivery, service discovery for message routing, and heartbeats for presence tracking.

In practice

Topics

Best for: Software Engineer, CTO, Consultant

Related on AIssential

Open in AIssential →

Editorial summary, takeaway, and curation by AIssential. Original article published by ByteByteGo.