Sidecar

Run supporting features such as proxying, logging or config sync in a separate container next to the app, sharing its lifecycle but not its code.

Description

A sidecar is a helper process deployed alongside each instance of an application, in the same pod or task, sharing its network and sometimes its disk. It adds capabilities without touching the application's code: TLS and retries (a service-mesh proxy), log shipping, metrics, secret refresh, or a local cache.

Because the sidecar is separate, it can be written in any language, upgraded on its own schedule, and reused across every service in the company. The app just talks to localhost or writes to a shared folder.

System design

One podmTLS request1localhost2writes to shared volume3ship logs4Other servicesMesh proxysidecar: mTLS, retriesOrders appplain HTTP on localhostLog shippersidecarLogging backend

Sidecar system design diagram

  1. Other services (client).
  2. Mesh proxy (gateway): sidecar: mTLS, retries.
  3. Orders app (service): plain HTTP on localhost.
  4. Log shipper (function): sidecar.
  5. Logging backend (external service).
  6. Step 1: Other services → Mesh proxy: mTLS request.
  7. Step 2: Mesh proxy → Orders app: localhost.
  8. Step 3: Orders app → Log shipper: writes to shared volume.
  9. Step 4: Log shipper → Logging backend: ship logs.
  1. Another service calls the orders app over mutual TLS. The sidecar proxy terminates it and enforces policies.
  2. The proxy passes the request to the app on localhost. The app knows nothing about certificates.
  3. The app writes its logs to a folder shared within the pod.
  4. A log-shipping sidecar sends them on to the logging backend, so the app has no logging SDK to configure.
AWS
ECS task definitions with multiple containers; EKS with Istio/App Mesh Envoy sidecars; FireLens for logs.
Azure
AKS pods with sidecars (Istio add-on); Container Apps with sidecar containers and Dapr.
Google Cloud
GKE pods with Cloud Service Mesh; Cloud Run sidecars (multi-container).

When to use it

Use it when

  • Many services written in different languages need the same infrastructure feature.
  • You want platform concerns (mTLS, telemetry, config) handled consistently without every team implementing them.
  • The feature must run next to each instance, with low latency and the same lifecycle.

Avoid it when

  • There's one service in one language. A library is simpler and cheaper.
  • Resources are tight. Every instance pays the sidecar's CPU and memory.
  • The interaction is so latency-critical that even a localhost hop matters.

Pitfalls

  • Resource overhead multiplied across hundreds of pods. Size sidecars carefully.
  • Startup and shutdown ordering: the app starts before its proxy is ready, or the proxy dies first and drops in-flight requests.
  • Debugging across two processes. Make the sidecar's logs and metrics as visible as the app's.

Alternatives

Ambassador

Choose it when the helper's job is specifically outbound calls to remote services: retries, routing, auth.

Shared library

Choose it when all services use one language and you control their builds.

Node-level agent (DaemonSet)

Choose it when one agent per machine is enough, as for log collection.