Bird
Raised Fist0
Interview Prepcomputer-networkseasyAmazonGoogleMicrosoftFlipkartSwiggyRazorpay

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

Choose your preparation mode3 modes available
🎯
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. When a host wants to send a packet to an IP address on the same subnet but does not have the MAC address cached, what sequence of events occurs in the ARP process?
easy
A. The host broadcasts an ARP request to all devices on the subnet and waits for the target to reply with its MAC address.
B. The host sends a broadcast DHCP request to obtain the MAC address.
C. The host sends a unicast ARP request to the target IP and waits for a unicast ARP reply.
D. The host consults its routing table to find the MAC address.

Solution

  1. Step 1: Understand ARP request nature

    ARP requests are broadcast to all devices on the local subnet because the sender does not know the MAC address of the target.
  2. Step 2: ARP reply is unicast

    The target device responds with a unicast ARP reply containing its MAC address.
  3. Step 3: Why not unicast request?

    Unicast ARP requests cannot be sent without knowing the MAC address, which is the problem ARP solves.
  4. Step 4: DHCP is unrelated

    DHCP is for IP address assignment, not MAC resolution.
  5. Step 5: Routing table does not store MAC addresses

    Routing tables map IP prefixes to next hops, not MAC addresses.
  6. Final Answer:

    Option A -> Option A
  7. Quick Check:

    ARP requests are broadcast; replies are unicast [OK]
Hint: ARP requests are always broadcast on local subnet [OK]
Common Mistakes:
  • Assuming ARP requests are unicast
  • Confusing DHCP with ARP
  • Thinking routing tables store MAC addresses
2. Which of the following statements about DHCP IP address leasing is INCORRECT?
medium
A. Once a lease expires, the IP address is immediately available for reassignment
B. Clients must renew their lease before it expires to keep the same IP address
C. DHCP servers can reclaim IP addresses from clients that do not renew leases
D. Leases help prevent IP address conflicts in the network

Solution

  1. Step 1: Understand lease expiration behavior

    When a lease expires, the IP address is not immediately available; there is usually a grace period before reassignment to avoid conflicts.
  2. Step 2: Analyze other options

    Options B, C, and D are correct statements about DHCP leasing behavior.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Immediate reassignment after expiration is incorrect; DHCP uses timers to prevent conflicts.
Hint: Lease expiration ≠ instant IP reuse; timers prevent conflicts
Common Mistakes:
  • Assuming IPs are instantly reusable after lease expiry
  • Confusing lease renewal with release
  • Believing leases do not prevent conflicts
3. Why is it generally not advisable to set a fixed Retransmission Timeout (RTO) value in TCP instead of using an adaptive algorithm?
medium
A. Because fixed RTO values prevent the sender from using sequence numbers effectively
B. Because fixed RTO values increase the TCP header size, reducing throughput
C. Because fixed RTO values cause the receiver to drop out-of-order packets more frequently
D. Because a fixed RTO cannot adjust to varying network delays, leading to either premature retransmissions or long delays

Solution

  1. Step 1: Understand RTO purpose

    RTO determines when the sender retransmits unacknowledged segments, ideally matching network delay.
  2. Step 2: Analyze fixed vs adaptive RTO

    Fixed RTO cannot adapt to changing RTTs, causing retransmissions either too early (wasting bandwidth) or too late (increasing latency).
  3. Step 3: Evaluate options

    Because fixed RTO values prevent the sender from using sequence numbers effectively is incorrect; sequence number usage is unaffected by RTO. Because fixed RTO values increase the TCP header size, reducing throughput is false; RTO does not affect header size. Because fixed RTO values cause the receiver to drop out-of-order packets more frequently is unrelated to RTO. Because a fixed RTO cannot adjust to varying network delays, leading to either premature retransmissions or long delays correctly identifies the main drawback.
  4. Final Answer:

    Option D -> Option D
  5. Quick Check:

    Adaptive RTO improves efficiency by matching network conditions.
Hint: Adaptive RTO matches RTT; fixed RTO causes inefficiency.
Common Mistakes:
  • Believing fixed RTO affects TCP header size
  • Confusing RTO with receiver packet handling
  • Assuming RTO impacts sequence number usage
4. Which of the following is a common misconception about the resource utilization of Server-Sent Events (SSE) compared to WebSockets?
medium
A. SSE uses fewer server resources than WebSockets because it only supports unidirectional communication
B. SSE cannot be used over HTTPS, limiting its security compared to WebSockets
C. SSE maintains a single persistent HTTP connection, reducing latency compared to HTTP Long Polling
D. SSE requires a new HTTP connection for each event, increasing overhead compared to WebSockets

Solution

  1. Step 1: Understand SSE connection model

    SSE maintains a single persistent HTTP connection over which events are streamed.
  2. Step 2: Analyze resource usage

    Because SSE uses one persistent connection, it avoids the overhead of repeatedly opening new connections.
  3. Step 3: Evaluate options

    SSE requires a new HTTP connection for each event, increasing overhead compared to WebSockets is false; SSE uses a single persistent connection. SSE uses fewer server resources than WebSockets because it only supports unidirectional communication is true. SSE maintains a single persistent HTTP connection, reducing latency compared to HTTP Long Polling is true. SSE cannot be used over HTTPS, limiting its security compared to WebSockets is a common misconception and is false; SSE works over HTTPS.
  4. Final Answer:

    Option B -> Option B
  5. Quick Check:

    SSE works over HTTPS; it is not limited in security compared to WebSockets
Hint: SSE = single persistent connection, supports HTTPS
Common Mistakes:
  • Assuming SSE opens a new HTTP request for every event
  • Believing SSE is bidirectional like WebSocket
  • Thinking SSE cannot be secured with HTTPS
5. If a network protocol stacks the headers of all OSI layers into a single large header before sending data, what is a likely consequence and how should it be addressed?
hard
A. Reduced latency because all headers are processed at once; solution is to increase processing power.
B. Improved security due to all headers being visible; solution is to encrypt the entire header stack.
C. No impact on performance; solution is to accept the design as is.
D. Increased overhead causing reduced throughput; solution is to optimize header sizes and use header compression.

Solution

  1. Step 1: Understand header stacking impact

    Stacking all headers into one large header increases packet overhead, reducing effective throughput.
  2. Step 2: Why other options are incorrect

    Visibility of headers does not inherently improve security; encryption is separate. No impact on performance is false. Reduced latency is unlikely due to larger packet size.
  3. Step 3: How to address the issue

    Optimizing header sizes and applying header compression reduces overhead and improves efficiency.
  4. Final Answer:

    Option D -> Option D
  5. Quick Check:

    Large headers increase overhead and reduce throughput [OK]
Hint: Large headers -> overhead -> optimize or compress headers [OK]
Common Mistakes:
  • Assuming large headers improve security automatically
  • Ignoring performance impact of large headers
  • Believing latency always decreases with header stacking
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