Run a helper next to your service to handle logging, security or networking for it.
The sidecar pattern puts a small helper program right next to your main service. They run together, share the same machine (or pod), and talk over localhost.
Imagine you have 50 services. Each of them needs the same things: secure connections, retries, timeouts, logs and metrics. You can write this code as a library and add it to every service. But then you need a copy for every programming language, and every fix means changing and redeploying 50 services.
The sidecar pattern moves those chores out of the app and into a second container that is always deployed together with it. The name comes from a motorcycle sidecar: a small extra seat attached to the main bike. It shares the trip, but it is a separate part.
In Kubernetes, one pod holds both containers. They share the same network (so they talk over localhost), can share disk volumes, and always start, stop and scale together. The app does not even need to know the sidecar is there: its outgoing calls are simply sent through the sidecar.
| Job | What the sidecar does | Example |
|---|---|---|
| Network proxy | Handles all in and out traffic: retries, timeouts, load balancing, mTLS | Envoy in Istio |
| Log / telemetry agent | Collects logs and metrics from the app and ships them | Fluent Bit, OpenTelemetry Collector |
| Config / secrets sync | Keeps files fresh and fetches secrets | Vault Agent |
| Runtime helper | Gives the app a local API for messaging, state and more | Dapr |
| Adapter / ambassador | Translates formats (for example, metrics into one standard) or talks to the outside world for the app | Prometheus exporter container |
| Question | Library | Sidecar |
|---|---|---|
| Language support | One build per language | Any language |
| Extra network hop | None, runs in process | A fast local hop |
| Resource use | Small, shared with the app | Extra memory and CPU for every pod |
| Upgrade | Change code, build, redeploy | Update the image or config |
| Failure isolation | A bug can crash the app | A sidecar crash is separate (but may block traffic) |
Example numbers only (60 MB per sidecar, 1 ms per local hop). Real sidecars (Envoy, for example) vary with traffic, config and version.
| Term | Meaning in easy words |
|---|---|
| Sidecar | A helper container deployed next to the main service, sharing its pod or host |
| Pod | In Kubernetes, the smallest unit: one or more containers that share network and storage |
| localhost | The address a program uses to talk to another program on the same machine |
| Proxy | A program that passes requests on behalf of another (Envoy is a popular one) |
| mTLS | Mutual TLS: both sides prove who they are and the traffic is encrypted |
| Cross-cutting concern | A chore needed by many services (logging, security, retries) |
| Ambassador | A sidecar that represents the app towards the outside world |
| Adapter | A sidecar that changes the app's output into a standard shape |
| Init container | A short container that runs first in a pod, often to set up network rules |
| Injection | Automatically adding the sidecar to a pod definition |
| Polyglot | A system using many programming languages |
| Choice | We gain | We lose |
|---|---|---|
| Sidecar instead of library | Language freedom and central upgrades | Memory, CPU and an extra hop for each pod |
| Auto-inject everywhere | Zero work for app teams | Surprise: hidden containers that teams must understand |
| Rich sidecar (many features) | Fewer things in app code | A heavier, harder to debug sidecar |
| Tiny single-job sidecars | Simple and easy to reason about | More containers per pod |
| Library in the app | No extra hop, no extra process | Many copies to build and keep in sync |