Communication & Data Transfer/Deep Cuts (Optional)

Custom Binary Protocols & Framing

Length-prefix framing, TLV formats, Protocol Buffers on raw TCP, HTTP/2 vs custom, and when FAANG teams still invent protocols.

5/5Overview: 35m

When custom protocols still happen

  • Ultra-low latency trading, gaming — UDP + custom framing
  • Embedded / IoT — constrained bandwidth
  • Legacy mainframe — fixed-width records
  • High-throughput internal — when protobuf+gRPC overhead still too high (rare)

Default answer in 2026: don't invent — use gRPC/protobuf unless profiling proves need.

Framing problem on TCP

TCP is a byte stream — no message boundaries. Protocols need framing:

StyleFormat
Length-prefix[4-byte len][payload]
Delimiternewline-terminated JSON (fragile)
TLVtype, length, value chains
HTTP/2frames (standard)

Partial read loop: buffer until full frame available; handle EAGAIN.

Versioning binary protocols

  • Header includes version byte
  • Unknown version → reject connection
  • New fields at end with length — forward compatible if readers skip unknown TLV

Same rules as protobuf field numbers.

Protobuf on raw TCP

Pre-gRPC pattern: length-delimited protobuf messages. gRPC standardized this with HTTP/2 headers + trailers.

Cap'n Proto / FlatBuffers

Zero-copy read — no decode step. Wins in games, browsers parsing maps. Ecosystem smaller than protobuf.

Security

Custom TCP protocols need TLS wrapper (or Noise protocol). Roll your own crypto = failure mode.

Interview framing

If asked "design a protocol":

  1. Requirements (latency, reliability, browser?)
  2. Pick TCP vs UDP (Networking)
  3. Framing + schema (protobuf)
  4. Auth, versioning, observability
  5. Only then optimize

Demonstrates restraint — staff engineers choose boring technology.

Further Reading

Hands-On Tasks (Optional)

API design drills and whiteboard exercises — protocol selection, contract design, and bulk-transfer architecture. Assumes Networking and sibling tracks on the hub page (Distributed Systems, Databases, Concurrency, LLD).

  • Design a length-prefixed frame format

    Binary protocol over TCP: header (version, type, length, checksum), payload. Handle partial reads, max frame size, and protocol evolution.

    20m