System designby Learnastra

Concept lesson · Foundations

Proxies: forward proxy, reverse proxy and API gateway

By Anup Rai

Start here

Definition

A proxy is an intermediary that forwards communication on behalf of another party. A forward proxy serves clients reaching destinations; a reverse proxy fronts servers receiving requests, and an API gateway commonly adds API-specific policy to that server-facing role.

Why it matters: An intermediary can provide a controlled place for routing, connection handling and permitted caching. Its role determines whose traffic it accepts and what it may trust.

The visual modelForward proxy, reverse proxy, and TLS trust boundaries

A forward proxy acts for a client; a reverse proxy fronts a service. TLS termination and forwarded identity create explicit trust boundaries.

Forward proxy, reverse proxy, and TLS trust boundariesA forward proxy acts for a client; a reverse proxy fronts a service. TLS termination and forwarded identity create explicit trust boundaries. A client uses a forward proxy to reach an origin; the proxy represents the client side. Public clients reach a reverse proxy which selects a protected origin; the proxy represents the service side. GET /orders/17 terminates TLS at the reverse proxy; the origin hop has its own encryption and authentication decision. Only trusted proxies may supply effective forwarded identity headers. The order service still checks whether the caller may read order 17.Whose side does the intermediary represent?FORWARD PROXY: chosen by the client sideClientForward proxyInternet originREVERSE PROXY: fronts the service sideClient browserReverse proxyOrder 17 serviceTLS connection 1TLS connection 2termination boundaryTrust headers only from your proxy. The origin still authorizes access to order 17.
Read the diagram step by step
  1. A client uses a forward proxy to reach an origin; the proxy represents the client side.
  2. Public clients reach a reverse proxy which selects a protected origin; the proxy represents the service side.
  3. GET /orders/17 terminates TLS at the reverse proxy; the origin hop has its own encryption and authentication decision.
  4. Only trusted proxies may supply effective forwarded identity headers. The order service still checks whether the caller may read order 17.

Worked example

A request to https://shop.example/orders/17 reaches the reverse proxy. The reverse proxy receives that public request, routes it to the order application, and relays the response; the application still checks that order 17 belongs to the authenticated caller.

Key takeaways

You will learn to

  • Identify which party a proxy represents.
  • Trace the request and trust boundary through TLS termination.
  • Explain open, anonymous, and transparent proxy properties without confusing them.

Practice in this chapter

8 interview questions with model answers and follow-ups.

Go to interview practice

Useful foundations: HTTP APIs and request lifecycle · Caching: cache hits, misses, write policies and invalidation

Workload and timing examples are interview assumptions.

01Proxy definition: forward versus reverse

A proxy is an intermediary that receives communication and forwards it on behalf of another party. A hop is one connection segment along that path. The same request can travel client → proxy → application, with a separate response returning through those components. The proxy can apply access or routing rules, cache a permitted response, or change how the next connection is made. A proxy adds a hop; it does not erase the need to understand the caller and the destination.

A forward proxy represents clients accessing remote services; an organizational gateway may filter destinations and record permitted outbound traffic. A reverse proxy fronts origin servers and routes incoming traffic to them. For example, shop.example can accept a public /orders/17 request and forward it to an internal order API.

The origin is the service responsible for producing the resource. A proxy may return a cached origin response when the policy allows. “Forward” and “reverse” describe whose side the intermediary serves, not whether packets travel only in one direction.

Role Whose side it serves Concrete example Limit
Forward proxy Clients choosing external destinations An employee browser reaches permitted websites through the company proxy It needs a destination and client-use policy
Reverse proxy Servers behind a public service name shop.example routes /orders/17 to an internal application It does not automatically establish order ownership
API gateway Commonly the reverse-proxy/API entry role Validate credentials, request size and API quotas The service that reads or changes business data must still enforce its correctness and access rules
Load balancer Selects among eligible destinations Choose order server A or B Selection alone does not add caching or API policy

One deployed component can perform several of these jobs. Explain the responsibilities separately so a product name does not hide an authorization or failure assumption.

02Worked example: an HTTPS request through a reverse proxy

