Serialization Formats
Beyond JSON — Protobuf, MessagePack, FlatBuffers, Cap'n Proto, Avro, CBOR.
Most APIs are JSON over HTTP and that's fine. Reach for the below when you have schemas you want to enforce, payloads you want smaller, or languages you want to interop across.
Schema-defined binary
- ★ Protocol Buffers (Protobuf) — Google's; widely used; tooling for every language. Use
buffor builds + lint + breaking-change detection. - FlatBuffers — zero-copy reads, especially fast for game / mobile. Bigger learning curve.
- Cap'n Proto — similar idea to FlatBuffers;
infinity:1zero-copy; less common in JS. - Apache Avro — schema-evolving binary; Hadoop / Kafka heritage; popular in data engineering.
- Apache Thrift — older Facebook / Apache; uncommon for new code.
Schema-free binary
- ★ MessagePack — JSON-shaped, smaller, fast; drop-in for many use cases.
@msgpack/msgpackis the maintained TS lib. - CBOR (RFC 8949) — IETF binary JSON; standard underlying WebAuthn / COSE.
- BSON — MongoDB's binary JSON; less common outside Mongo.
- UBJSON — universal binary JSON; niche.
RPC frameworks (built on top)
- ★ gRPC — Protobuf + HTTP/2;
@grpc/grpc-jsin Node,nice-grpcfor ergonomics. - ★ Connect-RPC (
@connectrpc) — Protobuf-defined services that work over HTTP/1, HTTP/2, gRPC, and gRPC-Web. Great browser story. The default new Protobuf-RPC pick. - Twirp — older, simpler Protobuf RPC.
- Cap'n Proto RPC — bundled.
- JSON-RPC — text-based; still used (LSP, Ethereum, etc.).
TS-flavored (no codegen)
- See Backend for tRPC, oRPC, ts-rest. These give you typed RPC without separate IDLs.
When to leave JSON
- Cross-language services with stable contracts: Protobuf + Connect-RPC.
- Browser → server payload size matters: MessagePack as a JSON drop-in.
- Game-tier latency / zero-copy parsing: FlatBuffers.
- Kafka topics with strong schema evolution: Avro.
- WebAuthn / hardware tokens: CBOR (you'll touch it via
cbor-x).
TS libraries
@bufbuild/protobuf+@connectrpc/connect-web/-node/-fastify— modern Protobuf in TS.google-protobuf— official; older API.@msgpack/msgpack— MessagePack.cbor-x— fast CBOR for Node + browser.flatbuffers— official FlatBuffers JS.avsc— Avro for Node.@bufbuild/buf— buf CLI for Protobuf workflows.
Pick this if…
- Default cross-language RPC: Protobuf + Connect-RPC.
- JSON-shaped but smaller: MessagePack.
- WebAuthn / IoT / constrained devices: CBOR.
- Kafka with schema evolution: Avro.
- Same language only, full TS: stick with JSON over tRPC / oRPC.