Bird
Raised Fist0
Interview Prepcomputer-networkseasyAmazonGoogleMicrosoftFlipkartSwiggyRazorpay

HTTP Status Codes - 2xx, 3xx, 4xx, 5xx - When Each Fires

Choose your preparation mode3 modes available
▶
Steps
setup

Client prepares HTTP request

The client node creates an HTTP GET request packet to send to the server. The packet is initialized with the request method and target resource.

💡 This step sets up the initial HTTP request packet, which is the starting point for the entire communication and status code determination.
Line:pass # No code needed for mechanism depth approach
💡 The HTTP request packet contains the information that will determine the server's response status code.
📊
HTTP Status Codes - 2xx, 3xx, 4xx, 5xx - When Each Fires - Watch the Algorithm Execute, Step by Step
Watching the packet flow and status code triggers step-by-step helps you understand when and why each HTTP status code category (2xx, 3xx, 4xx, 5xx) is fired in real network communication.
Step 1/10
·Active fill★Answer cell
Client created and sent HTTP GET request packet to Router 1
Hop: 1
Client
Router 1
Server
📦Packet
↗ fromclient
↘ torouter1
📄 payloadHTTP GET /index.html
🔌 protocolHTTP
🚩 flagsrequest
src→192.168.1.2:12345
dst→10.0.0.1:80
data→GET /index.html HTTP/1.1
flags→request
HTTP GET /index.html: client→router1
Router 1 forwarded HTTP GET request packet to Server
Hop: 2
Client
Router 1
Server
📦Packet
↗ fromrouter1
↘ toserver
📄 payloadHTTP GET /index.html
🔌 protocolHTTP
🚩 flagsrequest
src→192.168.1.2:12345
dst→10.0.0.1:80
data→GET /index.html HTTP/1.1
flags→request
HTTP GET /index.html: router1→server
Server started processing HTTP GET request
Hop: 3
Client
Router 1
Server
📦Packet
↗ fromrouter1
↘ toserver
📄 payloadHTTP GET /index.html
🔌 protocolHTTP
🚩 flagsrequest
src→192.168.1.2:12345
dst→10.0.0.1:80
data→GET /index.html HTTP/1.1
flags→request
HTTP GET /index.html: received by Server
Server generated 200 OK success response
Hop: 4
Client
Router 1
Server
📦Packet
↗ fromserver
↘ torouter1
📄 payloadHTTP 200 OK
🔌 protocolHTTP
🚩 flagsresponse, success
src→10.0.0.1:80
dst→192.168.1.2:12345
data→HTTP/1.1 200 OK
flags→response, success
HTTP 200 OK: server→router1
Router 1 forwarded 200 OK response to Client
Hop: 5
Client
Router 1
Server
📦Packet
↗ fromrouter1
↘ toclient
📄 payloadHTTP 200 OK
🔌 protocolHTTP
🚩 flagsresponse, success
src→10.0.0.1:80
dst→192.168.1.2:12345
data→HTTP/1.1 200 OK
flags→response, success
HTTP 200 OK: router1→client
Client received 200 OK success response
Hop: 6
Client
Router 1
Server
📦Packet
↗ fromrouter1
↘ toclient
📄 payloadHTTP 200 OK
🔌 protocolHTTP
🚩 flagsresponse, success
src→10.0.0.1:80
dst→192.168.1.2:12345
data→HTTP/1.1 200 OK
flags→response, success
HTTP 200 OK: received by Client
Server generated 301 Moved Permanently redirect response
Hop: 7
Client
Router 1
Server
📦Packet
↗ fromserver
↘ torouter1
📄 payloadHTTP 301 Moved Permanently
🔌 protocolHTTP
🚩 flagsresponse, redirect
src→10.0.0.1:80
dst→192.168.1.2:12345
data→HTTP/1.1 301 Moved Permanently
flags→response, redirect
HTTP 301 Moved Permanently: server→router1
Server generated 404 Not Found client error response
Hop: 8
Client
Router 1
Server
📦Packet
↗ fromserver
↘ torouter1
📄 payloadHTTP 404 Not Found
🔌 protocolHTTP
🚩 flagsresponse, client_error
src→10.0.0.1:80
dst→192.168.1.2:12345
data→HTTP/1.1 404 Not Found
flags→response, client_error
HTTP 404 Not Found: server→router1
Server generated 500 Internal Server Error server error response
Hop: 9
Client
Router 1
Server
📦Packet
↗ fromserver
↘ torouter1
📄 payloadHTTP 500 Internal Server Error
🔌 protocolHTTP
🚩 flagsresponse, server_error
src→10.0.0.1:80
dst→192.168.1.2:12345
data→HTTP/1.1 500 Internal Server Error
flags→response, server_error
HTTP 500 Internal Server Error: server→router1
Client received final HTTP status code response
Hop: 10
Client
Router 1
Server
📦Packet
↗ fromrouter1
↘ toclient
📄 payloadHTTP [2xx|3xx|4xx|5xx] Status Code
🔌 protocolHTTP
🚩 flagsresponse
src→10.0.0.1:80
dst→192.168.1.2:12345
data→HTTP/1.1 [status code]
flags→response
HTTP status code response received by Client

