Bird
Raised Fist0
Interview Prepcomputer-networksmediumAmazonGoogleFlipkartCRED

TCP Flow Control - Sliding Window & Congestion Control (AIMD)

Choose your preparation mode3 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Steps
setup

Initialize Sender and Receiver

The sender initializes its congestion window (cwnd) to 1 and slow start threshold (ssthresh) to 8. The receiver is ready to accept packets starting at sequence number 1.

💡 Setting initial cwnd and ssthresh is crucial to start TCP's congestion control and flow control mechanisms.
Line:cwnd = 1 ssthresh = 8 next_seq_num = 1 ack_expected = 1
💡 TCP starts cautiously with a small congestion window to probe network capacity.
📊
TCP Flow Control - Sliding Window & Congestion Control (AIMD) - Watch the Algorithm Execute, Step by Step
Watching the packet flow and window adjustments step-by-step reveals how TCP controls data transmission to avoid congestion and ensure reliable delivery, which is hard to grasp from code alone.
Step 1/17
·Active fillAnswer cell
Initialized sender cwnd=1, ssthresh=8; receiver ready for seq=1
Hop: 0
Sender
Receiver
Router1
Packet seq=1 sent, window size limits to 1 packet in flight
Hop: 1
Sender
Receiver
Router1
📦Packet
fromsender
toreceiver
📄 payloadseq=1
🔌 protocolTCP
🚩 flagsDATA
src10.0.0.1:50000
dst10.0.0.2:80
dataseq=1
flagsDATA
Sent: seq=1 from sender to receiver
Receiver processed seq=1, preparing ACK for seq=2
Hop: 2
Sender
Receiver
Router1
📦Packet
fromrouter1
toreceiver
📄 payloadseq=1
🔌 protocolTCP
🚩 flagsDATA
src10.0.0.1:50000
dst10.0.0.2:80
dataseq=1
flagsDATA
Sent: seq=1 from sender to receiver
Received: seq=1 at receiver
ACK for seq=2 sent, signaling successful receipt of seq=1
Hop: 3
Sender
Receiver
Router1
📦Packet
fromreceiver
tosender
📄 payloadack=2
🔌 protocolTCP
🚩 flagsACK
src10.0.0.2:80
dst10.0.0.1:50000
dataack=2
flagsACK
Sent: seq=1 from sender to receiver
Received: seq=1 at receiver
Sent: ack=2 from receiver to sender
Sender received ACK=2, cwnd increased from 1 to 2 (additive increase)
Hop: 4
Sender
Receiver
Router1
📦Packet
fromrouter1
tosender
📄 payloadack=2
🔌 protocolTCP
🚩 flagsACK
src10.0.0.2:80
dst10.0.0.1:50000
dataack=2
flagsACK
Received: seq=1 at receiver
Sent: ack=2 from receiver to sender
Received: ack=2 at sender
Sender sent packets seq=2 and seq=3 filling cwnd=2
Hop: 1
Sender
Receiver
Router1
📦Packet
fromsender
toreceiver
📄 payloadseq=2
🔌 protocolTCP
🚩 flagsDATA
src10.0.0.1:50000
dst10.0.0.2:80
dataseq=2
flagsDATA
Received: ack=2 at sender
Sent: seq=2 from sender to receiver
Sent: seq=3 from sender to receiver
Receiver processed seq=2, preparing ACK for seq=4
Hop: 2
Sender
Receiver
Router1
📦Packet
fromrouter1
toreceiver
📄 payloadseq=2
🔌 protocolTCP
🚩 flagsDATA
src10.0.0.1:50000
dst10.0.0.2:80
dataseq=2
flagsDATA
Sent: seq=2 from sender to receiver
Sent: seq=3 from sender to receiver
Received: seq=2 at receiver
ACK for seq=4 sent, acknowledging packets 2 and 3
Hop: 3
Sender
Receiver
Router1
📦Packet
fromreceiver
tosender
📄 payloadack=4
🔌 protocolTCP
🚩 flagsACK
src10.0.0.2:80
dst10.0.0.1:50000
dataack=4
flagsACK
Sent: seq=3 from sender to receiver
Received: seq=2 at receiver
Sent: ack=4 from receiver to sender
Sender received ACK=4, cwnd increased from 2 to 3 (additive increase)
Hop: 4
Sender
Receiver
Router1
📦Packet
fromrouter1
tosender
📄 payloadack=4
🔌 protocolTCP
🚩 flagsACK
src10.0.0.2:80
dst10.0.0.1:50000
dataack=4
flagsACK
Received: seq=2 at receiver
Sent: ack=4 from receiver to sender
Received: ack=4 at sender
Sender sent packets seq=4, 5, 6 filling cwnd=3
Hop: 1
Sender
Receiver
Router1
📦Packet
fromsender
toreceiver
📄 payloadseq=4
🔌 protocolTCP
🚩 flagsDATA
src10.0.0.1:50000
dst10.0.0.2:80
dataseq=4
flagsDATA
Sent: seq=4 from sender to receiver
Sent: seq=5 from sender to receiver
Sent: seq=6 from sender to receiver
Receiver processed seq=4, preparing ACK for seq=7
Hop: 2
Sender
Receiver
Router1
📦Packet
fromrouter1
toreceiver
📄 payloadseq=4
🔌 protocolTCP
🚩 flagsDATA
src10.0.0.1:50000
dst10.0.0.2:80
dataseq=4
flagsDATA
Sent: seq=5 from sender to receiver
Sent: seq=6 from sender to receiver
Received: seq=4 at receiver
ACK for seq=7 sent, acknowledging packets 4, 5, 6
Hop: 3
Sender
Receiver
Router1
📦Packet
fromreceiver
tosender
📄 payloadack=7
🔌 protocolTCP
🚩 flagsACK
src10.0.0.2:80
dst10.0.0.1:50000
dataack=7
flagsACK
Sent: seq=6 from sender to receiver
Received: seq=4 at receiver
Sent: ack=7 from receiver to sender
Sender received ACK=7, cwnd increased from 3 to 4 (additive increase)
Hop: 4
Sender
Receiver
Router1
📦Packet
fromrouter1
tosender
📄 payloadack=7
🔌 protocolTCP
🚩 flagsACK
src10.0.0.2:80
dst10.0.0.1:50000
dataack=7
flagsACK
Received: seq=4 at receiver
Sent: ack=7 from receiver to sender
Received: ack=7 at sender
Sender sent packet seq=7 filling cwnd=4
Hop: 1
Sender
Receiver
Router1
📦Packet
fromsender
toreceiver
📄 payloadseq=7
🔌 protocolTCP
🚩 flagsDATA
src10.0.0.1:50000
dst10.0.0.2:80
dataseq=7
flagsDATA
Sent: ack=7 from receiver to sender
Received: ack=7 at sender
Sent: seq=7 from sender to receiver
Receiver processed seq=7, preparing ACK for seq=8
Hop: 2
Sender
Receiver
Router1
📦Packet
fromrouter1
toreceiver
📄 payloadseq=7
🔌 protocolTCP
🚩 flagsDATA
src10.0.0.1:50000
dst10.0.0.2:80
dataseq=7
flagsDATA
Received: ack=7 at sender
Sent: seq=7 from sender to receiver
Received: seq=7 at receiver
Final ACK for seq=8 sent, confirming all packets received
Hop: 3
Sender
Receiver
Router1
📦Packet
fromreceiver
tosender
📄 payloadack=8
🔌 protocolTCP
🚩 flagsACK
src10.0.0.2:80
dst10.0.0.1:50000
dataack=8
flagsACK
Sent: seq=7 from sender to receiver
Received: seq=7 at receiver
Sent: ack=8 from receiver to sender
Sender received final ACK=8, cwnd increased from 4 to 5
Hop: 4
Sender
Receiver
Router1
📦Packet
fromrouter1
tosender
📄 payloadack=8
🔌 protocolTCP
🚩 flagsACK
src10.0.0.2:80
dst10.0.0.1:50000
dataack=8
flagsACK
Received: seq=7 at receiver
Sent: ack=8 from receiver to sender
Received: ack=8 at sender

