How-To Guide

How Slow Start and Congestion Control Affect APIs

See why fresh connections transfer slowly, why connection reuse wins throughput, and how to apply AIMD-style concurrency control in clients.

On this page

  1. Introduction
  2. The window mechanics
  3. Quantify the ramp on a large response
  4. Design responses for the initial window
  5. Prefer warm connections
  6. AIMD for application concurrency
  7. Measure transfer anatomy
  8. Common pitfalls
  9. Conclusion

Introduction

Transfer time is not bandwidth divided by size. A fresh TCP connection starts with a small congestion window and grows it one round trip at a time, so a large response begins life trickling rather than streaming. This is slow start, and it explains a class of performance mystery that bandwidth upgrades never fix: the ten-megabyte export that is fast on the second run and slow on the first, the cross-region replication that underperforms the line rate by an order of magnitude, the benchmark that improves when requests are warmed up. The mechanics live in the transport layer, but they are actionable from the application layer: connection reuse carries a warmed window, request sizing interacts with the initial window, and client concurrency can imitate the additive-increase, multiplicative-decrease discipline that made the internet stable. This tutorial explains the mechanics, quantifies the effect, and converts both into concrete client and server behavior.

The window mechanics

TCP tracks a congestion window, cwnd, the number of bytes it is willing to have in flight. A new connection begins with a small initial window, ten segments or roughly 14 kilobytes per RFC 6928. During slow start, cwnd doubles every round trip in which no loss occurs: roughly 14 kilobytes, then 28, then 56, climbing exponentially until it crosses the slow-start threshold. After that, congestion avoidance takes over and cwnd grows additively, one segment per round trip, probing for spare capacity. Loss, or an explicit congestion signal, cuts the window multiplicatively. This AIMD discipline is why TCP flows share links stably instead of oscillating into collapse. Two consequences matter for applications. First, throughput ramps over multiple RTTs, so a transfer shorter than the ramp never reaches line rate. Second, the ramp resets to the start on every new connection, which is why a connection that has already survived a transfer is measurably faster for the next one.

Quantify the ramp on a large response

Consider a ten-megabyte response over a 50-millisecond RTT link with 100 megabits per second of available bandwidth. Line-rate transfer time would be about 800 milliseconds. The window tells a different story. Reaching a 12-megabit window, enough to saturate the link at this RTT, requires the cwnd to grow from 14 kilobytes through roughly nine doublings, which is nine round trips, or 450 milliseconds, before full throughput is even available. The transfer then completes in the remaining time, so total latency lands around 1.25 seconds, more than fifty percent over the line-rate ideal. On a 150-millisecond intercontinental RTT, the ramp alone costs 1.35 seconds. The same transfer on a connection that has already carried data sits in congestion avoidance with a large window and completes near the line-rate ideal. This arithmetic is the entire argument for connection pooling on large transfers, and it also explains why first-load benchmarks are consistently pessimistic: they measure the ramp, not the throughput.

Design responses for the initial window

The first round trip can carry roughly 14 kilobytes regardless of bandwidth. That number should shape response design. Keep critical documents, API bootstrap payloads, and the first screen of data under the initial window so they arrive in one RTT. Paginate large collections by default with a page size in tens of kilobytes rather than megabytes. Compress before transfer: gzip or brotli frequently moves a payload under the window threshold at negligible CPU cost, converting a multi-round-trip response into a single-round-trip one. For genuinely large exports, prefer a streaming shape, where the client begins processing the first bytes while later bytes are still ramping, over a monolithic one that cannot start until the body completes. These are not micro-optimizations; they determine whether the user-perceived latency of a cold fetch is one RTT or ten.

Prefer warm connections

Every technique from connection pooling applies with extra force to large transfers. A pooled connection that recently carried traffic retains its window, so the next large transfer skips the ramp. This is why throughput-sensitive pipelines, database dumps, object replication, and log shipping, should pin long-lived connections rather than opening fresh ones per batch. It also interacts with load balancing: a per-request load-balancing strategy that opens a new connection each time re-pays the ramp on every request, while session affinity or a connection-pool-aware balancer lets windows stay warm. Idle timeouts cut against this, since a connection that sits idle long enough to be evicted loses its history along with its socket, so aligning idle timeouts with actual request cadence preserves warmed windows. On the server side, enabling HTTP keep-alive and HTTP/2, which multiplexes streams over one warm connection, converts this transport behavior into user-visible throughput for free.

Client configuration makes warm reuse the default rather than the accident:

import https from 'node:https';

