Bird
Raised Fist0
Interview Prepcomputer-networkseasyAmazonGoogleMicrosoftFlipkartSwiggyRazorpayZepto

HTTP Methods - GET, POST, PUT, PATCH, DELETE & Idempotency

Choose your preparation mode3 modes available
🎯
HTTP Methods - GET, POST, PUT, PATCH, DELETE & Idempotency
easyNETWORKSAmazonGoogleMicrosoft

Imagine ordering food online: you want to check the menu, place an order, update it if needed, or cancel it. Each action corresponds to a different HTTP method with specific rules.

💡 Beginners often confuse HTTP methods as just different ways to send data, missing their semantic differences and the importance of idempotency and safety in APIs.
📋
Interview Question

Explain the HTTP methods GET, POST, PUT, PATCH, DELETE and the concept of idempotency in HTTP. How do these methods differ in usage and behavior?

Purpose and semantics of HTTP methodsIdempotency and safety properties of HTTP methodsHow HTTP methods affect server state and client-server interaction
💡
Scenario & Trace
ScenarioA user browsing an e-commerce site wants to view a product, add it to the cart, update the quantity, and then remove it.
GET request fetches product details without changing server state → POST request adds product to cart creating a new resource → PUT request updates the quantity of the product in the cart replacing the previous value → PATCH request modifies only the quantity field without replacing entire cart item → DELETE request removes the product from the cart.
ScenarioA client sends the same DELETE request twice due to network retry.
First DELETE removes the resource → second DELETE has no effect but returns success because DELETE is idempotent.
  • What happens if a POST request is repeated due to network failure?
  • How does PATCH differ from PUT when updating partial resource data?
  • Is GET always safe and idempotent in practice?
  • What if a DELETE request targets a resource that does not exist?
⚠️
Common Mistakes
Confusing idempotency with safety

Interviewer thinks candidate does not understand that safe methods do not change state, while idempotent methods can change state but in a repeatable way.

✅ Clarify that safe methods (like GET) do not modify server state, whereas idempotent methods (like PUT, DELETE) may modify state but repeated calls have the same effect.

Assuming POST is idempotent

Interviewer doubts candidate's grasp of HTTP semantics and API design principles.

✅ Explain that POST is not idempotent because repeated POSTs can create multiple resources or trigger multiple actions.

Treating PATCH as always idempotent

Interviewer questions candidate's understanding of partial updates and their implications.

✅ Mention that PATCH is generally idempotent if designed properly, but it depends on the implementation and the nature of the partial update.

Believing GET requests can modify server state

Interviewer suspects candidate lacks knowledge of HTTP safety principles.

✅ State that GET should be safe and not change server state; if it does, it's a design flaw.

Not understanding the difference between PUT and PATCH

Interviewer thinks candidate cannot distinguish full replacement from partial update semantics.

✅ Explain PUT replaces the entire resource, while PATCH applies partial modifications.

🧠
Basic Definition - What It Is
💡 This level covers the fundamental purpose of each HTTP method and the basic idea of idempotency and safety.

Intuition

HTTP methods define the action to perform on a resource, with some methods safe (no side effects) and some idempotent (repeatable without additional effect).

Explanation

HTTP methods are standardized verbs used in requests to indicate the desired action on a resource. GET retrieves data without changing server state and is considered safe and idempotent. POST submits data to create a resource and is neither safe nor idempotent. PUT replaces a resource entirely and is idempotent. PATCH partially updates a resource and is usually idempotent but not guaranteed. DELETE removes a resource and is idempotent. Idempotency means that making the same request multiple times results in the same server state as making it once.

Memory Hook

💡 Think of HTTP methods as verbs in a sentence: GET is 'read', POST is 'create', PUT is 'replace', PATCH is 'edit', DELETE is 'remove'. Idempotent methods are like pressing the same button multiple times but only one action happens.

Interview Questions

❓ What is the difference between GET and POST?
  • GET retrieves data without side effects
  • POST submits data to create or process and can change server state
⏱
Depth Level
Interview Time30 seconds
Depthbasic

Covers fundamental definitions and basic properties; sufficient for screening rounds.

Interview Target: Minimum floor - never go below this

Knowing only this will help pass initial screening but not detailed technical interviews.

🧠
Mechanism Depth - How It Works
💡 This level explains the internal semantics, idempotency nuances, and practical implications in API design.

Intuition

Each HTTP method has defined semantics affecting server state and client expectations, with idempotency ensuring safe retries and consistent state.

Explanation

GET requests are safe and idempotent because they only retrieve data without modifying it, allowing caching and safe retries. POST requests create new resources or trigger processing and are neither safe nor idempotent, so repeated POSTs may create duplicates. PUT replaces the entire resource at the target URI and is idempotent because multiple identical PUTs result in the same resource state. PATCH applies partial modifications and is generally idempotent if designed carefully, but this depends on implementation. DELETE removes the resource and is idempotent because deleting an already deleted resource has no further effect. Understanding these properties is crucial for designing robust APIs, handling retries, and ensuring correct client-server interactions.

Memory Hook

💡 Imagine PUT as replacing a file completely, PATCH as editing a paragraph inside the file, POST as adding a new file, GET as reading the file, and DELETE as deleting the file. Idempotency means replacing or deleting the file multiple times leads to the same final state.