Key Takeaways

✓ HTTP status codes categorize server responses into success (2xx), redirection (3xx), client errors (4xx), and server errors (5xx).

This categorization is hard to grasp from code alone but becomes clear when watching the packet flow and server decisions.

✓ The server is the key decision point where the status code category is determined based on request validity and server state.

Seeing the server processing step-by-step reveals how different conditions trigger different status codes.

✓ Network devices like routers simply forward packets without altering HTTP content, ensuring the integrity of status code communication.

Understanding the role of intermediate nodes is easier when visualizing packet forwarding separately from server processing.

Practice

(1/5)
1. In which scenario is WebSocket the most appropriate choice compared to HTTP Long Polling and Server-Sent Events (SSE)?
easy
A. When the application requires full-duplex communication with low latency and frequent bidirectional data exchange
B. When the client only needs to receive unidirectional real-time updates from the server with minimal overhead
C. When the server needs to push occasional updates but the client cannot maintain persistent connections
D. When the client wants to reduce server resource usage by opening a new HTTP request for each update

Solution

  1. Step 1: Analyze communication direction requirements

    WebSocket supports full-duplex communication, allowing simultaneous two-way data flow, unlike SSE and Long Polling which are unidirectional or half-duplex.
  2. Step 2: Consider latency and connection persistence

    WebSocket maintains a persistent connection with low latency, ideal for frequent bidirectional exchanges.
  3. Step 3: Evaluate other options

    When the client only needs to receive unidirectional real-time updates from the server with minimal overhead describes SSE, which is unidirectional from server to client. When the server needs to push occasional updates but the client cannot maintain persistent connections is inaccurate because SSE requires persistent connections. When the client wants to reduce server resource usage by opening a new HTTP request for each update describes naive Long Polling, which is resource-heavy.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Full-duplex + low latency + frequent bidirectional data -> WebSocket
Hint: Full-duplex + frequent bidirectional updates -> WebSocket
Common Mistakes:
  • Confusing SSE as bidirectional
  • Assuming Long Polling is efficient for frequent updates
  • Believing WebSocket is only for server-to-client updates
2. Which of the following best explains why TCP's sliding window flow control alone cannot prevent network congestion?
medium
A. Because sliding window increases window size exponentially regardless of network state
B. Because sliding window only limits sender based on receiver buffer, not network capacity
C. Because sliding window retransmits lost packets too slowly
D. Because sliding window requires explicit congestion notification from routers

Solution

  1. Step 1: Understand sliding window's limitation

    Sliding window controls flow based on receiver's buffer availability, not network congestion.
  2. Step 2: Differentiate from congestion control

    Congestion control algorithms like AIMD adjust sending rate based on network feedback to avoid congestion.
  3. Step 3: Reject exponential increase and retransmission speed options

    Sliding window does not inherently increase window exponentially; retransmission speed is unrelated to flow control.
  4. Step 4: Clarify explicit congestion notification role

    Explicit congestion notification is optional and unrelated to sliding window's basic operation.
  5. Final Answer:

    Option B -> Option B
  6. Quick Check:

    Sliding window limits sender by receiver buffer, not network capacity.
Hint: Flow control = receiver buffer limit; congestion control = network capacity limit.
Common Mistakes:
  • Assuming sliding window adapts to network congestion
  • Confusing flow control with retransmission mechanisms
  • Believing sliding window depends on router signals
