Bird
Raised Fist0
Interview Prepcomputer-networkseasyAmazonGoogleMicrosoftFlipkartSwiggyRazorpay

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

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

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 fillAnswer 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
src192.168.1.2:12345
dst10.0.0.1:80
dataGET /index.html HTTP/1.1
flagsrequest
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
src192.168.1.2:12345
dst10.0.0.1:80
dataGET /index.html HTTP/1.1
flagsrequest
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
src192.168.1.2:12345
dst10.0.0.1:80
dataGET /index.html HTTP/1.1
flagsrequest
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
src10.0.0.1:80
dst192.168.1.2:12345
dataHTTP/1.1 200 OK
flagsresponse, 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
src10.0.0.1:80
dst192.168.1.2:12345
dataHTTP/1.1 200 OK
flagsresponse, 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
src10.0.0.1:80
dst192.168.1.2:12345
dataHTTP/1.1 200 OK
flagsresponse, 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
src10.0.0.1:80
dst192.168.1.2:12345
dataHTTP/1.1 301 Moved Permanently
flagsresponse, 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
src10.0.0.1:80
dst192.168.1.2:12345
dataHTTP/1.1 404 Not Found
flagsresponse, 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
src10.0.0.1:80
dst192.168.1.2:12345
dataHTTP/1.1 500 Internal Server Error
flagsresponse, 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
src10.0.0.1:80
dst192.168.1.2:12345
dataHTTP/1.1 [status code]
flagsresponse
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 the DHCP Discover message primarily used during network configuration?
easy
A. When a client wants to renew an existing IP lease
B. When a client releases its IP address back to the server
C. When a DHCP server confirms the IP address assignment
D. When a client initially connects to a network and needs an IP address

Solution

  1. Step 1: Understand the role of DHCP Discover message

    The Discover message is the initial broadcast sent by a client to locate available DHCP servers and request an IP address.
  2. Step 2: Analyze other options

    When a client wants to renew an existing IP lease describes lease renewal, which uses the Request message, not Discover. When a client releases its IP address back to the server refers to releasing an IP, unrelated to Discover. When a DHCP server confirms the IP address assignment is about the server confirming the IP assignment, which is the Acknowledgment message.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Discover is always the first message sent by a client seeking an IP address.
Hint: Discover = first client broadcast to find DHCP servers
Common Mistakes:
  • Confusing Discover with Request or Acknowledgment messages
  • Assuming Discover is used for lease renewal
  • Thinking Discover is sent by the server
2. Trace the sequence of server state changes when a client sends a PATCH request to update a user's email address. Which of the following best describes what happens step-by-step?
easy
A. The server modifies only the specified email field without affecting other user data.
B. The server replaces the entire user resource with the new email data.
C. The server creates a new user resource with the updated email.
D. The server deletes the old email and then inserts the new email as a separate resource.

Solution

  1. Step 1: Understand PATCH semantics

    PATCH is used for partial updates, modifying only specified fields.
  2. Step 2: Differentiate from PUT

    PUT replaces the entire resource, while PATCH updates parts.
  3. Step 3: Analyze options

    The server modifies only the specified email field without affecting other user data correctly states partial modification; others describe full replacement or resource creation/deletion.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    PATCH modifies only the targeted fields without affecting the rest.
Hint: PATCH = partial update, PUT = full replace
Common Mistakes:
  • Confusing PATCH with PUT and thinking it replaces the whole resource
  • Assuming PATCH creates new resources
  • Believing PATCH deletes and reinserts fields
3. Trace the sequence of events when an external client accesses an internal web server via port forwarding configured on a NAT router.
easy
A. The router changes the destination IP and port to the internal server's IP and port, forwards the packet, and rewrites the source IP of the reply back to the router's public IP.
B. The router changes the destination IP and port to the internal server's IP and port, then forwards the packet; the server replies directly to the client.
C. The router only changes the destination IP but leaves the port unchanged; the internal server receives the packet and replies to the router.
D. The router forwards the packet without any translation; the internal server replies directly to the external client.

