← Lessons

quiz vs the machine

Gold1400

Networking

The Nagle Algorithm Tradeoff

Batching tiny writes against the delay it can add.

5 min read · core · beat Gold to climb

Coalescing Small Writes

The Nagle algorithm improves efficiency by combining many small writes into fewer, larger packets. It holds back a tiny segment until the previous data is acknowledged or enough bytes gather to fill a full packet.

The Benefit

Sending one byte in its own packet wastes header space, since the headers can dwarf the payload.

  • Nagle waits for an acknowledgment before sending another small segment.
  • Meanwhile it collects more bytes to send together.
  • This cuts the flood of tiny packets that a chatty sender would otherwise produce.

The Hidden Delay

The trouble appears when it meets delayed acknowledgment, where the receiver waits briefly before replying. The sender waits for an acknowledgment that the receiver is holding back, adding tens of milliseconds to small interactive messages.

For request and reply protocols that send small messages and need low latency, this pairing causes visible stalls, so latency sensitive sockets often disable Nagle.

Key idea

The Nagle algorithm batches small writes to save header overhead, but combined with delayed acknowledgment it can stall small interactive messages, so low latency sockets frequently turn it off.

Check yourself

Answer to earn rating on the learn ladder.

1. What problem does the Nagle algorithm try to reduce?

2. Which pairing causes the classic Nagle stall?

3. Why do many low latency sockets disable Nagle?