How to secure a legacy app nobody dares redeploy
Gateways, sidecars and ambassadors can add authentication and logging from outside, provided each sits in the right place and the application keeps its own logic.
In brief
- A gateway sits in front of services and handles authentication, TLS, logging and throttling; a sidecar runs beside each instance; an ambassador runs beside the client and handles outbound calls.
- A gateway only works if the backend rejects every request that does not come through it, and it must never contain business logic.
- An ambassador should retry only idempotent operations, while a gateway must be designed and load-tested so it does not become a single point of failure.
One week to add API authentication, produce logs the security team can read and move some traffic to a new reporting service: that is the Monday-morning brief in this hypothetical engagement. The client’s order management system is a Java application written years ago. Its author has left, it has no tests and nobody dares redeploy it.
The first reflex of many engineers is to open the code and start editing. For an FDE, that is usually the worst option: the code is not yours, the client bears all the regression risk, and few people will sign off on a new build within a week.
The skill needed here is adding capabilities to the system from outside, with a proxy in the right place.
Microsoft’s Azure architecture documentation groups this work into clearly named patterns: gateway, sidecar, ambassador and a security-focused variant, gatekeeper. Once you know them, the next time you hear “you can’t change the code, but we need more features”, you will know where to put the proxy.
Where should the proxy sit, and what can it handle?
A request starts at the client, crosses the network and reaches the service. The three patterns differ in where the proxy stands along that path.
A gateway sits in front of a group of services. As the Gateway Routing pattern describes it, the gateway routes at Layer 7, so the client needs to know only one endpoint. You can add, split or rearrange the services behind it without changing the client. The Gateway Offloading pattern goes a step further: the gateway takes over cross-cutting concerns such as certificate management, authentication, TLS termination, monitoring, protocol translation and throttling from the backend.
A sidecar is a process or container that runs beside the application. Each instance has its own sidecar, and the two share a lifecycle. Because it runs separately, the sidecar does not depend on the application’s language. Service meshes such as Istio use sidecar proxies to provide mTLS, retries and telemetry without changes to application code.
An ambassador is also an out-of-process proxy, but it shares a host with the calling side. It handles monitoring, logging, routing, TLS and resiliency for outbound calls. Microsoft suggests this pattern for extending the networking capabilities of legacy applications or those that are hard to modify.
| Gateway | Sidecar | Ambassador | |
|---|---|---|---|
| Position | In front of a group of services | Beside each service instance | Beside the client, on the same host |
| Main traffic direction | Inbound | Into and out of one instance | Outbound |
| Best fit | A shared entry point with authentication and logs is needed | mTLS and telemetry are needed between services | An old app calls external APIs without TLS, retries or logs |
| Cost | Can become a single point of failure and a bottleneck | Adds latency and resource use to each instance | Adds latency; retries can easily cause harm |
Example: putting a gateway in front of the order application
Back to the client. Say the order application listens on port 8080, the new reporting service is on port 9000, and the client’s IT team already has a token verification service. A minimal nginx configuration for the gateway could look like this:
log_format json escape=json
'{"time":"$time_iso8601","method":"$request_method",'
'"uri":"$request_uri","status":$status,'
'"rt":$request_time,"user":"$auth_user"}';
server {
listen 443 ssl;
ssl_certificate /etc/nginx/certs/api.crt;
ssl_certificate_key /etc/nginx/certs/api.key;
access_log /var/log/nginx/api.json json;
location = /_auth {
internal;
proxy_pass http://auth-svc/verify;
proxy_pass_request_body off;
proxy_set_header Content-Length "";
proxy_set_header X-Original-URI $request_uri;
}
location /api/orders/ {
auth_request /_auth;
auth_request_set $auth_user $upstream_http_x_user;
proxy_pass http://legacy-orders:8080;
}
location /api/reports/ {
auth_request /_auth;
auth_request_set $auth_user $upstream_http_x_user;
proxy_pass http://reports-v2:9000;
}
}
Read the file against the client’s three requirements. Authentication lives in auth_request: every request must pass through /_auth first, and the Java application knows nothing about it. Logging lives in log_format json: each request writes one JSON line with the time, status code, latency and caller, which the security team can feed straight into its own systems.
Routing lives in the two location blocks. The client knows only one domain name, while /api/reports/ quietly goes to the new service. If the new version fails, rolling back means editing one proxy_pass line and reloading the gateway. As the Gateway Offloading pattern notes, the gateway gives you a baseline of monitoring and logging even when the service behind it is not properly instrumented.
What you must do once the configuration works
The setup above is still unsafe if the order application leaves port 8080 open to the internal network. Anyone who knows the address can call it directly, skipping authentication and leaving no log line.
Microsoft’s guidance is explicit that the backend should accept only requests that come through the gateway. In practice, you can enforce this with a firewall, security group or network policy that admits only the gateway’s IP.
The Gatekeeper pattern goes further. The intermediary that validates and sanitizes requests runs with limited privileges, while the application side holds access to storage and services. Applied here, the gateway should not hold the database password or backend keys, so that the damage is contained if it is compromised.
At the client site, roll out in this order. First run the gateway in parallel and only log, with authentication off, to see what real traffic looks like. Then turn on authentication route by route, close the direct path to the backend and, last of all, gradually shift traffic to the new service.
Sidecar and ambassador: when the gateway cannot reach
A gateway controls only the traffic that passes through the front door. When services inside a cluster call one another, or an old application calls a partner’s API, you need a proxy closer in.
Say the client runs on Kubernetes and wants traffic between services encrypted. A sidecar proxy in each pod, for instance through Istio, can provide mTLS and collect telemetry without the application knowing.
Istio’s documentation describes a service mesh as bringing zero-trust security, observability and advanced traffic management, with two modes: ambient or traditional sidecar.
If the order application calls a payment API over plain HTTP, with no timeout and no logs, put an ambassador on the same host. The application calls localhost; the ambassador handles TLS, logs each outbound call and applies a timeout. The old code stays as it is.
Four common traps
The first trap is leaving the backend open, as described above. The second is more dangerous because it comes from good intentions: the client asks, “While you’re at it, can you check the credit limit at the gateway?” Microsoft’s guidance says plainly that business logic should never be offloaded to the gateway.
A similar temptation arises with Gateway Aggregation, in which the gateway calls several backends and combines the results to spare the client multiple calls. If the aggregation logic starts to get complex, move it into a separate aggregation service behind the gateway.
The third trap is enabling retries in the ambassador for everything. Microsoft cautions that retries in an ambassador may be unsafe if the operations are not idempotent.
Say a create-payment call succeeds but its response times out. The proxy sends it again, and your client’s customer is charged twice.
Retry only operations such as GET, or writes that carry an idempotency key.
The fourth trap is forgetting that every request now passes through the gateway. It can become a single point of failure and a bottleneck, so load-test it before production and design it to the client’s availability requirements, for example by running multiple instances.
Sidecars have costs of their own: they add latency, waste resources on small applications and may be unnecessary if the client’s mesh already has a sidecarless data plane.
Which proxy would you choose in these three situations?
Answer before reading on. Situation A: an old reporting application calls a vendor’s API over plain HTTP, and the client wants TLS and a log of every outbound call. Situation B: an external partner needs a single authenticated endpoint to call three internal services.
Situation C: services on Kubernetes call one another, and the security team wants that traffic encrypted and telemetry collected without code changes.
The answers: A is an ambassador, because the problem lies in outbound traffic from the client side. B is a gateway, because the partner needs a shared entry point that handles authentication and routing.
C is a sidecar proxy in a service mesh, or ambient mode if the client’s mesh supports it and it meets the requirements. If you got all three right, you have grasped the core question: which way is the request going, and where on that path does the proxy stand?
How do you show this skill on a résumé?
When reading job descriptions for FDE or solutions engineer roles, look for phrases such as “integrate with legacy systems”, “API gateway”, “service mesh” and “observability”.
On your résumé, go beyond “knows nginx, Istio” and describe the outcome. For example: added authentication and structured logging to a legacy system through a gateway, with no code changes, and closed direct access to the backend. That line shows an interviewer that you understand both the technology and the client’s constraints.
The next time someone says “nobody dares touch this system”, don’t treat it as a dead end. It is usually the moment to ask where the requests travel and at which point to place a proxy.
Was this article useful?
Thanks for the feedback!
7 sources
- Gateway Routing pattern - Azure Architecture Center | Microsoft Learn · 2022-08-29
- Gateway Offloading Pattern - Azure Architecture Center | Microsoft Learn · 2026-09-23
- Gateway Aggregation Pattern - Azure Architecture Center | Microsoft Learn · 2026-06-02
- Sidecar Pattern - Azure Architecture Center | Microsoft Learn · 2026-02-17
- Ambassador Pattern - Azure Architecture Center | Microsoft Learn · 2026-02-25
- Gatekeeper Pattern - Azure Architecture Center | Microsoft Learn · 2026-06-01
- The Istio service mesh