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
🎯
HTTP Status Codes - 2xx, 3xx, 4xx, 5xx - When Each Fires
easyNETWORKSAmazonGoogleMicrosoft

Imagine you order a product online and the website tells you instantly if your order was successful, if you need to log in again, or if the product is out of stock. HTTP status codes are the language behind these messages.

💡 Beginners often confuse status codes as just numbers without understanding their categories or when each type is used, leading to vague or incorrect explanations. Think of status codes as grouped signals that tell you if your request was successful, needs redirection, or failed due to client or server issues.
📋
Interview Question

Explain the different categories of HTTP status codes (2xx, 3xx, 4xx, 5xx) and describe when each category is used in web communication.

Meaning and purpose of HTTP status code classesTypical scenarios triggering each status code categoryDifference between client-side and server-side errors
💡
Scenario & Trace
ScenarioA user submits a form to create a new account on a website.
Client sends POST request → Server processes and creates account → Server responds with 201 Created indicating success and resource creation.
ScenarioA user tries to access a webpage that has moved permanently.
Client sends GET request → Server responds with 301 Moved Permanently → Client updates URL and requests new location.
ScenarioA user requests a page that does not exist on the server.
Client sends GET request → Server cannot find resource → Server responds with 404 Not Found.
ScenarioServer encounters an unexpected error while processing a request.
Client sends request → Server fails internally → Server responds with 500 Internal Server Error.
  • What if a resource is temporarily moved? (Use 302 Found or 307 Temporary Redirect)
  • What if the client sends too many requests in a short time? (Use 429 Too Many Requests)
  • What if authentication is required but missing or invalid? (Use 401 Unauthorized or 403 Forbidden)
⚠️
Common Mistakes
Confusing 401 Unauthorized with 403 Forbidden

Interviewer thinks candidate lacks understanding of authentication vs authorization.

401 means user is not authenticated; 403 means authenticated but not allowed to access resource.

Treating all 4xx errors as the same client fault

Interviewer doubts candidate's grasp of specific client error meanings.

Explain specific codes like 400 Bad Request (syntax error), 404 Not Found (missing resource), 429 Too Many Requests (rate limiting).

Assuming 3xx redirects always mean permanent moves

Interviewer suspects candidate doesn't know redirect nuances.

Clarify difference between 301 (permanent) and 302/307 (temporary) redirects.

Using 500 Internal Server Error for all server problems

Interviewer thinks candidate lacks knowledge of specific server error codes.

Mention other 5xx codes like 503 Service Unavailable for overload or maintenance.

🧠
Basic Definition - What It Is
💡 This level covers the fundamental understanding of HTTP status codes and their broad categories, helping you quickly identify the general meaning behind a response code.

Intuition

HTTP status codes are standardized numbers that tell the client what happened with their request.

Explanation

HTTP status codes are three-digit numbers sent by the server in response to a client's request. They are grouped into five categories: 1xx (informational), 2xx (success), 3xx (redirection), 4xx (client errors), and 5xx (server errors). The most commonly discussed are 2xx, 3xx, 4xx, and 5xx. Each category indicates a general class of response - for example, 2xx means the request was successfully processed, while 4xx means there was an error caused by the client.

Memory Hook

💡 Think of HTTP status codes as traffic lights: green (2xx) means go/success, yellow (3xx) means caution/redirect, red (4xx and 5xx) means stop/error.

Illustrative Code

# No code needed for basic definition approach
pass

Interview Questions

What does a 200 status code mean?
  • Request succeeded
  • Response contains requested data
When would a 404 status code be returned?
  • Requested resource not found
  • Client error category
Depth Level
Interview Time30 seconds
Depthbasic

Covers the broad categories and their general meanings; sufficient for quick screening questions.

Interview Target: Minimum floor - never go below this

Knowing only this will help you pass initial screening but won't impress in detailed discussions.

🧠
Mechanism Depth - How It Works
💡 This level explains the specific use cases and nuances of each status code category expected in product company interviews, helping you answer detailed questions confidently.

Intuition

Each HTTP status code category corresponds to a specific type of server response reflecting the request's outcome and next steps.

Explanation