3. Why might the TCP three-way handshake introduce latency, and when could this be a disadvantage?
medium
A. Because it requires multiple round-trip times before data transfer, causing delay in time-sensitive applications
B. Because it encrypts all packets during handshake, increasing processing time
C. Because it uses UDP packets which are slower than TCP packets
D. Because it requires the server to send data before the client can send any

Solution

  1. Step 1: Identify handshake latency cause

    The handshake requires at least one full round-trip time (RTT) before data can be sent, introducing delay.
  2. Step 2: Analyze options

    Because it requires multiple round-trip times before data transfer, causing delay in time-sensitive applications correctly states the latency due to multiple RTTs, which can be problematic for real-time or low-latency applications. Because it encrypts all packets during handshake, increasing processing time is incorrect; encryption is separate from handshake. Because it uses UDP packets which are slower than TCP packets is false; handshake uses TCP packets, not UDP. Because it requires the server to send data before the client can send any is incorrect; the client sends data after handshake completes.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Handshake latency = multiple RTTs before data flow.
Hint: Handshake latency = waiting for multiple packet exchanges before data
Common Mistakes:
  • Confusing handshake with encryption overhead
  • Thinking handshake uses UDP packets
  • Believing server sends data first
4. If a domain's authoritative DNS server is down, which of the following best describes how DNS resolution behaves assuming the recursive resolver has a cached entry with a TTL of 300 seconds that expired 10 seconds ago?
hard
A. The recursive resolver will attempt to query the authoritative server despite the expired TTL and return an error if unreachable.
B. The recursive resolver will return the expired cached record to the client to avoid resolution failure.
C. The recursive resolver will immediately return a SERVFAIL error to the client since the authoritative server is unreachable.
D. The recursive resolver will query the root server again to find an alternative authoritative server.

Solution

  1. Step 1: Understand TTL expiration

    Once TTL expires, cached records are considered stale and should not be served without validation.
  2. Step 2: Behavior on authoritative server failure

    The recursive resolver tries to refresh the record by querying the authoritative server.
  3. Step 3: Outcome if authoritative server is down

    If unreachable, the resolver returns an error (e.g., SERVFAIL) to the client.
  4. Step 4: Why other options are incorrect

    The recursive resolver will immediately return a SERVFAIL error to the client since the authoritative server is unreachable ignores retry attempt; The recursive resolver will return the expired cached record to the client to avoid resolution failure violates TTL rules by serving expired data; The recursive resolver will query the root server again to find an alternative authoritative server is incorrect because root servers do not provide alternative authoritative servers.
  5. Final Answer:

    Option A -> Option A
  6. Quick Check:

    Expired TTL triggers retry; failure returns error -> correct
Hint: Expired TTL means resolver must retry; failure leads to error, not stale data.
Common Mistakes:
  • Assuming expired cache is always served
  • Thinking root servers provide alternative authoritative servers
  • Believing resolver returns error immediately without retry
5. Suppose you need to design a protocol for a sensor network where devices send frequent small updates, but network bandwidth is very limited and packet loss is common. Which approach best balances reliability and efficiency?
hard
A. Use UDP with application-layer acknowledgments and selective retransmissions to reduce overhead
B. Use TCP to ensure all packets are received and in order, despite bandwidth overhead
C. Use UDP without any reliability mechanisms to maximize speed and minimize bandwidth
D. Use TCP but disable retransmissions to save bandwidth

Solution

  1. Step 1: Understand constraints

    Limited bandwidth and frequent small updates require minimizing overhead.
  2. Step 2: Analyze TCP suitability

    TCP guarantees reliability but adds overhead and retransmits all lost packets, which may be costly.
  3. Step 3: Analyze UDP with app-layer reliability

    UDP avoids connection overhead; adding selective retransmissions at the application layer balances reliability and efficiency.
  4. Step 4: Evaluate options

    Use UDP with application-layer acknowledgments and selective retransmissions to reduce overhead best fits the scenario. TCP is too heavy for constrained bandwidth. UDP without reliability risks losing important data. TCP cannot disable retransmissions without breaking reliability.
  5. Final Answer:

    Option A -> Option A
  6. Quick Check:

    Custom reliability on UDP can optimize for constrained networks.
Hint: Combine UDP speed with app-layer reliability for constrained, lossy networks.
Common Mistakes:
  • Assuming TCP is always best for reliability regardless of overhead
  • Thinking UDP without reliability is sufficient for sensor data
  • Believing TCP retransmissions can be disabled
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard