LogoMasst Docs

HTTP

Understanding HTTP protocol in system design.

What is HTTP?

HTTP (Hypertext Transfer Protocol) is the foundation of data communication on the web. It's a request-response protocol where clients send requests and servers return responses.


HTTP Request Structure

GET /api/users/123 HTTP/1.1
Host: api.example.com
Authorization: Bearer token123
Content-Type: application/json
Accept: application/json
ComponentDescription
MethodGET, POST, PUT, DELETE, PATCH
PathResource URL
HeadersMetadata (auth, content type)
BodyData payload (POST, PUT, PATCH)

HTTP Methods

MethodPurposeIdempotentSafe
GETRetrieve resourceYesYes
POSTCreate resourceNoNo
PUTReplace resourceYesNo
PATCHPartial updateNoNo
DELETERemove resourceYesNo

HTTP Status Codes

RangeCategoryExamples
2xxSuccess200 OK, 201 Created, 204 No Content
3xxRedirection301 Moved, 304 Not Modified
4xxClient Error400 Bad Request, 401 Unauthorized, 404 Not Found
5xxServer Error500 Internal Error, 502 Bad Gateway, 503 Unavailable

HTTP/1.1 vs HTTP/2 vs HTTP/3

FeatureHTTP/1.1HTTP/2HTTP/3
MultiplexingNoYesYes
Header compressionNoHPACKQPACK
Server pushNoYesYes
TransportTCPTCPQUIC (UDP)
Head-of-line blockingYesPartiallyNo

Connection Management

HTTP/1.1

Connection: keep-alive  # Reuse TCP connection
Connection: close       # Close after response

Connection Pooling

┌─────────┐     ┌─────────────┐     ┌─────────┐
│ Client  │────►│ Conn Pool   │────►│ Server  │
└─────────┘     │ [conn1]     │     └─────────┘
                │ [conn2]     │
                │ [conn3]     │
                └─────────────┘

Interview Tips

  • Know HTTP methods and their semantics
  • Understand status code categories
  • Explain HTTP/2 improvements (multiplexing)
  • Discuss connection management and keep-alive
  • Mention idempotency for retry safety