← Lessons

quiz vs the machine

Gold1430

System Design

The Slack Realtime Messaging

Websockets plus per channel fan-out keep team conversations live and ordered.

5 min read · core · beat Gold to climb

Live by default

Slack feels instant because each client holds a websocket to a messaging server. New messages, typing indicators, and presence push down that socket without polling.

Channel fan-out

A message posted to a channel must reach every connected member. The server looks up who is subscribed to that channel and fans out the event to each of their sockets.

  • Clients connect via websocket to a gateway
  • The server maintains channel subscriptions per connection
  • A new message is pushed to all subscribed sockets

Ordering and history

Messages need a stable order. Each message gets a monotonic id within its channel, so clients can render in order and detect gaps. History is loaded from a durable store, while live updates arrive over the socket.

The realtime feel comes from pushing over persistent sockets, and correctness comes from per channel ordering.

Key idea

Hold a websocket per client, fan out each message to the channel subscribers, and assign a monotonic per channel id so everyone sees a consistent order.

Check yourself

Answer to earn rating on the learn ladder.

1. Why does Slack use websockets rather than polling?

2. What guarantees that members see channel messages in the same order?