Transport Layer Congestion Control and Leaky Bucket vs Token Bucket
Transport-layer congestion control prevents a sender from injecting traffic faster than the network can handle. In practice, transport protocols accomplish this via a feedback loop that uses loss and delay/ACK behavior as congestion signals, then adjusts the sending rate by changing the sender’s control variables (e.g., TCP’s congestion window).
Transport-layer congestion control and congestion window (cwnd) are tightly linked: TCP grows when the network appears healthy, and reduces it when congestion is inferred.
A key idea is that TCP uses:
- slow start
- congestion avoidance
- fast retransmit
- fast recovery
Important note (scope): There are multiple congestion-control designs across protocols. The most widely taught mechanism in textbooks is TCP Reno-style behavior. Other TCP variants (CUBIC, BBR) and QUIC congestion control differ in details, but the feedback-and-rate-adjustment principle remains the same.
TCP Congestion Control (cwnd, ssthresh, fast retransmit/fast recovery) — Tutorial
1) How transport-layer congestion control provides stability
At a high level, congestion control aims to keep the network in a regime where queues remain bounded and packet loss (or ECN marks) is rare.
TCP-style closed-loop control (conceptual)
- Start conservatively with a small to avoid overwhelming routers.
- Probe for capacity:
- If ACKs arrive without congestion indications, increase .
- React to congestion:
- Loss / timeout suggests queues are overflowing; reduce sharply.
- Duplicate ACKs suggest segment loss but route is still delivering other segments; reduce less drastically and recover faster.
This yields a control law that alternates between probing and backing off, preventing persistent overload.
Relationship to reliability mechanisms
TCP also has reliability mechanisms (ACKs and retransmissions). Congestion control is different: retransmissions can occur due to link errors, but congestion control treats certain retransmission patterns as congestion evidence and reduces future sending rate accordingly.
Duplicate ACK is therefore central: it provides earlier, finer-grained feedback than waiting for a timeout.
Transport-layer (TCP-style) congestion-control loop
- 1Step 1
Start with a small congestion window and a slow-start threshold; send up to worth of unacknowledged data.
- 2Step 2
Use incoming ACKs to measure how much data the receiver successfully got and infer network health.
- 3Step 3
If , increase rapidly (commonly exponentially) per successful acknowledgments.
- 4Step 4
If , increase more slowly (commonly roughly linearly) to probe capacity gently.
- 5Step 5
If a segment is lost, you’ll typically observe duplicate ACKs or eventually a timeout.
- 6Step 6
On duplicate ACKs, retransmit the missing segment and reduce (often multiplicatively) without returning to slow start.
- 7Step 7
On timeout, treat it as stronger congestion evidence: reduce substantially and return toward slow start behavior.
- 8Step 8
Continue the loop to converge around the path’s sustainable sending rate.
Pro Tip: Think in terms of “rate control with feedback”
Congestion control is essentially a feedback controller: ACK patterns and loss events act as sensor signals, and (or pacing rate) is the actuator.
Warning: Loss is not always congestion
Packet loss can come from wireless errors or link-layer problems. TCP often treats loss as congestion anyway—this can temporarily underutilize a clean link. ECN and modern algorithms aim to reduce this ambiguity.
2) Leaky Bucket vs Token Bucket: definitions and differentiation
Both leaky bucket and token bucket are classic traffic shaping and rate limiting algorithms used in the data plane (often implemented in routers/switches). They control how bursts are handled while enforcing a long-term average rate.
Key parameters:
- For token bucket: token generation rate and bucket capacity (burst size).
- For leaky bucket: drain rate and queue/buffer capacity.
Traffic shaping and rate limiting are the general goals.
Leaky bucket (queue that “leaks” at constant rate)
- Concept: A bucket holds up to bytes (or tokens representing bytes).
- A constant rate process removes (“leaks”) one unit per time interval.
- If packets arrive faster than the leak rate:
- buffer fills up to
- once full, arrivals are dropped (or delayed if implemented with queueing semantics).
This tends to create a smoother, more regular output stream.
Token bucket (bucket fills with tokens; sending consumes tokens)
- Tokens are generated at a fixed average rate up to a maximum capacity .
- To send/forward unit of data, you must “spend” (consume) token.
- If a packet arrives and tokens are available, it is forwarded immediately.
- If tokens are insufficient:
- the packet is typically delayed until enough tokens accumulate, or dropped depending on the implementation policy.
This allows bursty traffic up to the capacity while still enforcing the average rate over time.
3) Direct comparison table
| Feature | Leaky Bucket | Token Bucket |
|---|---|---|
| Output shape | Smoother, more “regular” rate | Allows bursts up to bucket size |
| Core mechanism | Queue drains at constant rate | Tokens accumulate at constant rate |
| Burst behavior | Generally limited by buffer; bursts get clipped by dropping when full | Bursts can pass as long as tokens were accumulated (up to ) |
| Long-term rate enforcement | Yes (average drain rate) | Yes (average token generation rate) |
| Typical action on excess | Drop when bucket/queue full | Delay until tokens available or drop if configured |
| Intuition | “Leak fixed; overflow is waste” | “Accumulate credits; spend to send” |
Intuition: Burst tolerance vs smoothing (conceptual)
Higher means the algorithm more naturally allows bursts before enforcement (ignoring implementation-specific drop/delay policies).
Edge cases and practical implementation details
Rate control behavior over time (conceptual)
Initial state
t0Token bucket may start with some tokens (up to ); leaky bucket starts with an empty/initial queue."
Burst arrival
High arrival burstToken bucket forwards immediately while tokens last; leaky bucket buffers then drops once buffer is full."
Sustained rate exceeds limit
Enforcement phaseBoth maintain average constraints: token bucket runs out of tokens and delays/drops; leaky bucket leaks at a fixed rate and overflows."
Traffic returns to compliant rate
RecoveryToken bucket regains tokens; leaky bucket buffer drains back toward empty."
Knowledge Check
In TCP congestion control, what is the main purpose of the congestion window (cwnd)?