Design Pattern

Container Design Pattern – Sidecar Pattern


The container is a software package that includes all your code, dependencies (configuration and system libraries). A design pattern provides an already established solution/method for implementation. In the case of a container, design patterns help in building/deploying an application that is reliable and scalable by using already proven methods.

In this series, We will be going through a few design patterns which can be used for container development/deployment in a distributed environment. Let’s begin.

Sidecar pattern

As the name suggests, in the sidecar pattern a secondary container is attached to the primary container and is deployed in the same pod. It shares the pod resource with the main container. It extends the functionality provided by the main container. At the same time, this can be used as a reusable component.



A container that reads/polls log messages from published by the main container and publish it some monitoring system. This can be attached as a sidecar to any container that needs to publish logs to a monitoring system.

Below is an example of a yaml definition for deploying a sidecar named “logmonitor”. We are going to provide definitions of two containers in the “containers” tag, the first one is “maincontainer” and the second is “logmonitor” (working as sidecar).

– name: maincontainer
image: maincontainerImg

– name:logmonitor


Even though functionality provided by sidecar can still be part of the main container itself, here are some of the benefits of having it as a separate container:

  • Sidecar components can be developed/maintained separately. It can be managed by a different team and can be written in a completely different language as compared to the main container.
  • Sidecar being a common functionality can be attached to different(not multiple) containers. Different pods can have one sidecar container deployed along with the main container.
  • The point of failure is segregated, even if the sidecar is failing due to any reason it will not impact the main container.
  • The sidecar can be upgraded independently.

While using sidecar pattern it’s useful to keep in mind other than the above advantage it comes with an overhead and latency in calls.

In the next blog, we are going to cover “Adapter Pattern”