0
0
Computer Networksknowledge~15 mins

Flow control (stop-and-wait, sliding window) in Computer Networks - Deep Dive

Choose your learning style9 modes available
Overview - Flow control (stop-and-wait, sliding window)
What is it?
Flow control is a technique used in computer networks to manage the rate of data transmission between two devices. It ensures that the sender does not overwhelm the receiver with too much data at once. Two common methods are stop-and-wait, where the sender waits for an acknowledgment after each packet, and sliding window, which allows multiple packets to be sent before waiting for acknowledgments.
Why it matters
Without flow control, a fast sender could flood a slower receiver, causing data loss and network congestion. This would lead to poor communication quality, delays, and wasted resources. Flow control keeps data flowing smoothly and efficiently, making sure both sender and receiver work well together.
Where it fits
Before learning flow control, you should understand basic data transmission and acknowledgments in networking. After mastering flow control, you can explore error control, congestion control, and advanced protocols like TCP that use these techniques.
Mental Model
Core Idea
Flow control balances data sending speed so the receiver can handle incoming data without being overwhelmed.
Think of it like...
Imagine a water faucet filling a glass: stop-and-wait is like filling one glass at a time and waiting for it to be emptied before filling the next; sliding window is like filling several glasses at once before checking if they are emptied.
Sender Side                      Receiver Side
┌───────────────┐               ┌───────────────┐
│ Send Packet 1 │──────────────▶│ Receive Packet 1│
│ Wait for ACK  │◀─────────────│ Send ACK 1     │
└───────────────┘               └───────────────┘

Sliding Window Example:
[Packet 1][Packet 2][Packet 3][Packet 4]
  ↓        ↓        ↓        ↓
Receiver accepts multiple packets before sending ACKs.
Build-Up - 6 Steps
1
FoundationBasic concept of flow control
🤔
Concept: Flow control prevents data loss by matching sender speed to receiver capacity.
When two devices communicate, the sender might send data faster than the receiver can process. Flow control is the method that makes the sender pause or slow down to avoid overwhelming the receiver.
Result
Data is transmitted without overwhelming the receiver, reducing errors and lost packets.
Understanding that uncontrolled data flow causes errors helps appreciate why flow control is essential for reliable communication.
2
FoundationStop-and-wait flow control basics
🤔
Concept: Stop-and-wait sends one packet and waits for acknowledgment before sending the next.
In stop-and-wait, the sender transmits a single data packet and then stops to wait for an acknowledgment from the receiver. Only after receiving this acknowledgment does the sender send the next packet.
Result
Simple and reliable, but can be slow because the sender waits after every packet.
Knowing this method's simplicity helps understand its limitations in high-speed or long-distance networks.
3
IntermediateSliding window flow control introduction
🤔Before reading on: do you think sliding window sends packets one-by-one or multiple at once? Commit to your answer.
Concept: Sliding window allows sending multiple packets before waiting for acknowledgments, improving efficiency.
Instead of waiting for each packet's acknowledgment, sliding window lets the sender send several packets up to a set window size. The receiver acknowledges received packets, and the sender slides the window forward to send more.
Result
Higher data throughput and better use of network capacity compared to stop-and-wait.
Understanding this method reveals how networks achieve faster data transfer without losing control.
4
IntermediateWindow size and its impact
🤔Before reading on: does increasing window size always improve performance? Commit to yes or no.
Concept: Window size controls how many packets can be sent before waiting; it affects speed and reliability.
A larger window size means more packets sent before waiting for acknowledgment, which can increase speed. However, if the window is too large, it may cause congestion or overwhelm the receiver.
Result
Choosing the right window size balances speed and network stability.
Knowing the trade-off helps optimize network performance and avoid bottlenecks.
5
AdvancedHandling lost or delayed packets
🤔Before reading on: do you think sliding window automatically recovers lost packets without extra steps? Commit to yes or no.
Concept: Flow control methods include mechanisms to detect and recover lost or delayed packets.
Both stop-and-wait and sliding window use timeouts and retransmissions. If an acknowledgment is not received in time, the sender resends the packet. Sliding window protocols often use sequence numbers to track packets and acknowledgments.
Result
Reliable data transfer even with network errors or delays.
Understanding error recovery within flow control shows how networks maintain data integrity.
6
ExpertSliding window in real protocols like TCP
🤔Before reading on: do you think TCP uses fixed or dynamic window sizes? Commit to your answer.
Concept: TCP uses a dynamic sliding window that adjusts based on network conditions for optimal flow control.
TCP's sliding window size changes during communication depending on factors like network congestion and receiver capacity. This adaptive approach maximizes throughput while preventing overload.
Result
Efficient, reliable, and adaptive data transmission in real-world networks.
Knowing TCP's dynamic window management reveals how flow control adapts to complex network environments.
Under the Hood
Flow control works by coordinating sender and receiver states using acknowledgments and sequence numbers. The sender maintains a window of packets it can send without acknowledgment. The receiver tracks received packets and sends acknowledgments to inform the sender which packets arrived successfully. Timeouts trigger retransmissions if acknowledgments are missing. This coordination prevents buffer overflow at the receiver and manages network congestion.
Why designed this way?
Early networks had limited processing and memory capacity, so simple methods like stop-and-wait were used first. As networks grew faster and more complex, sliding window was designed to improve efficiency by allowing multiple packets in transit. The design balances simplicity, reliability, and performance, evolving to adapt to varying network conditions.
Sender Buffer
┌───────────────┐
│ Packet 1      │
│ Packet 2      │
│ Packet 3      │
│ Packet 4      │
└───────────────┘
      │
      ▼