Key Takeaways

TCP starts with a small congestion window and cautiously probes network capacity.

This cautious start prevents overwhelming the network and causing congestion early on.

Additive Increase Multiplicative Decrease (AIMD) allows TCP to grow cwnd linearly when no loss occurs.

Watching cwnd increase step-by-step shows how TCP balances throughput and congestion avoidance.

Cumulative ACKs efficiently confirm receipt of multiple packets, enabling sliding window advancement.

Visualizing ACK numbers clarifies how TCP confirms data receipt and controls flow.

Practice

(1/5)
1. When a user requests a web page through a CDN, what is the correct sequence of events if the requested content is not present in the edge cache?
easy
A. Edge server returns an error; user retries directly to origin server
B. Edge server serves stale cached content while asynchronously fetching fresh content
C. DNS server redirects user to origin server bypassing edge server
D. Edge server forwards request to origin server, caches response, then serves user

Solution

  1. Step 1: User request reaches edge server

    The edge server checks its cache for the requested content.
  2. Step 2: Cache miss triggers origin fetch

    If content is missing, the edge server forwards the request to the origin server.
  3. Step 3: Edge server caches the origin response

    Once the origin server responds, the edge server caches the content for future requests.
  4. Step 4: Edge server serves content to user

    The user receives the content from the edge server, reducing latency for subsequent requests.
  5. Final Answer:

    Option D -> Option D
  6. Quick Check:

    Edge servers act as intermediaries that fetch and cache content on cache misses.
