Stackbook Logo
distribution-communicationestablished · medium operational burden

Sidecar

Also known as: sidecar-container, sidecar-proxy

Intent

Deploy supporting functionality in a separate process or container that shares the lifecycle and network namespace of the main application.

Problem

Cross-cutting concerns such as TLS, logging, metrics and retries are reimplemented in every service and language, drifting out of sync and coupling application releases to infrastructure upgrades.

Forces

  • •Polyglot services cannot share one client library
  • •Infrastructure concerns evolve faster than applications
  • •Isolation between app and helper limits blast radius
  • •Extra processes cost memory and latency

Solution

Overview

A sidecar is a companion process attached to a primary application, like a sidecar on a motorcycle. It extends the application without modifying it and lives and dies with it.

How it works

In Kubernetes, containers in one pod share a network namespace and can share volumes. A proxy sidecar intercepts or receives traffic on localhost, applies policy and forwards it.

Pod
+------------------------------+
| app  <--localhost-->  sidecar|--> network
|   \--shared volume--/        |
+------------------------------+

Common roles: mesh proxy for mTLS and retries, log forwarder tailing a shared volume, secret refresher writing credentials to a file, config watcher reloading settings.

Pitfalls

  • Startup ordering. Make the app wait for sidecar readiness or use native sidecar container support so ordering is guaranteed.
  • Shutdown ordering. Traffic proxy must outlive the app while it drains in-flight requests.
  • Jobs that never finish because the sidecar keeps the pod running.
  • Under-sized resource requests, causing throttling of the proxy and tail latency spikes.
  • Multiplying overhead: fifty instances at 100 MB each is 5 GB just for helpers.
  • Version skew across the fleet after slow sidecar upgrades.

Key takeaways

  • Sidecars move cross-cutting concerns out of application code.
  • They share lifecycle, network and storage with the app.
  • Budget the per-instance cost and manage version rollouts.
  • Define explicit startup and shutdown ordering.
  • Prefer a library when you have one language and tight latency needs.

✓ When to Use

  • •Polyglot fleets needing uniform networking, security or telemetry
  • •Adding capability to legacy apps without changing code
  • •Concerns that must follow each instance such as log shipping

✗ When Not to Use

  • •Very small deployments where a library is simpler
  • •Latency budgets too tight for an extra hop
  • •Resource-constrained environments with thousands of tiny instances

Pros

  • +Language-agnostic reuse of infrastructure logic
  • +Independent upgrade path and ownership
  • +Fault isolation between app and helper

Cons

  • −Per-instance CPU and memory overhead
  • −Added hop and more moving parts to debug
  • −Startup and shutdown ordering issues

Cost Profile

Infrastructure

Medium - resource overhead multiplied by instance count

Operational

Medium - fleet-wide sidecar version rollouts

Cognitive

Medium - two processes to reason about

Failure Modes

  • App starts before sidecar is ready and drops early traffic

  • Sidecar crash or hang takes down all traffic for that instance

  • Sidecar keeps a job pod alive after the main container exits

Real-World Examples

Alternatives

  • service-mesh

Related Patterns

  • ambassador
  • service-mesh
  • kubernetes-patterns
  • mtls

Competency Domains

distribution communicationreliability ops