For an HTTPS request to https://shop.example/orders/17, several protocols have separate responsibilities. DNS maps a service name to a network address. HTTP carries the request and response. TLS encrypts a connection and authenticates its endpoint using certificates; HTTPS is HTTP over a protected connection. TLS termination is where that protected connection ends and the receiver can inspect its HTTP content. The following steps use those terms; protocol details are in the request-lifecycle chapter.

  1. DNS resolves the public shop name to a reachable edge address.
  2. The browser establishes an encrypted connection to the shop's reverse proxy and verifies its certificate for that name.
  3. The proxy receives GET /orders/17, plus the session credential. That credential is evidence used to authenticate the signed-in account; the URL itself proves no identity. The proxy routes the request to the order service.
  4. It opens or reuses a backend connection. If this crosses an untrusted network segment, encrypt and authenticate that hop too.
  5. The order service derives the caller’s identity from a validated credential and checks permission to read order 17.
  6. The response travels back through the proxy to the browser. Private order data is not placed in a broadly shared cache.

An API gateway is often a reverse proxy with additional API policy: authentication checks, quotas, routing, or request validation. A load balancer chooses among eligible backends. One product can perform both roles, but the responsibilities remain separate.

Worked example diagramOne request path shows a forward proxy serving an employee client; the other shows a reverse proxy serving the shop. Both relay replies back. The order service still decides whether the caller may read order 17.
Proxies: forward proxy, reverse proxy and API gateway: architecture diagram1. Employee browser to 2. Forward proxy: company policy: 1. Client sends permitted web request; 2. Forward proxy: company policy to 3. External website: 2. Forward proxy represents client; 4. Client: HTTPS /orders/17 to 5. Reverse proxy: shop.example: 3. Request public shop service; 5. Reverse proxy: shop.example to 6. Order service: authorize order 17: 4. Reverse proxy fronts order service; 6. Order service: authorize order 17 to 5. Reverse proxy: shop.example: 5. Return authorized order response1 → 2: 1. Client sends permitted web request2 → 3: 2. Forward proxy represents client4 → 5: 3. Request public shop service5 → 6: 4. Reverse proxy fronts order service6 → 5: 5. Return authorized order response01Employee browser02Forward proxy:company policy03External website04Client: HTTPS/orders/1705Reverse proxy:shop.example06Order service:authorize order 17
  1. 1 → 21. Client sends permitted web requestEmployee browser → Forward proxy: company policy
  2. 2 → 32. Forward proxy represents clientForward proxy: company policy → External website
  3. 4 → 53. Request public shop serviceClient: HTTPS /orders/17 → Reverse proxy: shop.example
  4. 5 → 64. Reverse proxy fronts order serviceReverse proxy: shop.example → Order service: authorize order 17
  5. 6 → 55. Return authorized order responseOrder service: authorize order 17 → Reverse proxy: shop.example

03Forwarding headers and trusted client identity

The backend connection originates at the proxy, so the backend's immediate peer address may be the proxy's address. Forwarding headers can carry earlier connection information. They must be trusted only from known proxy hops, because a public caller can forge ordinary request headers.

Field or connection fact At the public edge Safe backend interpretation
Host / authority shop.example Route only allowed hostnames
Client network address Seen by the trusted edge Use trusted forwarding metadata, not arbitrary caller claims
User identity Caller credential Validate credential and resource permission
Request ID Accept or issue under a policy Correlate logs without treating it as authentication

Suppose an attacker sends X-Forwarded-For: 127.0.0.1. A backend that treats that value as proof of an internal caller may grant unintended access. The edge should normalize forwarding metadata, and the backend should know which upstreams are authorized to supply it. Rewriting a header is a security-sensitive operation when policy depends on that field.

04Open, anonymous and transparent proxies

Forward and reverse describe whom a proxy represents. Open, anonymous and transparent describe other properties: who may use it, what identity information it reveals, or how traffic reaches it. These labels can overlap; choosing one does not answer the questions covered by the others.

An open proxy accepts use from a broad or unrestricted set of clients. A closed organizational proxy limits who may use it. Openness is an access-control property. It says nothing by itself about whether the proxy hides the client identity or inspects content.

An anonymous proxy attempts not to reveal some client-identifying information to the destination. That is not a promise of universal anonymity: accounts, cookies, behavior, or other headers can still identify a user. Explain the exact information hidden rather than using anonymity as a security guarantee.

“Transparent proxy” is overloaded. In common network terminology, a transparent or interception proxy handles traffic without explicit proxy configuration in the client. Older HTTP specifications also used transparent to mean that the proxy does not transform requests or responses beyond changes needed for proxy authentication and identification. These are different properties; name the intended meaning. Intercepting encrypted content requires an applicable trust and certificate arrangement; a device that only forwards encrypted bytes cannot arbitrarily inspect their HTTP content.

