Bird
Raised Fist0
Interview Prepcomputer-networkseasyAmazonGoogleMicrosoftFlipkartSwiggyRazorpayZepto

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

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 GET request

The client constructs an HTTP GET request packet to retrieve data from the server.

💡 This step shows how a simple GET request is formed before sending, establishing the starting point of communication.
Line:request = HTTPRequest(method='GET', url='/resource')
💡 Understanding the initial request setup is crucial to follow the packet flow.
📊
HTTP Methods - GET, POST, PUT, PATCH, DELETE & Idempotency - Watch the Algorithm Execute, Step by Step
Watching each HTTP method's request and response flow helps you understand the fundamental differences and the concept of idempotency in HTTP.
Step 1/20
·Active fillAnswer cell
Client prepares GET request packet.
Hop: 0
Client
Server
src192.168.1.2:12345
dst192.168.1.10:80
dataGET /resource HTTP/1.1
Packet is in transit from client to server.
Hop: 1
Client
Server
📦Packet
fromclient
toserver
📄 payloadGET /resource HTTP/1.1
🔌 protocolHTTP
🚩 flags
src192.168.1.2:12345
dst192.168.1.10:80
dataGET /resource HTTP/1.1
GET: client→server (request)
Server is processing GET request.
Hop: 1
Client
Server
src192.168.1.2:12345
dst192.168.1.10:80
dataGET /resource HTTP/1.1
GET: client→server (request)
Server sends response packet to client.
Hop: 2
Client
Server
📦Packet
fromserver
toclient
📄 payloadHTTP/1.1 200 OK Content: resource data
🔌 protocolHTTP
🚩 flags
src192.168.1.10:80
dst192.168.1.2:12345
dataHTTP/1.1 200 OK Content: resource data
GET: client→server (request)
200 OK: server→client (response)
Client processes response data.
Hop: 2
Client
Server
src192.168.1.10:80
dst192.168.1.2:12345
dataHTTP/1.1 200 OK Content: resource data
GET: client→server (request)
200 OK: server→client (response)
Client prepares POST request packet.
Hop: 0
Client
Server
src192.168.1.2:12345
dst192.168.1.10:80
dataPOST /resource HTTP/1.1 Body: new data
GET: client→server (request)
200 OK: server→client (response)
POST request packet is in transit.
Hop: 1
Client
Server
📦Packet
fromclient
toserver
📄 payloadPOST /resource HTTP/1.1 Body: new data
🔌 protocolHTTP
🚩 flags
src192.168.1.2:12345
dst192.168.1.10:80
dataPOST /resource HTTP/1.1 Body: new data
GET: client→server (request)
200 OK: server→client (response)
POST: client→server (request)
Server processes POST request and updates resource.
Hop: 1
Client
Server
src192.168.1.2:12345
dst192.168.1.10:80
dataPOST /resource HTTP/1.1 Body: new data
GET: client→server (request)
200 OK: server→client (response)
POST: client→server (request)
Server sends POST response to client.
Hop: 2
Client
Server
📦Packet
fromserver
toclient
📄 payloadHTTP/1.1 201 Created
🔌 protocolHTTP
🚩 flags
src192.168.1.10:80
dst192.168.1.2:12345
dataHTTP/1.1 201 Created
200 OK: server→client (response)
POST: client→server (request)
201 Created: server→client (response)
Client processes POST response.
Hop: 2
Client
Server
src192.168.1.10:80
dst192.168.1.2:12345
dataHTTP/1.1 201 Created
200 OK: server→client (response)
POST: client→server (request)
201 Created: server→client (response)
Client prepares PUT request packet.
Hop: 0
Client
Server
src192.168.1.2:12345
dst192.168.1.10:80
dataPUT /resource HTTP/1.1 Body: updated data
200 OK: server→client (response)
POST: client→server (request)
201 Created: server→client (response)
PUT request packet is in transit.
Hop: 1
Client
Server
📦Packet
fromclient
toserver
📄 payloadPUT /resource HTTP/1.1 Body: updated data
🔌 protocolHTTP
🚩 flags
src192.168.1.2:12345
dst192.168.1.10:80
dataPUT /resource HTTP/1.1 Body: updated data
POST: client→server (request)
201 Created: server→client (response)
PUT: client→server (request)
Server processes PUT request and updates resource.
Hop: 1
Client
Server
src192.168.1.2:12345
dst192.168.1.10:80
dataPUT /resource HTTP/1.1 Body: updated data
POST: client→server (request)
201 Created: server→client (response)
PUT: client→server (request)
Server sends PUT response to client.
Hop: 2
Client
Server
📦Packet
fromserver
toclient
📄 payloadHTTP/1.1 200 OK
🔌 protocolHTTP
🚩 flags
src192.168.1.10:80
dst192.168.1.2:12345
dataHTTP/1.1 200 OK
201 Created: server→client (response)
PUT: client→server (request)
200 OK: server→client (response)
Client processes PUT response.
Hop: 2
Client
Server
src192.168.1.10:80
dst192.168.1.2:12345
dataHTTP/1.1 200 OK
201 Created: server→client (response)
PUT: client→server (request)
200 OK: server→client (response)
Client prepares DELETE request packet.
Hop: 0
Client
Server
src192.168.1.2:12345
dst192.168.1.10:80
dataDELETE /resource HTTP/1.1
201 Created: server→client (response)
PUT: client→server (request)
200 OK: server→client (response)
DELETE request packet is in transit.
Hop: 1
Client
Server
📦Packet
fromclient
toserver
📄 payloadDELETE /resource HTTP/1.1
🔌 protocolHTTP
🚩 flags
src192.168.1.2:12345
dst192.168.1.10:80
dataDELETE /resource HTTP/1.1
PUT: client→server (request)
200 OK: server→client (response)
DELETE: client→server (request)
Server processes DELETE request and removes resource.
Hop: 1
Client
Server
src192.168.1.2:12345
dst192.168.1.10:80
dataDELETE /resource HTTP/1.1
PUT: client→server (request)
200 OK: server→client (response)
DELETE: client→server (request)
Server sends DELETE response to client.
Hop: 2
Client
Server
📦Packet
fromserver
toclient
📄 payloadHTTP/1.1 200 OK
🔌 protocolHTTP
🚩 flags
src192.168.1.10:80
dst192.168.1.2:12345
dataHTTP/1.1 200 OK
200 OK: server→client (response)
DELETE: client→server (request)
200 OK: server→client (response)
Client processes DELETE response.
Hop: 2
Client
Server
src192.168.1.10:80
dst192.168.1.2:12345
dataHTTP/1.1 200 OK
200 OK: server→client (response)
DELETE: client→server (request)
200 OK: server→client (response)

