☰ All patterns
Proxy
A stand-in that controls access to the real thing.
01
Explain it like I'm new
Real-life analogy
A personal assistant
People ask the assistant for the boss's schedule. If they already know the answer they reply instantly; otherwise they ask the boss once and remember it.
😩 The problem
A weather API is slow and costs money per call. Many parts of your app ask for the same city again and again.
💡 The pattern
Put a proxy that implements the SAME interface in front of the real service. It decides whether to answer from cache, check permissions, or forward the call.
02
Play with it
An interactive model of the pattern. Click around, nothing can break.
- Requests
- 0
- Real API calls
- 0
- Time saved
- 0.0s
💡 The caller code is identical either way. It just calls weather.Temperature(city). Only the proxy knows about the cache.
03
Walk through the code
Click a step to highlight its lines. This is a complete program you can copy and run.
Press ▶ Run to execute this program.This output was captured by running the program with Go 1.24. Copy it into your editor or the Go Playground and try changing things.
04
When should I use it?
✅ Reach for it when…
- •Caching, rate limiting, access control, lazy initialisation, logging remote calls.
🚫 Skip it when…
- •The extra layer adds complexity without a clear benefit.
🐹 Go tip
For concurrent use, guard the cache map with a sync.Mutex, or use sync.Map for read-heavy workloads.
🌍 You've already seen it in
httputil.ReverseProxy, gRPC client stubs and caching wrappers around repositories.
05
Quick check
One question. No pressure.
How is a Proxy different from a Decorator?