The useful interview distinction is role plus policy: who can use the proxy, which destination it represents, what it can see, and what information it forwards.

05Reverse-proxy caching and API gateway policies

A reverse proxy can cache public versioned images, compress permitted responses, terminate TLS, filter malformed requests, and route to service pools. For each feature, state which requests it applies to, what it may change, and its resource or security cost. Compression uses CPU; logging can expose sensitive data; transformation can invalidate signatures or cached representations if done incorrectly.

For the private order page, choose authorization-aware forwarding and an explicit cache policy. HTTP private prevents shared caches from storing the response but can permit a browser cache; no-store tells caches not to store it. Choose the policy required by the product instead of treating those directives as synonyms. For /images/P7/v9.jpg, a shared edge cache can reuse the same immutable public bytes. The first request misses and fetches the static origin; the next permitted request hits nearby storage. Different paths can therefore have different cache and authentication policies.

An API gateway may reject excess traffic before it reaches expensive application work, but it must identify users and quota dimensions correctly. Sending all traffic through a single unreplicated gateway creates a new failure point even if the applications behind it are redundant.

06Proxy timeouts, retries and redirect rewriting

A proxy can rewrite the path it forwards so a public URL maps to a different internal path. A redirect instead asks the client to make a new request, using the destination in the response’s Location header. The two mechanisms interact when the public and internal URL layouts differ.

Path rewriting also changes visible behavior. Suppose a public service lives under /store/ while the origin serves /. A redirect from the origin to /orders/17 can escape the public prefix unless the proxy rewrites the Location header or published links avoid the redirect. Verify both the origin address and the public path; success at one does not prove the other works.

Health-check and replicate the proxy layer, measure added latency and errors, and consider how configurations roll out. A malformed routing rule can fail every healthy backend at once. Keep configuration changes reviewable and validate representative paths, headers, uploads, and redirects.

Parsing must also agree across hops. Request framing determines where one HTTP message ends and the next begins. If a proxy and backend interpret ambiguous length information differently, they can disagree about which bytes belong to an authorized request. Prefer standards-compliant parsers, reject ambiguous framing under an explicit edge policy, and apply consistent path normalization before authorization and routing. HTTP/2 or HTTP/3 at the client does not remove this boundary when an intermediary translates to HTTP/1.1 upstream. See the HTTP/1.1 framing specification.

07Interview example: justify the proxy boundary

Interviewer: “Why do you need a reverse proxy if you already have an application?”

Candidate: “It gives the public service one controlled entry point for TLS and routing. For an order request, it forwards to an eligible order server, but the server still checks that the caller can read order 17. Public versioned images can be cached at the edge; private orders cannot share that policy. I also configure deadlines, safe forwarding headers, and redundant proxy capacity. The extra hop is useful because it performs these specific responsibilities.”

NGINX can implement this reverse-proxy role with explicit upstream routing and header policy. For a protected HTTPS backend, configure certificate verification, the expected backend name and the trusted certificate set; merely selecting an https:// upstream is not the complete identity check. The current proxy-module reference documents proxy_ssl_verify as off by default, so enable verification deliberately where required. The real-IP module separately controls which proxies may supply network-address metadata. Those options do not authenticate the application user. See the proxy module and trusted real-IP configuration.

Practise the interview questions

Say your answer aloud before opening the model answer. Then answer the follow-up and compare the reasoning.

Foundation · Question 1

What is the difference between a forward and reverse proxy?

Reveal a model answer

“A forward proxy represents clients reaching external destinations, such as employees using a company web gateway. A reverse proxy represents servers to incoming callers, such as shop.example forwarding to an internal order service. Both relay responses back; the names describe role, not one-way packet direction.”

What the answer must demonstrate: Say whose behalf the proxy acts on.

Foundation · Question 2

When a reverse proxy terminates HTTPS for an order API, which connection does TLS protect?

Reveal a model answer

“The browser’s TLS connection ends at the reverse proxy, which presents the shop certificate and can inspect the HTTP request. The proxy may then establish a separate protected backend connection. I would not assume browser-to-edge encryption automatically protects the entire path.”

What the answer must demonstrate: Draw both connection segments.

Applied · Question 3

Why can’t the backend trust any X-Forwarded-For value?

Reveal a model answer

“An external caller can send that ordinary header. In a one-edge deployment I replace untrusted claims at the edge with its observed address, and the backend accepts forwarding metadata only from that trusted edge. Multiple proxies require an explicit trusted-hop traversal rule. A forged localhost value must not grant internal access, and an IP address still does not establish user identity.”

