FOUNDATIONS / SYSTEM CONCEPT BRIEF

HTTP / HTTPS

HTTP (Hypertext Transfer Protocol) is the request-response protocol of the web.

BeginnerPhase 01 / Topic 4 of 17RequirementsTrade-offsFailure modes
01

Overview

HTTP (Hypertext Transfer Protocol) is the request-response protocol of the web. A client sends a method (GET, POST, PUT, DELETE), a path, headers, and an optional body; the server replies with a status code, headers, and a body. HTTP is stateless: each request carries everything the server needs, which is why cookies and tokens exist.

HTTPS is HTTP over TLS. TLS encrypts the traffic, proves the server's identity with a certificate signed by a trusted authority, and detects tampering. Today HTTPS is mandatory for any production system: browsers flag HTTP as insecure, and features like HTTP/2, service workers, and geolocation require it.

A form at a government office, in a sealed envelope

HTTP is filling out a standard form: what you want (method and path), extra details (headers), and attachments (body). The clerk returns a stamped result code. HTTPS puts that form in a tamper-proof envelope that only the verified office can open.

02

When to use it

  • Any web or API communication between clients and servers.
  • Designing REST APIs: choosing methods, status codes, and headers.
  • Caching decisions with Cache-Control, ETag, and Last-Modified.
  • Security: protecting credentials and data in transit.
03

Where it shows up in interviews

API contract design

Recognize it when: choose methods, status codes, idempotency, and caching headers.

  • Design a REST API for an e-commerce cart
  • Design a public API
HTTP caching

Recognize it when: reduce load and latency for read-heavy content.

  • Design a news site
  • Design a CDN-backed image service
TLS termination

Recognize it when: where to decrypt traffic in your architecture.

  • Design the edge of a web platform
  • Design a secure internal service mesh
04

Where it is used in real software

Let's Encrypt

A free certificate authority that issues automated 90-day certificates; it moved the web from under 50% HTTPS to over 90%.

TLS termination at load balancers

AWS ALB, Nginx, and Cloudflare decrypt traffic at the edge and forward it to backends, often re-encrypted.

HSTS preload

Sites like Google and banks are hardcoded in browsers to always use HTTPS, preventing downgrade attacks.

05

Key terms

Method
GET (read), POST (create / action), PUT (replace), PATCH (partial update), DELETE (remove).
Status code
2xx success, 3xx redirect, 4xx client error, 5xx server error.
Idempotent
Repeating the request has the same effect as doing it once (GET, PUT, DELETE).
Cache-Control
Header that tells browsers and CDNs whether and how long to cache.
TLS certificate
Proves a server owns a domain; signed by a certificate authority.
06

TLS 1.3 handshake

  1. 1
    ClientHello

    The client sends supported cipher suites and a key share (its half of a Diffie-Hellman exchange).

  2. 2
    ServerHello and certificate

    The server picks a cipher, sends its key share, its certificate chain, and a signature proving it holds the private key.

  3. 3
    Client verifies

    The client checks the certificate chain up to a trusted root, the domain name, and the expiry date.

  4. 4
    Both derive session keys

    From the key shares, both sides compute the same symmetric keys without sending them.

  5. 5
    Encrypted HTTP

    All HTTP traffic is now encrypted with fast symmetric crypto (AES-GCM or ChaCha20). One round trip total.

HTTPS request with TLS 1.3
Step 1 / 4
Client
TCP handshake
ClientHello
ServerHello + cert
Verify cert
Encrypted GET
200 OK

STEP 1A TCP connection is established first (1 RTT).

07

Status codes you must know

Pick the most specific correct code; clients and monitoring depend on it

Step 1 / 5
CodeMeaningTypical use
200 / 201 / 204OK / Created / No ContentSuccessful read, create, or delete
301 / 302 / 304Moved / Found / Not ModifiedPermanent redirect, temporary redirect, cache revalidation
400 / 401 / 403Bad Request / Unauthorized / ForbiddenInvalid input, missing auth, not allowed
404 / 409 / 429Not Found / Conflict / Too Many RequestsMissing resource, version conflict, rate limited
500 / 502 / 503 / 504Server error / Bad Gateway / Unavailable / Gateway TimeoutBug, upstream failure, overload, upstream too slow

NOWCode: 200 / 201 / 204 | Meaning: OK / Created / No Content | Typical use: Successful read, create, or delete

401 means 'who are you?' (not authenticated); 403 means 'I know who you are, but no' (not authorized). 502 and 504 usually come from a proxy describing a problem with the server behind it.

08

Implementation

GET /api/products/42 HTTP/1.1Host: shop.example.comAccept: application/jsonAuthorization: Bearer eyJhbGciOi...If-None-Match: "v7" HTTP/1.1 304 Not ModifiedETag: "v7"Cache-Control: private, max-age=60 POST /api/orders HTTP/1.1Host: shop.example.comContent-Type: application/jsonIdempotency-Key: 8f14e45f-ea3c-4c8b {"productId": 42, "quantity": 2} HTTP/1.1 201 CreatedLocation: /api/orders/9001
09

Complexity and performance

TLS 1.3 handshake1 RTT

TLS 1.2 needed 2 RTT.

Resumed session0-1 RTT

Session tickets / 0-RTT data.

Encryption overheadnegligible

AES-GCM is hardware accelerated on modern CPUs.

10

Trade-offs

Terminate TLS at the edge vs end-to-end

Terminating at the load balancer simplifies certificates and lets it inspect traffic; re-encrypting to backends (or mTLS) is needed for zero-trust and compliance.

PUT vs PATCH

PUT replaces the whole resource and is idempotent; PATCH sends only changes, saving bandwidth but requiring careful semantics.

11

Variants and related techniques

mTLS

Both client and server present certificates; common for service-to-service authentication.

HTTP/2 and HTTP/3

Multiplexing and faster handshakes; see HTTP/1.1 to HTTP/3.

Conditional requests

ETag and If-None-Match let clients revalidate cached data and receive 304 without a body.

12

Common mistakes

  • Using GET for actions that change data.

    Fix: GET must be safe; crawlers and prefetchers will call it. Use POST, PUT, PATCH, or DELETE.

  • Returning 200 with an error message in the body.

    Fix: Use proper 4xx/5xx codes so clients, retries, and monitoring behave correctly.

  • Letting certificates expire.

    Fix: Automate renewal (ACME / cert-manager) and alert well before expiry.

13

Interview questions

What does HTTPS protect against, and what does it not?

It protects confidentiality, integrity, and server identity against network attackers. It does not protect against a compromised server, malicious clients, or application bugs like SQL injection.

Which HTTP methods are idempotent and why does it matter?

GET, HEAD, PUT, DELETE, and OPTIONS are idempotent. Clients, proxies, and load balancers can safely retry them after a timeout; POST retries need an idempotency key to avoid duplicates.

14

Practice problems

ProblemDifficultyWhat it trains
Inspect headers of a real site with curl -IEasyCaching and security headers.
Design status codes and headers for an orders APIMediumSemantics and idempotency.
Design TLS termination for a multi-tenant SaaSHardCertificates at scale.