Flow control mechanism is to prevent sender from overwhelming the receiver. It controls the rate of sending packets by a sender through a buffer (window) maintained at sender side. This window moves to next set of packet(s) only when an acknowledgement is received from the receiver.
So, basically it works this way:
- Sender has a window of size N, while receiver has a window of size 1 (For simplicity we are considering Go Back to N). Sender Window was Packets number $#1, #2... #N$
- Sender sends $Packet #1, Packet #2 ... Packet #N$ to the receiver and waits for ACK.
- When senders gets ACK for Packet #1, it shifts a window to $Packet #2, Packet #3.. Packet #N + 1$
- When senders gets ACK for Packet #2, it shifts a window to $Packet #3, Packet #4.. Packet #N + 2$
- The process goes on
So, sender wants for receiver to ACK the packet so that it is not overwhelmed with lot of packets being sent to the receiver. That is the whole idea behind this mechanism that a faster sender must not overwhelm a slow receiver.
Internet as a whole can be considered a Queue of Packets. There are nodes which are putting packets and there are nodes which are picking packets from this queue. If there are too many nodes putting packets then what can be picked up from the queue by the nodes, then this degrades performance and is known as congestion. There can be several reasons for this congestion like bursty traffic, slow processing at nodes (routers).. etc. When congestion occurs, the routers drop the packets as they are unable to cope up with the flow. This means that when a device sends a packet and does not receive an acknowledgment from the receiver, in most the cases it can be assumed that the packets have been dropped by intermediate devices due to congestion. Remember that in case of Flow Control mechanism, it would retransmit the packets again to the sender, at the same rate (whatever amount of packets are in window). This would only cause more harm to the situation, right ?
While there are several methods to control this congestion in the network like Leaky Bucket, Token Bucket, but for for now, would only talk about TCP Congestion control mechanism. It works by setting the size of amount of data to be sent equal to the Maximum Segment Size (Negotiated during connection establishment). When an ACK is received for this segment, the maximum size of data that can now be sent is set to 2 MSS. When ACK is received for this, then the size of data that can now be sent is set to 4 MSS .. and so on. This keeps on doubling till a threshold is reached. If the ACK is not received, and the timer times out waiting for ACK, then the maximum size of data that can be sent is set to 1 MSS and the threshold is to half the size of maximum data which was last sent. This is called TCPs Additive Increase Multiplicative Decrease (AIMD).
So, while flow control is used to stop sender from overwhelming the receiver, the congestion control is used to dynamically control the flow of packets sent from sender to receiver so that the network as a whole remain within its carrying capacity.