How TCP avoids overloading the network.
Network congestion occurs when a network (or a part of it, like a router) is overloaded with more traffic than it can handle, leading to packet loss and increased latency. TCP has sophisticated, built-in mechanisms for congestion control to prevent this from happening. It's a way for a sender to regulate its sending rate based on the perceived state of the network. Unlike flow control, which protects the receiver, congestion control protects the network itself. TCP's congestion control is managed by maintaining a 'congestion window' (cwnd), which limits the amount of unacknowledged data a sender can have in transit. The process generally involves four main algorithms. 1) Slow Start: When a connection begins, TCP starts with a small cwnd (e.g., 1 or 2 segments) and doubles it for every ACK received. This allows the sending rate to increase exponentially until it reaches a certain threshold. 2) Congestion Avoidance: Once the threshold is reached, the sender switches to a less aggressive, linear increase, adding one segment to the cwnd for each round-trip time. 3) Congestion Detection: Congestion is typically inferred from packet loss, either through a timeout waiting for an ACK or by receiving duplicate ACKs. 4) Congestion Reaction: When congestion is detected, TCP drastically reduces its sending rate. For a timeout, it cuts the cwnd back to 1 and re-enters slow start. For duplicate ACKs, it typically halves the cwnd (this is called fast recovery). This additive-increase, multiplicative-decrease (AIMD) approach allows TCP to efficiently utilize available bandwidth while quickly backing off when congestion occurs.