Key Takeaways

HTTP methods differ in how they affect server state and idempotency.

Reading code alone doesn't clearly show how repeated requests behave differently; watching packet flows clarifies this.

GET requests retrieve data without side effects, while POST requests submit data and are not idempotent.

Visualizing the request and response packets helps understand why POST can cause multiple changes if repeated.

PUT and DELETE methods are idempotent, meaning repeated identical requests result in the same server state.

Seeing the packet flow and server processing steps highlights the idempotency concept concretely.

Practice

(1/5)
1. In which scenario is the TCP sequence number most critical for ensuring reliable data transfer?
easy
A. When the receiver needs to reorder out-of-sequence packets before delivering data to the application
B. When the sender wants to detect duplicate acknowledgments to trigger fast retransmission
C. When the receiver uses it to calculate the retransmission timeout (RTO)
D. When the sender uses it to encrypt the data payload for security

Solution

  1. Step 1: Understand the role of TCP sequence numbers in packet ordering

    TCP sequence numbers uniquely identify bytes in the data stream, allowing the receiver to reorder packets that arrive out of order.
  2. Step 2: Analyze each option

    When the receiver needs to reorder out-of-sequence packets before delivering data to the application is correct because reordering depends on sequence numbers. When the sender wants to detect duplicate acknowledgments to trigger fast retransmission relates to ACKs, not sequence numbers directly. When the receiver uses it to calculate the retransmission timeout (RTO) is incorrect because RTO calculation uses RTT estimates, not sequence numbers. When the sender uses it to encrypt the data payload for security is unrelated to sequence numbers.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Sequence numbers enable ordering, not encryption or RTO calculation.
