Why are both flow control and congestion control procedures required in a TCP connection - What mechanisms does the TCP protocol use to implement these?
In short: Flow control makes sure that the receiver is never overloaded with more data it can handle whereas congestion control is used to avoid congesting the network between sender and receiver.
Flow control: each ACK the receiver sends to the sender includes the current size of the receive window, which states how many more bytes fit into the receive buffer. This procedure is called the sliding window protocol.
Congestion control: after TCP was introduced, it was noticed, that too much traffic resulted in a so-called congestion of the network: not all packages could be delivered when the network bandwidth was exceeded. The TCP implementation reacts to missing ACKs by sending these packets again, which however only makes the situation worse, as the network becomes even more congested.
The answer to this problem is the congestion control. It is quite complex, but basically what happens is, that as soon as a message can't be delivered (when a message isn't acknowledged after a certain timeout, it is considered that the message couldn't be delivered), it is assumed that the package was lost because of a congestion in the network, and the sending rate is reduced. This is also implemented using a sliding window, the congestion window. The actual algorithm is more complex, it nowadays includes the slow-start, congestion avoidance, fast retransmit, and fast recovery algorithms.
At any given moment, a TCP implementation is allowed to send at most
min(receive window, congestion window) unacknowledged packets to respect both the flow control and the congestion control.
Flow control is used to help prevent overloading the receiver with too much data. Flow control uses a sliding window in which the receiver states how much they are able to receive and buffer so that the sender does not send to much data.
Congestion control, or congestion avoidance, is used to help avoid the congestion that could occur in the event of packet loss; the packet loss or packet re-ordering could lead to duplicate ACKs being received. Congestion control uses a window similar to flow control in order to limit the number of unacknowledged packets sent.