Proxy
Description
A proxy is a stand-in that preserves the subject’s interface but interposes itself between client and subject. From the client’s perspective the proxy is indistinguishable from the subject — same calls, same return shapes — but the proxy gets to do something on the way through: check permissions, cache results, lazy-instantiate the real subject, log accesses, throttle, encrypt, marshal to a remote process. The defining contrast is with adapter: an adapter changes the interface shape, a proxy preserves it. The defining contrast with decorator is orientation: a decorator adds behavior to operations; a proxy controls access to operations.Triggers
User-initiated: User describes wanting to add caching, access control, logging, or remoting without changing the surface the rest of the code calls. Vocabulary cues: “transparent,” “intercept,” “on the way through,” “without the caller noticing,” “stand-in.” Agent-initiated: Agent notices that some cross-cutting concern (auth, logging, caching, rate-limiting, remoting) is being repeatedly tangled into call sites and would be better absorbed at a single interception point. Candidate inference: “introduce a proxy in front of the subject; pull the cross-cutting concern out of the call-site noise.” Situation-shape signals: Repeated boilerplate around access to a single resource. A subject that’s expensive to construct but cheap to wrap. A boundary between two trust domains where access deserves checking. A subject that needs to be reachable from another process / machine.Exclusions
- No cross-cutting concern to absorb — if every call site has its own bespoke pre/post logic, there’s nothing for the proxy to factor out; adding a proxy is then overhead without reuse.
- The control is semantic, not structural — if “controlling access” means changing what the operation means (different return values, different effects), it’s not a proxy anymore; it’s an alternate implementation pretending to be a proxy, which leaks badly.
- Performance budget can’t afford the indirection — tight loops and hot paths sometimes can’t tolerate even a virtual-method-call layer; the proxy must be inlined or omitted.
Structure
Relationships
- active-gate-vs-passive-audit — the protection-proxy variant is exactly active-gate; the proxy blocks before passing through, vs. audit that records and surfaces later.
- surface — the proxy is the surface the client sees; the subject is what’s behind the surface, possibly with structural detail the client never needs to see.
- adapter — proxy and adapter are siblings at the interface boundary; proxy preserves the shape, adapter changes it.
- decorator — proxy and decorator share the wrap-the-subject shell but differ in intent: control vs. extend.
- cost-cascade — caching proxies are the canonical cheap-default → expensive-fallback case; the proxy serves from cache and only falls through to the subject on miss.
Examples
HTTP forward / reverse proxies · computer-science
HTTP forward / reverse proxies · computer-science
Legal proxy (power of attorney; proxy voting) — predates software; the structural shape is "stand-in authorized to act in subject's place" · law
Legal proxy (power of attorney; proxy voting) — predates software; the structural shape is "stand-in authorized to act in subject's place" · law
CPU cache · computer-science
CPU cache · computer-science
Gamma, Helm, Johnson, Vlissides (1994), Design Patterns: Elements of Reusable Object-Oriented Software (Gang of Four). Structural pattern, ch. 4. · computer-science
Gamma, Helm, Johnson, Vlissides (1994), Design Patterns: Elements of Reusable Object-Oriented Software (Gang of Four). Structural pattern, ch. 4. · computer-science
adapter and decorator are where the contrast lives.GoF protection proxy · computer-science
GoF protection proxy · computer-science
GoF remote proxy · computer-science
GoF remote proxy · computer-science
GoF smart proxy / smart pointer · computer-science
GoF smart proxy / smart pointer · computer-science
GoF virtual proxy · computer-science
GoF virtual proxy · computer-science
Service mesh sidecar (Envoy, Istio) · computer-science
Service mesh sidecar (Envoy, Istio) · computer-science