Hint: Sequence numbers order bytes; ACKs confirm receipt.
Common Mistakes:
  • Confusing sequence numbers with ACK numbers
  • Thinking sequence numbers affect RTO calculation
  • Assuming sequence numbers relate to encryption
2. Trace the sequence of events when a TCP sender receives three duplicate ACKs for the same sequence number. What happens next?
easy
A. The sender ignores duplicate ACKs and continues sending new data segments
B. The sender waits for the retransmission timeout (RTO) before retransmitting the missing segment
C. The sender immediately retransmits the missing segment without waiting for RTO expiration
D. The sender resets the connection due to suspected network failure

Solution

  1. Step 1: Understand duplicate ACKs in TCP

    Three duplicate ACKs indicate packet loss but that the network is still delivering packets, triggering fast retransmission.
  2. Step 2: Analyze sender's response

    Upon receiving three duplicate ACKs, the sender retransmits the missing segment immediately without waiting for RTO.
  3. Step 3: Evaluate options

    The sender ignores duplicate ACKs and continues sending new data segments is incorrect because the sender does not ignore duplicate ACKs. The sender waits for the retransmission timeout (RTO) before retransmitting the missing segment is incorrect because RTO wait is bypassed. The sender immediately retransmits the missing segment without waiting for RTO expiration correctly describes the fast retransmit behavior. The sender resets the connection due to suspected network failure is an extreme reaction not triggered by duplicate ACKs.
  4. Final Answer:

    Option C -> Option C
  5. Quick Check:

    Fast retransmit improves performance by avoiding RTO delays.
Hint: 3 duplicate ACKs -> fast retransmit, no RTO wait.
Common Mistakes:
  • Confusing fast retransmit with waiting for RTO
  • Ignoring duplicate ACKs as noise
  • Assuming connection reset on packet loss
3. If a load balancer using IP Hash algorithm encounters clients behind a NAT (Network Address Translation) device, what is a potential challenge and how can it be mitigated?
hard
A. Clients behind NAT have different IPs, causing inconsistent routing; mitigation is to disable IP Hash and use Round Robin
B. Multiple clients share the same public IP, causing all their requests to be routed to the same server; mitigation involves using additional session identifiers beyond IP
C. NAT devices block IP Hash algorithms; mitigation is to switch to Least Connections
D. IP Hash cannot detect unhealthy servers behind NAT; mitigation is to increase health check frequency

Solution

  1. Step 1: Understand NAT impact on IP Hash

    NAT causes multiple clients to share a single public IP address.
  2. Step 2: Effect on IP Hash routing

    Since IP Hash uses client IP, all clients behind the same NAT get routed to the same backend server, potentially causing load imbalance.
  3. Step 3: Mitigation strategies

    Using additional session identifiers (cookies, tokens) can differentiate clients beyond IP, improving distribution.
  4. Step 4: Why other options are incorrect

    Clients behind NAT have different IPs, causing inconsistent routing; mitigation is to disable IP Hash and use Round Robin incorrectly states clients behind NAT have different IPs; they share one. NAT devices block IP Hash algorithms; mitigation is to switch to Least Connections falsely claims NAT blocks IP Hash. IP Hash cannot detect unhealthy servers behind NAT; mitigation is to increase health check frequency confuses health checks with NAT issues.
  5. Final Answer:

    Option B -> Option B
  6. Quick Check:

    NAT causes IP Hash collisions; use extra session info to mitigate.
Hint: NAT causes IP Hash collisions; add session IDs
Common Mistakes:
  • Assuming IP Hash works perfectly behind NAT
  • Thinking NAT changes client IPs individually
  • Confusing NAT issues with health check problems
4. 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
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