What the answer must demonstrate: Separate network provenance and identity.

Applied · Question 4

Can a reverse proxy share an authenticated order response using only its URL as the cache key?

Reveal a model answer

“No. A private order response must not become another user’s response. I choose an authorization-compatible cache policy, often avoiding shared caching for this path. Public versioned product images can use a different policy.”

What the answer must demonstrate: Protect the authorization decision as well as key separation.

Applied · Question 5

Does “open proxy” mean “anonymous proxy”?

Reveal a model answer

“No. Open describes who is allowed to use it; anonymous describes which identifying information it tries to hide. A proxy can be open and still log users or forward identifying headers. Neither term alone establishes privacy or safety.”

What the answer must demonstrate: Treat role, access, and visibility as different dimensions.

Applied · Question 6

The gateway times out on POST /checkout. Can it retry automatically?

Reveal a model answer

“Only if the checkout protocol makes repeating that logical request safe. The origin may already have committed the purchase while the response was delayed. A stable idempotency key and saved result let a retry recover the outcome; an arbitrary new POST may create a second purchase.”

What the answer must demonstrate: A timeout is an unknown outcome.

Applied · Question 7

The origin works but the public subpath fails. What do you inspect?

Reveal a model answer

“I inspect path stripping, relative links, redirects, query strings, and asset routes. If the origin redirects to a root-relative path, it may omit the public prefix. I verify the actual public URL rather than treating origin success as end-to-end proof.”

What the answer must demonstrate: Follow the visible URL through the proxy.

Applied · Question 8

Which responsibilities would you keep out of a generic gateway?

Reveal a model answer

“I can centralize routing, TLS, request-size limits, and some authentication or quota checks. The order service must still check who may read or change an order, and the component committing a purchase must enforce rules such as not selling more stock than is available. Otherwise an alternate internal caller could bypass the only business check.”

What the answer must demonstrate: Explain responsibility and shared failure modes.

Blank-page exercise · 15 minutes

Build the answer yourself

Draw an HTTPS order lookup through a reverse proxy, then diagnose a forged forwarding header and an escaped redirect.

  • Identify forward versus reverse roles.
  • Mark both TLS segments and trusted header hops.
  • Separate private order and public image caching.
  • Explain one proxy timeout or redirect failure.

Check that each component and design decision follows from your requirements and workload.

Recall the key ideas

Answer from memory before opening each card. Explain why the choice works and what it costs. Revisit missed cards tomorrow.

Proxies: forward proxy, reverse proxy and API gatewayProxy rolesRecall first, then reveal

Forward proxies serve clients; reverse proxies front origin services.

Who is represented?

Return to lesson
Proxies: forward proxy, reverse proxy and API gatewayIf a proxy terminates TLS, what must the application verify next?Recall first, then reveal

Protect and authenticate the proxy-to-application connection as needed. Trust forwarded identity headers only from approved proxies that replace untrusted client values.

Check who supplied identity at each hop.

Return to lesson
Proxies: forward proxy, reverse proxy and API gatewayGateway timeoutRecall first, then reveal

The origin may already have completed the operation.

Recover the result before repeating the action.

Return to lesson

Final revision

Summary and interview notes

A proxy forwards communication on behalf of clients or servers and can centralize connection handling, routing and caching. For each connection, specify how endpoints are authenticated, what requests are authorized, how messages are parsed, and what happens when the connection fails.

Remember these points

  • Forward and reverse describe whose side the proxy serves, not the direction responses travel.
  • TLS termination exposes HTTP to the terminator; an opaque CONNECT tunnel does not.
  • Trust forwarding metadata only from configured proxy hops, and keep network provenance separate from account identity.
  • Private response caching, path rewriting and message framing must preserve the application’s access contract.
  • A timeout may follow an origin commit; a proxy retry needs the same logical operation identity.

Interview tips

  • Draw both TLS segments and label who validates each endpoint.
  • Trace one forged forwarding header through the trusted-hop policy.
  • Test the externally visible URL, redirect and asset paths rather than checking only the origin.

Important qualifications

  • An encrypted upstream connection is not sufficient proof of peer identity unless certificate/name validation is configured.
  • A gateway can perform shared checks, but the service that changes or returns business data must also enforce the relevant correctness and access rules.
  • Replicated proxies can still share a bad configuration; rollouts and overload behavior need their own controls.

Technical references

Practice marks stay in this browser.