[Window Size = 3]
Packets sent: 1, 2, 3
Waiting for ACKs...

Receiver Buffer
┌───────────────┐
│ Packet 1      │◀ ACK 1 sent
│ Packet 2      │◀ ACK 2 sent
│ Packet 3      │◀ ACK 3 sent
└───────────────┘

Sender slides window forward to send Packet 4.
Myth Busters - 4 Common Misconceptions
Quick: Does stop-and-wait send multiple packets before waiting for ACK? Commit yes or no.
Common Belief:Stop-and-wait can send several packets before waiting for acknowledgments.
Tap to reveal reality
Reality:Stop-and-wait sends only one packet at a time and waits for its acknowledgment before sending the next.
Why it matters:Believing otherwise leads to expecting high speed from stop-and-wait, causing confusion when performance is slow.
Quick: Does increasing sliding window size always improve network speed? Commit yes or no.
Common Belief:A bigger sliding window always means faster data transfer.
Tap to reveal reality
Reality:Too large a window can cause congestion and overwhelm the receiver, reducing performance.
Why it matters:Ignoring this can cause network slowdowns and packet loss, harming communication quality.
Quick: Does sliding window automatically fix all lost packets without retransmission? Commit yes or no.
Common Belief:Sliding window flow control alone guarantees no lost packets without extra mechanisms.
Tap to reveal reality
Reality:Sliding window requires timeouts and retransmissions to recover lost packets; flow control manages rate, not error correction alone.
Why it matters:Assuming flow control fixes all errors can lead to missing necessary error handling, causing data loss.
Quick: Is TCP's sliding window size fixed during a connection? Commit yes or no.
Common Belief:TCP uses a fixed sliding window size throughout the connection.
Tap to reveal reality
Reality:TCP dynamically adjusts its window size based on network conditions to optimize flow control.
Why it matters:Thinking the window is fixed prevents understanding TCP's adaptability and efficiency.
Expert Zone
1
Sliding window protocols often use cumulative acknowledgments, which acknowledge all packets up to a certain point, reducing overhead.
2
The choice of window size in sliding window protocols is influenced by the bandwidth-delay product, a measure of network capacity and latency.
3
TCP's flow control interacts closely with congestion control, making window size adjustments complex and dynamic.
When NOT to use
Stop-and-wait is inefficient for high-speed or long-distance networks due to waiting after each packet; sliding window is preferred. However, in very simple or low-resource systems, stop-and-wait may still be used. For networks with highly variable delays or errors, advanced protocols with selective acknowledgments or error correction may be better.
Production Patterns
In real networks, TCP uses sliding window with dynamic sizing and congestion control to optimize throughput. Protocols like HDLC and PPP implement sliding window for reliable link-layer communication. Stop-and-wait is sometimes used in simple embedded systems or initial protocol designs where simplicity is key.
Connections
Congestion control
Flow control manages sender-receiver speed, while congestion control manages overall network traffic load.
Understanding flow control helps grasp how networks prevent receiver overload, which complements congestion control's role in avoiding network-wide overload.
Producer-consumer problem (computer science)
Both involve managing the rate of production and consumption to avoid overflow or underflow.
Recognizing flow control as a producer-consumer synchronization problem clarifies its purpose in balancing data flow.
Traffic lights in road systems
Traffic lights control vehicle flow to prevent congestion, similar to how flow control regulates data packets.
Seeing flow control like traffic management reveals its role in orderly, efficient movement through a shared resource.
Common Pitfalls
#1Sending packets continuously without waiting for acknowledgments in stop-and-wait.
Wrong approach:Send Packet 1 Send Packet 2 Send Packet 3 // No waiting for ACKs
Correct approach:Send Packet 1 Wait for ACK 1 Send Packet 2 Wait for ACK 2 Send Packet 3 Wait for ACK 3
Root cause:Misunderstanding that stop-and-wait requires waiting after each packet to ensure reliable delivery.
#2Setting sliding window size too large for the receiver's buffer.
Wrong approach:Window size = 1000 packets Sender floods receiver buffer
Correct approach:Window size = receiver buffer capacity (e.g., 10 packets) Sender respects receiver limits
Root cause:Ignoring receiver capacity leads to buffer overflow and packet loss.
#3Assuming acknowledgments arrive instantly and never get lost.
Wrong approach:Sender never retransmits packets after sending once.
Correct approach:Sender uses timeout to retransmit if ACK not received in time.
Root cause:Overlooking network delays and losses causes unreliable communication.
Key Takeaways
Flow control ensures the sender does not overwhelm the receiver by managing data transmission speed.
Stop-and-wait is simple but inefficient for fast or long-distance networks because it waits after every packet.
Sliding window improves efficiency by allowing multiple packets to be sent before waiting for acknowledgments.
Choosing the right window size balances speed and reliability, preventing congestion and data loss.
Real-world protocols like TCP use dynamic sliding windows to adapt flow control to changing network conditions.