Minimal serialization
By Robin Dowling · a year ago
When sending frequent updates in a real-time system, JSON wastes a surprising amount of bandwidth. Every key is wrapped in quotes, separated by colons, and repeated on every update. For small payloads, that overhead can be bigger than the actual data.
For example, a JSON delta update like:
{ "a": "Alice", "b": "30" }
is 23 bytes on the wire. By removing quotes, braces, and colons, and by making the first character of each segment the key, the same data becomes:
aAlice,b30
— just 14 bytes.
This compact format works best when keys are short and fixed, and values are simple strings. It’s trivial to encode and decode, and in high-frequency updates the savings add up quickly.
To go a step further, the system wraps this compact string format inside MessagePack binary frames. The serialization logic stays the same, but the transport layer encodes the result into MessagePack bytes and sends them over binary WebSocket frames, eliminating UTF-8 framing overhead and shaving off another ~20-30% on the wire.