WebSocket Gateways, Message Persistence, and Delivery

Clients connect to WebSocket gateways that authenticate sessions and maintain connection state. A message submission is authorized, persisted, assigned an ordering position, and then distributed to connected recipients. For durability, acknowledge only after the chosen persistence boundary succeeds.

Gateways may publish recipient events through a broker so any gateway can deliver to its connected clients. Maintain a mapping from user/device to gateway, but treat it as transient and repairable. Reconnection should resume from a cursor rather than assume every push was received.

Use per-conversation partitioning where it helps preserve order and distribute load. Large group chats can create fan-out spikes; batch deliveries, apply backpressure, and distinguish accepted, persisted, delivered, and read states. These are different events and should not be conflated.

Chat message flow
Key Takeaways
  • Persist before acknowledging durable message acceptance.
  • Use a broker or routing layer to reach clients on other gateways.
  • Define the meaning of every message status.