const agent = new https.Agent({
 keepAlive: true,
 keepAliveMsecs: 30_000,
 maxSockets: 8,
});

// the first transfer pays the ramp; the connection keeps its window for the next
https.get({ host: 'internal-export', path: '/dump.csv', agent }, (res) => {
 let bytes = 0;
 res.on('data', (chunk) => { bytes += chunk.length; sink.write(chunk); });
 res.on('end', () => console.log('transferred', bytes));
});

// an immediate second transfer on the same warm connection runs near line rate
https.get({ host: 'internal-export', path: '/dump2.csv', agent }, drain);

AIMD for application concurrency

The stability argument behind congestion control applies unchanged to clients deciding how many concurrent requests to send a server they cannot fully observe. Additive increase, multiplicative decrease: raise concurrency slowly while requests succeed, cut it sharply when the system signals distress. The distress signals in HTTP are 429 and 503 responses, connect timeouts, and latency spikes; all of them mean the offered load exceeds capacity somewhere.

export class AimdController {
 private concurrency = 4;

 constructor(private min = 1, private max = 64) {}

 current() { return this.concurrency; }

 onSuccess() {
  this.concurrency = Math.min(this.max, this.concurrency + 1);
 }

 onCongestion() {
  this.concurrency = Math.max(this.min, Math.ceil(this.concurrency / 2));
 }
}

Driving a semaphore with this controller produces a client that finds available capacity within a few round trips and sheds half its load the moment the server pushes back, instead of oscillating between timeout storms and idle capacity. It composes with retry: retries consumed on congestion signals should feed onCongestion, not just fire again at the same concurrency.

Measure transfer anatomy

Make the ramp visible before optimizing it. Packet-level analysis with tcpdump or a summarizing tool shows cwnd growth directly, but three application-level measurements usually suffice. Compare cold versus warm transfer time for the same large object: a persistent gap is the ramp. Instrument bytes received over time on the client and plot the throughput curve: a ramp shape means window growth dominates, while a flat low line means bandwidth or path limits dominate. Correlate with connection reuse flags from the HTTP client, httptrace in Go or event timing in the browser, to confirm which transfers rode fresh connections. These three views distinguish the transport-limited case this tutorial addresses from the genuinely bandwidth-limited case, where no amount of connection warmth helps and the fix is compression, smaller payloads, or a better path.

Common pitfalls

  • Benchmarking cold connections. First-request numbers measure the slow-start ramp, not steady throughput; warm up before measuring.
  • Fresh connections for large batches. Every batch repays the ramp; pin and reuse connections for throughput pipelines.
  • Monolithic multi-megabyte responses. The window grows while the user waits; paginate, stream, or compress under the initial window.
  • Concurrency without backoff. A fixed high concurrency converts server distress into timeout storms; AIMD sheds load when signaled.
  • Ignoring HTTP/2 for parallel streams. Multiplexing over one warm connection replaces the per-connection ramp on parallel traffic.
  • Attributing ramp cost to bandwidth. Buying more bandwidth cannot shorten the ramp; fewer round trips or warm connections do.

Conclusion

Slow start and congestion control explain the gap between line rate and real transfer time. A fresh connection begins with a small window and buys throughput one round trip at a time, so large cold transfers pay a ramp tax that bandwidth cannot remove. Three behaviors convert the mechanics into advantage: keep first-round-trip payloads under the initial window, reuse warm connections for large transfers, and let client concurrency follow AIMD discipline, additive growth on success, multiplicative cut on congestion signals, so clients find capacity without stampeding it. Measure the ramp explicitly, cold versus warm transfers and throughput over time, before optimizing, because transport-limited and bandwidth-limited problems have different fixes and only one of them is fixed here.

Sources: RFC 5681: TCP congestion control, RFC 9002: QUIC congestion control, MDN: Connection management in HTTP/1.x.

FAQ

Does slow start affect small API responses?
Barely. A response under about 14 kilobytes fits in the initial congestion window and leaves in the first round trip. The effect grows with body size: ten megabytes can spend more round trips growing the window than the bandwidth itself justifies.
Is congestion control different on HTTP/3?
Yes in mechanism, no in consequence. QUIC implements its own congestion control per RFC 9002, but the slow-start ramp and the benefit of avoiding new connections remain, so the operational guidance is unchanged.
How is this different from rate limiting?
Rate limiting is a server policy about request counts. Congestion control is transport feedback about capacity. A well-behaved client responds to both: it respects quotas and backs off multiplicatively when the network or server signals distress.

Related Examples