By BluffKing · · Updated
WebSocket Traffic Reduction
A historical compact-JSON experiment cut bytes 22.3% and bytes per hand 23.3%. What it proved, and how today’s delta and compression transport differs.
In August 2026 the production instance began struggling at about 200 tables: at 300 tables it recorded 199 outbound-backpressure evictions while CPU and Postgres were not saturated. The same code ran 1,000 local tables on two Tokio workers at 1.2 ms action round-trip p99, but application JSON alone needed about 4.07 Mbit/s, twice the fixed 2 Mbps production link. So the limit was not CPU; the production outbound path was the leading suspect, though we had not yet separated Caddy, TLS, socket queues and the shaper.
We did not enlarge queues (with fixed egress they only hold congestion longer) or enable generic WebSocket compression (it would put secret cards and user-controlled text in one compression context, a side-channel risk). Instead the H5 client of that time explicitly negotiated wire=compact-v1: the server stopped repeating defaults (such as a zero pot or folded=false) and unchanged static fields, and dropped no-op frames that carried only cards:null to non-owners; H5 rebuilt the full state with deterministic rules. Clients without the parameter still received full JSON, and privacy projection ran before any field was omitted.
An A/B on the same machine, the same 1,000-table load and the same 20-second window cut JSON bytes from 10,177,073 to 7,912,044 (−22.3%) and bytes per completed hand from 5,451 to 4,182 (−23.3%), with action p99 still 1.2 ms and zero early closes. The optimized 3.16 Mbit/s was still above the 2 Mbps link, and the old code already held 1,000 tables locally, so this proved fewer bytes per hand, not that production capacity grew from 200 to 1,000 tables; only a production retest on the same ladder can show that.
The lesson: every field the server omits needs one deterministic, tested rule for rebuilding it in the client, or saved bandwidth turns into state divergence. This was a historical experiment; today’s transport uses delta envelopes with dictionary DEFLATE and Protobuf for public events, and the connection URL no longer carries a wire parameter, so these percentages do not apply to it. The later protocol comparison is in Protobuf at the Poker Table; the current code lives in server/src/ws_codec.rs and client-game/src/services/wsCodec.ts.