advanced
Chat
Design connection management, message ordering, delivery receipts, presence, storage, fan-out, and offline sync.
Chat systems combine real-time delivery, message persistence, ordering per conversation, presence, read receipts, and offline sync. Typical architecture: WebSocket or SSE gateway, message service, conversation store (partitioned by chat ID), push notifications for offline users, and media via object storage.
Group chats multiply fan-out — consider message fanout service and per-user inbox materialization. Ordering uses server-assigned sequence per channel. End-to-end encryption changes storage and search trade-offs.
On interviews: draw send message flow, online versus offline delivery, and how you preserve order in a group chat.
Common pitfalls: WebSocket without reconnect and cursor sync; hot celebrity chat overloading single partition; storing all media inline in database.
Checklist:
- Real-time transport plus persistent store.
- Per-channel ordering and delivery acks.
- Offline push and catch-up sync.
- Partition storage by conversation ID.