Solution

  1. Step 1: Understand port forwarding (DNAT)

    Port forwarding rewrites destination IP and port of incoming packets to internal server's IP and port.
  2. Step 2: Trace reply path

    The server replies to the router's internal IP, which rewrites the source IP back to its public IP before sending to the external client.
  3. Step 3: Analyze options

    The router changes the destination IP and port to the internal server's IP and port, forwards the packet, and rewrites the source IP of the reply back to the router's public IP correctly describes both forward and reply translation. The router changes the destination IP and port to the internal server's IP and port, then forwards the packet; the server replies directly to the client is incorrect because the server cannot reply directly to the client without NAT rewriting. The router only changes the destination IP but leaves the port unchanged; the internal server receives the packet and replies to the router misses port translation. The router forwards the packet without any translation; the internal server replies directly to the external client ignores NAT translation entirely.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Port forwarding requires bidirectional NAT translation [OK]
Hint: Port forwarding rewrites destination IP/port inbound and source IP outbound
Common Mistakes:
  • Assuming server replies directly to external client
  • Forgetting port translation in forwarding
  • Ignoring reply path NAT rewriting
4. Which of the following statements about DNS caching is INCORRECT?
medium
A. DNS caching at the recursive resolver reduces the number of queries sent to authoritative servers.
B. Local DNS resolvers cache negative responses (e.g., non-existent domains) to improve efficiency.
C. Caching at the browser level can completely eliminate the need for DNS queries for repeated domain lookups.
D. DNS cache entries respect TTL values, after which cached data must be refreshed.

Solution

  1. Step 1: Understand caching layers

    DNS caching occurs at multiple levels: browser, OS resolver, recursive resolver.
  2. Step 2: Browser caching limitations

    Browser caches DNS results temporarily but cannot completely eliminate DNS queries because OS or network conditions may require fresh lookups.
  3. Step 3: Why other options are correct

    Recursive resolvers cache to reduce authoritative queries; negative caching is standard; TTL governs cache expiry.
  4. Final Answer:

    Option C -> Option C
  5. Quick Check:

    Browser caching helps but does not fully eliminate DNS queries -> incorrect statement
Hint: Browser DNS cache helps but does not fully replace DNS queries.
Common Mistakes:
  • Assuming browser cache is authoritative and permanent
  • Ignoring negative caching
  • Forgetting TTL governs cache validity
5. If a client crashes immediately after sending the final ACK in the TCP three-way handshake, what is the likely impact on the server's connection state?
hard
A. The server resets the connection upon detecting no ACK from the client
B. The server immediately closes the connection due to missing data
C. The server retransmits SYN-ACK packets until timeout, then closes the connection
D. The server considers the connection established and waits indefinitely for data

Solution

  1. Step 1: Understand handshake completion

    After the client sends the final ACK, the server marks the connection as established.
  2. Step 2: Consider client crash impact

    If the client crashes immediately after ACK, the server has no immediate way to detect this and will wait for data or timeout based on application-level timeouts.
  3. Step 3: Analyze options

    The server considers the connection established and waits indefinitely for data correctly states the server waits indefinitely (or until timeout). The server immediately closes the connection due to missing data is incorrect; server does not close immediately. The server retransmits SYN-ACK packets until timeout, then closes the connection is wrong; retransmission of SYN-ACK happens before handshake completes, not after. The server resets the connection upon detecting no ACK from the client is incorrect; server does not reset connection without explicit reset packet.
  4. Final Answer:

    Option D -> Option D
  5. Quick Check:

    Server trusts handshake completion after final ACK, unaware of client crash.
Hint: Server trusts final ACK; client crash after means server waits for data
Common Mistakes:
  • Assuming server detects client crash immediately
  • Confusing retransmission behavior post-handshake
  • Thinking server resets connection without RST packet