RamblerRambler
All posts
Engineering

How Rambler's WebSocket protocol works

A tiny framed protocol keeps the client and server in sync. A look at the frames behind every message.

The Rambler teamJune 4, 20265 min read

Everything you see in a Rambler room - a new message, someone joining, a reaction, a typing indicator - travels over a single WebSocket connection using a small, predictable protocol.

Outbound: key then payload

When the client wants to do something, it sends a frame that's a short key followed by a JSON payload - for example a join request or a chat message. The key tells the server which handler should pick it up. It's compact and trivial to read on the wire when you're debugging.

Inbound: one envelope for everything

Everything the server sends back shares one envelope shape: a type, an optional id, the subscription it belongs to, a timestamp, and the data. Because the shape is uniform, the client can route any message with a single switch - a chat message, a roster change, a ban, a rename - and the id doubles as the post identifier that reactions and replies target.

Handlers by reflection

On the server, request and response processors are discovered automatically at startup. Adding a new message type is mostly a matter of writing its contract and its handler; the wiring finds them. That keeps the protocol easy to grow without a central registry to keep in sync.

Small protocols age well. This one has room to grow while staying easy to reason about.

Comments

Loading comments…