Sidecar Pattern with Use Case Examples

Raju Dawadi
3 min readOct 14, 2018

--

Sidecar by name is assisting entity that stays attached with main application and perform some action to extend or improve the parent container like as sidecar of motorbikes. Rather than adding additional logics on main container other than application logics and dependencies, its better to employ sidecar container for better performance, enhance functionality and maintainable. It isn’t necessary to use container only as sidecar but in this post, we will focus keeping sidecar container in center.

Motorcycle with Sidecar

Why use Sidecar Pattern?

  1. Keep application logic intact and maintainable: Using sidecar pattern enables to keep parent container with application logic only without adding complexity of additional logic & configuration.
  2. Secure or access control application container: By using sidecar pattern, configurations can be made to filter traffic or control access to main container keeping it secure.
  3. Separate networking configurations from application container: For the operation of application, there is need of external dependencies, networking logics can be managed by sidecar container
  4. Reusability of containers: Common logic in sidecar container is reusable across similar application containers rather than adding the functionality of sidecar to application container itself

Now, let’s dive into some use case examples where sidecar pattern could make application deployment, operation easy and maintainable.

  1. Git sync: This is simple way of updating application code and keep in sync with the respective git repo. We can use a sidecar container that keeps the application updated at certain interval by running git pull command. This could prevent using a separate pipeline but would not be a good way to manage dependencies and for larger application. An example of git sync is on this Kubernetes deployment config.
  2. Keeping server configuration updated: If we are using nginx, apache, haproxy like servers, they might need to be updated and reload the servers. Using sidecar container for the purpose eases and makes it faster for updating the configs. Sidecar container can be configured to download server config from a static link and reload the server if the config is changed.
  3. Sending logs of application to logging servers: There are numerous logging service providers paid and open source. We can assure of using specific service to the end of world. If we keep the logging service logic considering one service, it makes us vendor lock. By offloading the log transmitting logic to sidecar container, we can easily shift and also use multiple logging platform at once.
  4. SSL termination: This sounds like ambassador pattern but we can employ sidecar for ambassador services like: circuit breaking, routing, monitoring.
  5. Managing application configuration/variables: If we have volume mounted environment variables or any application configuration, sidecar pattern can easily update them. Also, sidecar container with connection to some external service can be configured to trigger application container to do some update.

If you have any cool examples of using sidecar pattern, I would be very interested to hear. That’s all for now.

--

--

Raju Dawadi
Raju Dawadi

No responses yet