Messaging gateway failover session resume

DesignMedium40 minMeta style

Your task

Design the region strategy for a real-time messaging/presence service where each connected client holds a long-lived WebSocket to a gateway in its nearest region, and the gateway holds in-memory session state (subscriptions, presence, unacked messages). Two requirements collide: clients want the nearest gateway for low latency, but when a gateway or whole region fails, clients must reconnect and resume their session (recent messages, presence) with minimal loss and within a couple seconds, without every gateway synchronously replicating every keystroke globally. Design connection routing, where session state lives, and the reconnect/failover path. Be explicit about what state can be lost vs must survive.

It covers

  • Session affinity
  • Stateful failover
  • State replication