The 2xx codes indicate successful handling of the request, with 200 OK meaning the request succeeded and the server returned the requested data, and 201 Created indicating a new resource was created. The 3xx codes handle redirection, telling the client to make a new request to a different URI; for example, 301 Moved Permanently signals a permanent redirect, while 302 Found is temporary. The 4xx codes represent client errors, such as 400 Bad Request for malformed syntax, 401 Unauthorized when authentication is required, 403 Forbidden when access is denied, and 404 Not Found when the resource doesn't exist. The 5xx codes indicate server errors, like 500 Internal Server Error for unexpected failures or 503 Service Unavailable when the server is overloaded or down for maintenance. Understanding these helps in debugging and designing robust web applications.

Memory Hook

💡 Imagine a conversation: 2xx means 'I got it and did it', 3xx means 'Go ask somewhere else', 4xx means 'You messed up', and 5xx means 'I messed up'.

Illustrative Code

# No code needed for mechanism depth approach
pass

Interview Questions

Explain the difference between 301 and 302 status codes.
  • 301 is permanent redirect; client should update bookmarks
  • 302 is temporary redirect; client should continue using original URL
What status code would you use if a user tries to access a resource without proper authentication?
  • 401 Unauthorized if authentication is missing or invalid
  • 403 Forbidden if authentication is valid but access is denied
When does a 429 status code occur?
  • Client sent too many requests in a given time frame
  • Used for rate limiting to protect server resources
Depth Level
Interview Time2-3 minutes
Depthintermediate

Demonstrates detailed understanding of when and why each status code is used, expected in FAANG-level interviews.

Interview Target: Target level for FAANG on-sites

Mastering this level distinguishes you from most candidates and shows practical knowledge.

📊
Explanation Depth Levels
💡 Choose your explanation depth based on interview stage and company expectations.
LevelInterview TimeSuitable ForRisk
Basic Definition30sScreening call or quick conceptual questionsToo shallow for detailed technical interviews
Mechanism Depth2-3 minutesOn-site interviews at product companies like FAANGRequires good understanding and ability to explain nuances
💼
Interview Strategy
💡 Use this guide to structure your explanation clearly and confidently before every mock or real interview. It helps you cover all important points systematically.

How to Present

Start with a brief definition of HTTP status codes and their purpose.Give a simple analogy or example to make the concept relatable.Explain the main categories (2xx, 3xx, 4xx, 5xx) and typical scenarios for each.Mention important edge cases and subtle differences between similar codes.

Time Allocation

Definition: 30s → Example: 1min → Mechanism: 2min → Edge cases: 30s. Total ~4min

What the Interviewer Tests

Interviewer checks if you understand the meaning behind each category, can differentiate client vs server errors, and know common codes and their use cases.

Common Follow-ups

  • What is the difference between 401 and 403 status codes? → 401 means authentication required; 403 means authenticated but forbidden.
  • How do status codes affect REST API design? → They communicate request outcomes clearly and guide client behavior.
💡 These follow-ups test your deeper understanding and ability to apply knowledge practically.
🔍
Pattern Recognition

When to Use

When asked to explain HTTP communication, REST API responses, or debugging web client-server interactions.

Signature Phrases

'Explain HTTP status codes''Compare 4xx vs 5xx errors''What happens when a resource is moved?'

NOT This Pattern When

Similar Problems

Practice

(1/5)
1. Trace the sequence of events when a client sends a request to a web server protected by a reverse proxy. Which step happens immediately after the reverse proxy receives the client request?
easy
A. The reverse proxy forwards the request to the backend server
B. The firewall inspects and blocks the request if malicious
C. The proxy server caches the response for future requests
D. The client directly connects to the backend server

Solution

  1. Step 1: Understand reverse proxy role

    Reverse proxy acts as an intermediary on the server side, receiving client requests first.
  2. Step 2: After receiving the request

    The reverse proxy forwards the request to the backend server for processing.
  3. Step 3: Other options

    Firewall inspection happens before the reverse proxy in the network path; proxy caching is client-side; client does not connect directly to backend when reverse proxy is used.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    Reverse proxy forwards request to backend server immediately after receiving it [OK]
Hint: Reverse proxy forwards requests to backend servers.
Common Mistakes:
  • Assuming firewall acts after reverse proxy
  • Confusing proxy caching with reverse proxy behavior
2. In which scenario is Source NAT (SNAT) most appropriately used within a private IPv4 network?
easy
A. When internal hosts initiate outbound connections to the internet, hiding their private IPs behind a public IP
B. When external users need to access a specific internal server via a public IP and port
C. When translating destination IP addresses for incoming packets to reach internal hosts
D. When mapping multiple public IPs to a single internal IP without port translation

