Understand the building blocks / CHAPTER 11
Forward and reverse proxies
Understand who a proxy represents and how trust, caching, and routing cross its boundary.
Builds on System design building blocks.
- Distinguish forward proxies from reverse proxies.
- Explain TLS termination and forwarded identity.
- Keep proxy capabilities separate from end-to-end guarantees.
01Who does the intermediary represent?
Jo’s browser requests a supplier’s catalog from the company office. Follow who controls each intermediary:
- The browser sends outbound traffic through a company service. That service applies the company’s destination rules and forwards permitted requests for employees. It acts for the clients, so it is a forward proxy.
- The request reaches the supplier’s public entry service. This service receives requests for the supplier’s private application servers and forwards them inward. It acts for the servers, so it is a reverse proxy.
- The catalog application reads its data and produces the response. Neither proxy needs to own the catalog records.
A proxy is an intermediary that receives and forwards traffic on another participant’s behalf. Its role depends on whom it represents, even though every proxy both receives and sends traffic.
Separate related responsibilities:
- Proxying forwards traffic on another participant’s behalf.
- Load balancing selects which application server receives traffic.
- One reverse proxy can do both jobs. A product’s name alone does not describe its role in this request.
Each added hop can also delay or fail a request. Show where it waits, which information it can inspect, and what information it is allowed to change.
02Trace encryption and identity through the hops
Jo uses HTTPS so the catalog request is encrypted while travelling over a connection. TLS, or Transport Layer Security, provides that connection protection. Locate its endpoints before saying which intermediary can read the content.
- The company forward proxy can set up a tunnel and relay encrypted bytes between Jo and the supplier. In that mode it does not read the HTTP body. To read the body, the company proxy would have to end that encrypted connection under an inspection arrangement the client trusts, then open another connection toward the supplier. That is different from relaying an opaque tunnel.
- The supplier’s reverse proxy may end the TLS connection. This is TLS termination: the proxy can now read HTTP and choose an application destination.
- The proxy opens a separate connection to the application. Decide how that connection is encrypted and how the application verifies the proxy. Protection of the public connection does not automatically protect this new hop.
- The application checks the verified account’s permission for the requested record. Knowing that Jo is signed in does not give Jo permission for another account’s invoice.
A header that claims a caller address or identity is just request text until its source is trusted. For example, a public caller can write a fake X-Forwarded-For header.
To use forwarded information safely:
- Configure the trusted proxy to remove or overwrite untrusted caller-supplied values.
- Configure the application to accept the resulting information only from that trusted proxy path. Prevent a direct-origin route from bypassing the rule.
- Check permission for the particular resource after establishing identity. Forwarding a true account name does not grant access to every record.
The same reasoning applies when proxies forward language, scheme, or host information used to construct a response: say who supplies it and whether the application may trust it.
03Check caching, retries, and streaming
A proxy can change visible behavior even when the application code is correct. Test three common cases.
Private cached responses
- Jo requests
/profileand the application returns Jo’s details. - A shared proxy cache saves the response using only the URL as its key.
- Another user requests the same URL and receives Jo’s saved response without reaching the application.
Prevent shared reuse of that private response, or isolate every permitted copy using verified identity and all other fields that change the result. Follow the HTTP caching rules. An application permission check cannot protect bytes that the proxy serves without contacting it.
A response lost after a purchase
- The application saves a purchase.
- Its connection to the proxy closes before the response arrives.
- The proxy sees a disconnect, but does not know whether the purchase committed.
- A blind repeat can create a second purchase. Follow the service’s retry contract: retain the same supported operation identifier and recover its saved outcome. Bound retries by the remaining time budget.
A delayed progress stream
- The application can produce one event per second while the proxy holds events until a larger chunk accumulates. Check buffering and flushing through the deployed path.
- Idle-timeout settings can close a quiet stream. Protocol upgrades and connection limits must also support the chosen mechanism.
- Replacement closes long-lived connections. Clients need a reconnect and progress-recovery policy.
Give a request a tracing identifier and carry it across proxy and application observations. This connects the same request’s waiting times and failures; the identifier does not grant permission or make repeated writes safe. Finally, test a proxy failure and a gradual rollout. A shared proxy policy mistake can affect every application behind it.
One request crosses two different proxy roles
Follow the numbered arrows
- Jo’s browser → Company forward proxyrequests external catalog
- Company forward proxy → Supplier reverse proxytunnel or configured inspection
- Supplier reverse proxy → Verified caller informationverify and replace caller claims
- Verified caller information → Catalog applicationpass verified account and request
- Supplier reverse proxy → Catalog applicationseparate protected origin hop
Trace the diagram in words
- Jo’s request passes through the company’s client-facing forward proxy.
- The supplier’s reverse proxy receives it for the catalog servers.
- The supplier establishes which forwarded information the application may trust.
- The application checks permission for the requested catalog record.
DRAW. CALCULATE. EXPLAIN.
Audit a private progress API proxy
20 minutes · guided practice
A private job API has four proxy problems:
- It accepts an identity header supplied directly by the caller.
- It shares
/jobs/statusresponses using only the URL. - It repeats every job-creation POST after a disconnect.
- It buffers progress events before forwarding them.
Explain one concrete repair and one useful verification for each.
Compare the worked solution
- Remove caller-supplied identity claims and establish identity through the trusted proxy path. The application accepts claims only from that path and checks the requested job’s owner. Verify that a public caller cannot impersonate another account by adding a header.
- For this private job API, disable shared proxy caching of status responses. Each read reaches the application’s owner check. Request the same URL with two accounts and verify that neither receives the other’s status; a URL-only cache must not bypass that check.
- Follow the job API’s retry contract. Reuse the original supported request identifier and look up its saved creation result after a disconnect. Lose a successful creation response deliberately and verify that recovery returns the same job.
- Configure forwarding so progress events are not held unnecessarily. Align idle timeouts and reconnect behavior with the stream. Observe events through the deployed proxy and replace a proxy instance while the stream is active.
The checkboxes record your own assessment. The worked solution gives you a way to check the reasoning.
RETRIEVE BEFORE YOU REVEAL
Keep the important ideas.
Say the answer aloud, then turn the card over.
CARD 01Whom does a forward proxy represent, and whom does a reverse proxy represent?
- A forward proxy acts for clients making outbound requests.
- A reverse proxy receives inbound requests for servers.
Jo’s company proxy and the supplier’s public proxy can both take part in one catalog request.
CARD 02What changes at TLS termination?
- TLS termination ends one encrypted connection at the proxy.
- Protect and verify the separate connection to the application.
- Remove fake forwarded claims and accept replacements only from the trusted proxy.
- Check the user’s permission for the requested resource.
CARD 03Which proxy behaviors can change privacy, retries or visible updates?
- Prevent a private cached response from reaching another user.
- Recover the original result after a lost write response; do not blindly create it again.
- Check buffering, idle timeouts, and reconnection for event streams.
Test through the real proxy, not only the application port.
CHECK THE REASONING
Can you explain the choice?
Answer every question, then finish for an immediate score and an explanation for each answer. Aim for 80%, then revisit any gaps.
CLOSE THE LOOP
Explain it without the page.
Summarise the mechanism, one trade-off, and one failure mode. Then mark this chapter complete.