94% Compression: Custom Serialization Patterns for Structured Data
We cut a React Flow agent-graph payload by 94% without losing a single node, edge, or coordinate. The trick wasn't reaching for gzip — it was designing a serialization format around what the data actually is: a structure with a known schema, not a bag of prose. When you stop sending generic JSON and start sending the structure, most of the bytes turn out to be redundant.
Generic JSON pays for the same keys over and over
A graph of 400 nodes serialized as idiomatic JSON repeats the strings "position", "data", "type", "sourceHandle" four hundred times. It ships default values that never changed. It encodes absolute coordinates that mostly differ from their neighbours by a few pixels. Every one of those is a byte you're paying to transmit, parse, and re-transmit — and none of them carry information.
Design the format around the data, not the other way around
The reduction came from three schema-aware moves, each lossless. Dedupe the keys: the schema is known, so field names live in one header, not on every record. Drop the defaults: if a node's type is the common case, omit it and reconstruct on read. Delta-encode the positions: store each coordinate as an offset from the last, so a tidy layout compresses to near-nothing. gzip on top of that is gravy; gzip on top of verbose JSON is lipstick.
// before: 1 record = repeated keys + defaults + absolute coords
{ "id": "n12", "type": "agent", "position": { "x": 740, "y": 320 }, ... }
// after: columnar header + omitted defaults + delta coords
schema: ["id", "type?", "dx", "dy"] // keys declared once
rows: [["n12", , 12, 8], ...] // type omitted = default; coords are deltasPayload is a budget — measure it like latency
The reason this is worth doing isn't bytes for their own sake. Payload size is a budget that buys you faster loads, cheaper bandwidth, and smaller diffs over the wire on every interaction. Teams instrument latency obsessively and never look at payload — yet on a real-time canvas, the payload is the latency. Treat it as a first-class metric and the 94% is just what falls out of taking it seriously.
Compression isn't something you bolt on at the end. The biggest wins come from encoding the data as what it is — structure with a schema — long before gzip ever sees it.
A small payload is half of feeling instant; the other half is streaming. This pattern grew out of the agent orchestration canvas. Continue on the roadmap.