Solution

  1. Step 1: Identify SNAT purpose

    SNAT modifies the source IP of outgoing packets, typically to allow multiple internal hosts to share a public IP for internet access.
  2. Step 2: Analyze options

    When internal hosts initiate outbound connections to the internet, hiding their private IPs behind a public IP correctly describes SNAT's role in outbound connections. When external users need to access a specific internal server via a public IP and port describes DNAT or port forwarding. When translating destination IP addresses for incoming packets to reach internal hosts is DNAT's function. When mapping multiple public IPs to a single internal IP without port translation is not typical SNAT behavior.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    SNAT = source IP translation for outbound traffic [OK]
Hint: SNAT changes source IP for outbound traffic
Common Mistakes:
  • Confusing SNAT with DNAT
  • Assuming SNAT handles inbound connections
  • Believing SNAT can map multiple public IPs to one internal IP without ports
3. Which of the following statements about reverse proxies is INCORRECT?
medium
A. Reverse proxies always cache all content to reduce backend load
B. Reverse proxies can improve security by hiding backend server details
C. Reverse proxies can perform SSL termination to offload encryption work
D. Reverse proxies distribute incoming requests among multiple backend servers

Solution

  1. Step 1: Understand reverse proxy caching

    Reverse proxies may cache some content but do not always cache all content; caching is selective based on configuration.
  2. Step 2: Other statements

    Reverse proxies hide backend details (A), perform SSL termination (C), and load balance requests (D) -- all correct.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Reverse proxies do not always cache all content [OK]
Hint: Reverse proxies cache selectively, not always.
Common Mistakes:
  • Assuming reverse proxies cache everything
  • Confusing reverse proxy with CDN caching behavior
4. Which of the following statements about the scalability and overhead trade-offs between Distance Vector and Link State routing is TRUE?
medium
A. Distance Vector routing scales better in large networks because it floods link state advertisements less frequently
B. Distance Vector routing has lower convergence time but higher memory usage compared to Link State
C. Link State routing requires more memory and CPU but scales better due to faster convergence and less routing loops
D. Link State routing uses less bandwidth overall because it only sends updates when topology changes

Solution

  1. Step 1: Understand resource usage

    Link State routing stores the entire network topology, requiring more memory and CPU for Dijkstra's algorithm.
  2. Step 2: Analyze scalability and convergence

    Link State converges faster and avoids routing loops better, making it more scalable despite higher resource use.
  3. Step 3: Evaluate options

    Distance Vector routing scales better in large networks because it floods link state advertisements less frequently is false because Distance Vector does not flood link state advertisements at all. Distance Vector routing has lower convergence time but higher memory usage compared to Link State is false because Distance Vector generally has slower convergence and lower memory usage. Link State routing uses less bandwidth overall because it only sends updates when topology changes is misleading; Link State floods updates on topology changes, which can be bandwidth intensive.
  4. Final Answer:

    Option C -> Option C
  5. Quick Check:

    Link State trades higher resource use for better scalability and convergence.
Hint: More CPU/memory but faster convergence -> Link State scales better
Common Mistakes:
  • Assuming Distance Vector floods updates like Link State
  • Confusing convergence time and memory usage
  • Believing Link State sends fewer updates overall
5. Which of the following statements about the TCP connection termination process is INCORRECT?
medium
A. The connection closes immediately after the first FIN packet is sent
B. Either side can initiate termination by sending a FIN packet
C. Connection termination requires four steps involving FIN and ACK packets from both sides
D. After termination, both sides enter a TIME_WAIT state to ensure all packets are received

Solution

  1. Step 1: Review TCP termination steps

    Termination involves a four-step exchange: FIN from initiator, ACK from receiver, FIN from receiver, ACK from initiator.
  2. Step 2: Analyze each statement

    Connection termination requires four steps involving FIN and ACK packets from both sides is correct describing the four-step process. Either side can initiate termination by sending a FIN packet is correct; either side can initiate. After termination, both sides enter a TIME_WAIT state to ensure all packets are received is correct; TIME_WAIT ensures delayed packets are handled. The connection closes immediately after the first FIN packet is sent is incorrect because connection does not close immediately after first FIN; it requires the full handshake.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Termination is a multi-step process, not instantaneous.
Hint: Termination = 4 steps, not immediate close after FIN
Common Mistakes:
  • Assuming connection closes right after first FIN
  • Thinking only server can initiate termination
  • Ignoring TIME_WAIT state