Lessons in this course (14)

11. Case study — chat / messaging system

Advanced★ Must knowLesson 11 of 14

Requirements: 1:1 and group chat, online presence, delivery/read receipts, message history, push notifications when offline.

  • Connections: WebSockets (SignalR in .NET) to chat servers; a connection registry (Redis) maps user → server.
  • Send flow: sender → chat server → persist message (store sorted by conversation + time; wide-column DB or SQL partitioned by conversation) → look up recipient's server → deliver over its WebSocket; if offline → push notification service (APNs/FCM) via a queue.
  • Ordering: per-conversation sequence numbers; client de-duplicates by message id.
  • Groups: fan-out to members (small groups) or members pull (large channels).
  • Presence: heartbeats with TTL in Redis; publish presence changes only to contacts.
  • Scale: chat servers scale horizontally; a pub/sub backplane (Redis / Azure SignalR Service) routes messages between servers.