fivenines
18/39
Lesson 2.3

Reliable messaging: gaps, NAKs, retransmits

What you'll learn

How every consumer of a sequenced stream detects loss instantly and heals it — the transport layer everything since 1.7 has quietly assumed.

Part 2 now leans on one stream feeding many consumers: primary, standby, market data, post-trade, journals. Networks drop packets; four nines can't drop events. The fix is already in our hands: every message carries its sequence number, so any consumer can prove completeness locally. If you hold 500 and receive 502, you are missing 501 — no negotiation with the publisher required, detection is instant and certain.

sequenceDiagram
    autonumber
    participant P as Publisher
    participant R as Retransmit server
    participant C as Consumer
    P->>C: seq 500
    Note over P,C: seq 501 lost by the network
    P->>C: seq 502
    C->>C: gap! expected 501, got 502 — buffer 502
    C->>R: NAK — retransmit 501
    R->>C: seq 501 (from its journal copy)
    C->>C: deliver 501, then buffered 502 — order restored
    
Gap-and-fill. The consumer buffers ahead, requests exactly what's missing, and releases in order. Retransmit servers — themselves just subscribers that journal the stream — serve the fills, keeping recovery load off the publisher's hot path.

Why this beats the two obvious alternatives at exchange scale:

  • Versus per-consumer TCP: TCP gives one consumer reliability, but the publisher then carries per-connection state and — worse — one slow consumer's backpressure can stall the send path for everyone. Publish-once (multicast in colo, fan-out relays in cloud) with NAK-based repair keeps the publisher oblivious to its audience: fast consumers never wait for slow ones, and slow consumers repair themselves from retransmit servers.
  • Versus ACK-everything: positive acks make the publisher track every consumer's progress — the fan-in crushes it at scale. NAKs invert the deal: silence means healthy, and work happens only on actual loss, which is rare.

Two boundary details. Long gaps: a consumer that was down for an hour doesn't NAK a million messages — past a threshold it switches to recovery mode: snapshot + journal replay (1.7), then rejoins the live stream. Same machinery, no special case. Journal quorum: this is also where the 2.1 journal SPOF resolves — an event is accepted only once multiple independent journal replicas have acknowledged appending it. The primary's disk dying no longer threatens history; a quorum of journals is the history. (3.2 tightens exactly when that acknowledgment gates the trade.)

Key ideas
  • Sequence numbers make completeness locally provable — silence means healthy.
  • NAK + retransmit servers decouple the publisher from every consumer's fate.
  • Long gaps degrade gracefully into snapshot + replay; journal quorum kills the last storage SPOF.
Next step

See what actually stuck.

Take the practice scenarios now.