Interview Questions

❓ Why is PUT idempotent but POST is not?
  • PUT replaces resource at URI, so repeated PUTs have same effect
  • POST creates new resources or triggers actions, so repeated POSTs can create duplicates
❓ How does PATCH differ from PUT?
  • PATCH applies partial updates, PUT replaces entire resource
  • PATCH may not be idempotent depending on implementation
⏱
Depth Level
Interview Time2-3 minutes
Depthintermediate

Demonstrates understanding of HTTP semantics, idempotency, and practical API design considerations.

Interview Target: Target level for FAANG on-sites

Mastering this level distinguishes you from most candidates and prepares you for system design discussions.

📊
Explanation Depth Levels
💡 Choose your explanation depth based on interview stage and role requirements.
LevelInterview TimeSuitable ForRisk
Basic Definition30sScreening call or initial roundsToo shallow for on-site or system design interviews
Mechanism Depth2-3 minutesOn-site interviews, FAANG, and senior rolesRequires good understanding and ability to explain nuances
💼
Interview Strategy
💡 Use this guide to structure your explanation clearly and confidently before interviews.

How to Present

Start with a concise definition of each HTTP method and their purpose.Give a real-world analogy or example illustrating their use.Explain the concept of idempotency and safety with respect to these methods.Discuss edge cases and implications for retries and API design.

Time Allocation

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

What the Interviewer Tests

Interviewer checks your understanding of HTTP method semantics, idempotency, and ability to apply these concepts in real-world scenarios.

Common Follow-ups

  • What happens if a POST request is retried due to network failure? → It may create duplicate resources unless handled carefully.
  • Can GET requests ever change server state? → Ideally no, but some poorly designed APIs violate this.
💡 These common curveballs test your deeper understanding and practical awareness.
🔍
Pattern Recognition

When to Use

When asked to explain HTTP methods, REST API design, or how client-server communication works in web applications.

Signature Phrases

'Explain HTTP methods and their differences''What is idempotency in HTTP?''Compare PUT vs PATCH'

NOT This Pattern When

Similar Problems

Practice

(1/5)
1. Trace the sequence of steps when an IPv6 packet is sent over an IPv4-only network using tunneling. What happens to the packet headers during this process?
easy
A. The IPv6 packet is converted into an IPv4 packet using NAT64 before transmission
B. The IPv6 header is replaced by an IPv4 header, and the packet is routed as IPv4
C. The IPv6 packet is fragmented into IPv4 packets and reassembled at the destination
D. The IPv6 packet is encapsulated inside an IPv4 header, which is then routed over the IPv4 network

Solution

  1. Step 1: Understand tunneling

    Tunneling encapsulates the entire IPv6 packet inside an IPv4 packet to traverse IPv4 infrastructure.
  2. Step 2: Analyze options

    The IPv6 packet is encapsulated inside an IPv4 header, which is then routed over the IPv4 network correctly describes encapsulation with an IPv4 header. The IPv6 header is replaced by an IPv4 header, and the packet is routed as IPv4 incorrectly states header replacement, which loses IPv6 info. The IPv6 packet is fragmented into IPv4 packets and reassembled at the destination is incorrect; fragmentation does not convert protocols. The IPv6 packet is converted into an IPv4 packet using NAT64 before transmission describes NAT64, a different technique.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Tunneling wraps IPv6 packets inside IPv4 headers for transport.
Hint: Tunneling = IPv6 packet inside IPv4 header [OK]
Common Mistakes:
  • Confusing tunneling with header replacement
  • Mixing up NAT64 with tunneling
  • Assuming fragmentation converts protocols
2. In which scenario is the IP Hash load balancing algorithm most appropriate compared to Round Robin or Least Connections?
easy
A. When you need to ensure session persistence by routing requests from the same client IP to the same server
B. When servers have highly variable processing speeds and you want to balance load evenly
C. When the number of active connections per server is constantly changing and you want to minimize response time
D. When you want to distribute requests strictly in a cyclic order regardless of client identity

Solution

  1. Step 1: Understand IP Hash purpose

    IP Hash uses the client's IP address to consistently route requests to the same backend server, enabling session persistence (sticky sessions).
  2. Step 2: Why not Round Robin or Least Connections?

    Round Robin distributes requests evenly without regard to client identity, so it does not guarantee session persistence. Least Connections balances based on current load but also does not ensure the same client hits the same server.
  3. Step 3: Match scenarios to algorithms

    When you need to ensure session persistence by routing requests from the same client IP to the same server correctly identifies the scenario where IP Hash is preferred: session persistence. Options A and C describe scenarios better suited for Least Connections or Round Robin. When you want to distribute requests strictly in a cyclic order regardless of client identity describes Round Robin behavior.
  4. Final Answer:

    Option A -> Option A
  5. Quick Check:

    IP Hash -> session stickiness; Round Robin -> cyclic distribution; Least Connections -> load-aware balancing.
Hint: IP Hash = sticky sessions by client IP
Common Mistakes:
  • Confusing Least Connections with session persistence
  • Assuming Round Robin can maintain client affinity
  • Believing IP Hash balances load evenly regardless of client IP distribution
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. 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
5. 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
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