Skip to main content

Sidecar Pattern

The Sidecar pattern runs a helper component alongside the main app in the same unit to add capabilities like proxying, logging, or config without changing the app. It lets teams apply cross-cutting concerns uniformly across diverse services.

Organization
Microsoft
Published
Jun 23, 2018

Best Practice: Sidecar Pattern

The Sidecar pattern attaches a helper component to a main application and runs it in the same deployment unit, such as the same Kubernetes pod. The sidecar shares the application's lifecycle and host but runs as a separate process. It handles supporting concerns the application should not have to implement itself: proxying network traffic, shipping logs, fetching configuration, or terminating TLS. Because the sidecar is independent, it can be written in any language and updated without touching the main app. Microsoft documents it as a cloud design pattern, and it underpins service meshes. It matters when you want to add capabilities uniformly across diverse services without modifying each one.

Step-by-Step Implementation Guidance

  1. Identify cross-cutting concerns that are not core to the application's purpose.
  2. Confirm the concern benefits from sharing the app's host and lifecycle.
  3. Package the sidecar to deploy in the same unit as the application.
  4. Communicate over localhost or shared volumes to keep latency low.
  5. Keep the sidecar's interface stable so the main app does not couple to its internals.
  6. Set resource limits on the sidecar so it cannot starve the main container.
  7. Manage sidecar versions and updates independently from the application.

Common Mistakes Teams Make When Ignoring This Practice

  • Re-implementing logging, proxying, or config loading inside every service.
  • Using a sidecar for concerns that do not need to share the host, adding needless overhead.
  • Letting the sidecar consume unbounded resources next to the main container.
  • Coupling the application tightly to a specific sidecar implementation.
  • Forgetting that the sidecar adds startup and shutdown ordering considerations.

Tools and Techniques That Support This Practice

  • Kubernetes pods, which natively support multi-container sidecars.
  • Envoy proxy as a networking sidecar.
  • Fluentd or Fluent Bit as logging sidecars.
  • Service meshes such as Istio and Linkerd, built on sidecars.

How This Practice Applies to Different Migration Types

  • Cloud Migration: Add observability or proxy sidecars to legacy apps without rewriting them.
  • Database Migration: Use a sidecar proxy to manage connections and retries to a transitioning datastore.
  • SaaS Migration: Run an adapter sidecar that translates between your app and a SaaS API.
  • Codebase Migration: Offload cross-cutting concerns to sidecars while extracting services from a monolith.

Checklist

  • Identify cross-cutting concerns suitable for a sidecar.
  • Confirm the concern needs to share the app's host and lifecycle.
  • Deploy the sidecar in the same unit as the app.
  • Communicate over localhost or shared volumes.
  • Set resource limits on the sidecar.
  • Keep the app decoupled from sidecar internals.
  • Version and update sidecars independently.