Multiplexing Cheat Sheet
One page for recognizing multiplexing problems and designing a safe frame format.
When multiplexing fits
- Many logical conversations need one shared road: connection, thread, radio link, file descriptor, stream.
- Separate roads are expensive: handshakes, memory, sockets, ports, battery, latency.
- Some channels are idle while others could use the road.
- You can attach enough labels for the receiver to sort pieces back.
Minimum frame design
| Field | Why it exists | Example |
|---|---|---|
channelId | Demultiplex to the right logical conversation. | chat, stream 3 |
sequence | Rebuild chunks in order and detect gaps. | 0, 1, 2 |
data | Payload carried by this piece. | hell |
timestamp | Needed when playback time matters. | 33ms |
priority | Needed when urgent work must avoid waiting behind bulk work. | chat > file |
Common failure modes
- No labels: receiver cannot demultiplex.
- No sequence: chunks can arrive mixed and rebuild wrong.
- No fairness: huge stream blocks tiny urgent stream.
- No backpressure: sender overwhelms receiver memory.
- No timeout/close rule: dead channels leak forever.
- No observability: you cannot tell which channel is slow or broken.
Course mental map
| Domain | Shared road | Label | Demux target |
|---|---|---|---|
| Toy protocol | Transport | Channel ID | Logical channel |
| TCP/UDP host | Network interface | Protocol + IP + port | Socket/listener |
| I/O loop | One thread | Readiness event | Handler/callback |
| HTTP/2 | TCP connection | Stream ID | HTTP stream |
| Media | Packet stream | Track + timestamp | Playback track/time |