<< back to Guides

🧱 Sidecar Pattern Guide

The Sidecar Pattern is a microservices design pattern where an auxiliary component (the β€œsidecar”) runs alongside the main application component to provide supporting features β€” without modifying the core logic.


πŸš— What Is the Sidecar Pattern?


🧰 Use Cases

Use Case Example
Service Mesh Envoy or Linkerd for traffic management
Logging & Metrics Fluent Bit, Promtail for log forwarding
Authentication Proxy Sidecar adds mTLS, OAuth handling
Configuration Management Inject config updates via sidecar
Caching Redis running as a sidecar

πŸ” How It Works

        +--------------------+       +--------------------+
        |    Primary App     | <-->  |   Sidecar Service  |
        |  (Main Container)  |       | (Helper Container) |
        +--------------------+       +--------------------+
                  |                           |
                  |--- Shared Network Space --|
                  |--- Shared Storage Vol ----|

βœ… Benefits


⚠️ Drawbacks


πŸ§ͺ Real-World Examples

1. Envoy as Sidecar (Service Mesh)

Used in Istio to control traffic between services (routing, retries, timeouts).

2. Fluent Bit Sidecar for Logs

Pushes logs to a central logging service like Elasticsearch or Loki.

apiVersion: v1
kind: Pod
metadata:
  name: loggable-app
spec:
  containers:
  - name: app
    image: my-app
  - name: log-agent
    image: fluent/fluent-bit
    volumeMounts:
      - name: varlog
        mountPath: /var/log
  volumes:
    - name: varlog
      emptyDir: {}

πŸ“Œ When to Use It


πŸ›  Tools That Use the Sidecar Pattern


🧭 Alternatives

Pattern Use Case
Ambassador Cross-cutting proxy for APIs
Adapter Transform inputs/outputs
Proxy External routing & filtering

βœ… Summary

The Sidecar Pattern is ideal for injecting platform-level capabilities like logging, monitoring, and security into microservices without coupling or rewriting them. It aligns perfectly with cloud-native and Kubernetes-first architectures.

<< back to Guides