Hint: Cache miss -> edge fetches origin -> caches -> serves user
Common Mistakes:
  • Assuming edge server returns error on cache miss
  • Thinking DNS redirects user directly to origin
  • Believing stale content is served without user awareness
2. You want to prevent unauthorized access to your internal network by filtering incoming and outgoing traffic based on IP addresses and ports. Which network component is best suited for this task?
easy
A. Proxy server acting as an intermediary for client requests
B. Firewall filtering traffic based on rules
C. Reverse proxy optimizing server load
D. Content Delivery Network (CDN) caching static content

Solution

  1. Step 1: Identify the role of each component

    Firewalls are designed to filter network traffic based on IP addresses, ports, and protocols, enforcing security policies.
  2. Step 2: Understand Proxy and Reverse Proxy roles

    Proxies forward client requests but do not primarily filter traffic at the network level; reverse proxies handle server-side requests and optimize load.
  3. Step 3: CDN role

    CDNs cache content to improve performance but do not filter traffic for security.
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    Firewall is the component that filters traffic based on rules [OK]
Hint: Firewall filters traffic; proxies forward requests.
Common Mistakes:
  • Confusing proxy with firewall as a security filter
  • Assuming reverse proxy filters traffic like a firewall
3. In which scenario is HTTPS preferred over HTTP for client-server communication?
easy
A. When the client and server are on the same trusted local network
B. When sensitive data like passwords or credit card numbers are transmitted
C. When the server wants to reduce latency by avoiding encryption overhead
D. When the client only needs to fetch static public content like images

Solution

  1. Step 1: Understand the purpose of HTTPS

    HTTPS encrypts data to protect confidentiality and integrity, especially for sensitive information.
  2. Step 2: Analyze each option

    A: On a trusted local network, encryption may be less critical, so HTTP might suffice.
    B: Sensitive data requires encryption to prevent eavesdropping, so HTTPS is necessary.
    C: HTTPS adds overhead; avoiding it to reduce latency sacrifices security.
    D: Static public content does not require encryption, so HTTP is often acceptable.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    HTTPS is essential when transmitting sensitive data to ensure security.
Hint: Use HTTPS whenever data confidentiality matters
Common Mistakes:
  • Assuming HTTPS is always needed regardless of data sensitivity
  • Believing HTTPS always causes unacceptable latency
  • Thinking HTTP is fine for sensitive data on any network
4. Which of the following is a limitation of using a proxy server for improving network security compared to a firewall?
medium
A. Proxy servers cannot filter traffic based on IP addresses and ports
B. Proxy servers cannot cache content to improve performance
C. Proxy servers introduce significant latency due to encryption overhead
D. Proxy servers block all incoming traffic by default

Solution

  1. Step 1: Proxy server capabilities

    Proxy servers act as intermediaries forwarding client requests but typically do not filter traffic at the IP/port level.
  2. Step 2: Firewall capabilities

    Firewalls filter traffic based on IP addresses, ports, and protocols, providing network-level security.
  3. Step 3: Evaluate other options

    Proxy servers can cache content (contradicts C), do not block all incoming traffic by default (contradicts D), but may introduce latency due to encryption overhead in some cases.
  4. Final Answer:

    Option C -> Option C
  5. Quick Check:

    Proxy servers may introduce latency due to encryption overhead, unlike firewalls [OK]
Hint: Proxy forwards requests; firewall filters traffic.
Common Mistakes:
  • Assuming proxies filter traffic like firewalls
  • Confusing caching capabilities of proxies
5. Why is it generally discouraged to use POST for operations that are intended to be idempotent, such as updating a user profile repeatedly with the same data?
medium
A. Because POST requests are cached by default, leading to stale data issues.
B. Because POST always deletes the resource before updating it.
C. Because POST cannot carry a request body, limiting update capabilities.
D. Because POST is not idempotent, repeated identical requests may cause unintended side effects.

Solution

  1. Step 1: Recall idempotency definition

    An idempotent method produces the same result no matter how many times it is repeated.
  2. Step 2: Analyze POST properties

    POST is not idempotent; repeated identical POSTs can create multiple resources or side effects.
  3. Step 3: Evaluate options

    Because POST is not idempotent, repeated identical requests may cause unintended side effects correctly identifies the non-idempotent nature of POST. Others are factually incorrect.
  4. Final Answer:

    Option D -> Option D
  5. Quick Check:

    POST is not idempotent, so using it for idempotent operations risks unintended consequences.
Hint: POST ≠ idempotent; PUT and DELETE are idempotent
Common Mistakes:
  • Thinking POST is cached by default (it is not)
  • Believing POST cannot carry a body (it can)
  • Assuming POST deletes resources before updating