Sidecar pattern

No Comments

This is the content from chapter 2 in Designing Distributed Systems.

1. What is the sidecar pattern?

Usually, we deploy a new container along with the application container, instead of deploying the application container alone, for realizing some functions(proxy, monitor, etc.). We call this the sidecar pattern. It belongs to the single-node pattern.

2. What can sidecar pattern help us?

We can realize such functions with the sidecar pattern: proxy, monitoring, and synchronization as PaaS.

  • Proxy
An illustration of the HTTPS sidecar
Figure 1

For example, we have a legacy backend application only support HTTP. Now if we want to use HTTPS, we can use the sidecar SSL proxy container to handle HTTPS requests and forward them to the old legacy service.

  • Synchronization as PaaS
A sidecar example for managing dynamic configuration
Figure 2
Illustration of a simple sidecar based Platform as a Service (PaaS)
Figure 3

Check figures above, with the sidecar application, developers can easily update the configure file or repository codes.

  • Monitoring

We can deploy a sidecar container with the same IPC namespace as the original application container. We then collect the resource usage from the sidecar container and expose a port from the sidecar container for metrics collection.

Designing Sidecars for Modularity and Reusability

We follow these three rules to build our sidecars:

  1. Parameterizing your containers
  2. Creating the API surface of your container
  3. Documenting the operation of your container