Skip to content

Try “polymorphism”, “TCP handshake” or “git rebase”.

    Computer Basics / Networking 3: DNS, HTTP and HTTPS

    Proxies, Load Balancers and CDNs

    A proxy is a server that sits between a client and a server and passes traffic along.

    Chapter 12 of 133 min read

    The Plain Picture#

    • A company receptionist who takes all visitors and sends each to the right department — visitors never walk the corridors themselves.

    • A neighbourhood corner shop that keeps popular items from the big warehouse, so you don't travel to the warehouse for milk.

    The Real Names#

    • A proxy is a server that sits between a client and a server and passes traffic along.

      • A forward proxy acts for clients (a company proxy all employees' browsing goes through).

      • A reverse proxy acts for servers: clients talk to it thinking it is the website, and it forwards to the real servers behind it. nginx is the classic example.

    • A load balancer is a reverse proxy that spreads requests across many copies of your app (Load Balancing (coming soon)).

    • A CDN (Content Delivery Network) is a worldwide network of reverse proxies that cache content (Ch 8) close to users. Cloudflare, Akamai, AWS CloudFront.

    Under the Hood#

      Browser ──HTTPS──▶  CDN edge (Chennai)  ──▶  Load balancer  ──HTTP──▶  app server 1
                          cache hit? reply             TLS ends here       ──HTTP──▶  app server 2
                          immediately                  (Ch 11)             ──HTTP──▶  app server 3

    Real evidence — the curl -I https://example.com from Bangalore returned these headers:

    Output
      server: cloudflare
      age: 1068
      cf-cache-status: HIT
      cf-ray: a42098f34f847f43-MAA
    • server: cloudflare — a CDN answered, not example.com's own server.

    • cf-cache-status: HIT — served from the CDN's cache.

    • age: 1068 — this cached copy is 1,068 seconds old.

    • MAA — the airport code for Chennai: the answer came from a nearby CDN edge, not from the other side of the world (remember the latency table in How Computers Work Ch 6).

    The original client IP: behind a proxy, your app sees the proxy's IP as the source. Proxies add X-Forwarded-For: <client IP> (and X-Forwarded-Proto: https) so the app knows who the real client was — only trust these headers when they come from your own proxy, since clients can fake them.

    Check yourself

    3 questions
    1

    Forward proxy vs reverse proxy?

    Show answer

    A forward proxy acts on behalf of clients; a reverse proxy sits in front of servers and acts on their behalf.

    2

    What does a CDN do, and why does it make sites faster?

    Show answer

    Caches content at servers near users, cutting the round-trip distance.

    3

    How does your app learn the real client's IP behind a load balancer?

    Show answer

    From the X-Forwarded-For header added by the proxy (trusted only if your own proxy set it).