Practice this topic in a realistic system design interview
Distributed systems often repeat the same supporting work across many services: shipping logs, fetching secrets, exposing metrics, and encrypting traffic. Building all of that into every application leads to duplicated code, uneven upgrades, and behavior that slowly drifts between teams and languages.
The Sidecar pattern moves that work into a separate helper process that runs next to the application. The application keeps doing its main job, and the sidecar handles the supporting task.
This chapter covers what the Sidecar pattern is, how it lets us add capabilities to a service without changing its code, some common ways it is used in practice, and the trade-offs that come with running a helper process alongside every service instance.
Suppose we run thirty microservices. Along with their main business logic, all of them need a few supporting features.
The direct approach is to build all of this into every application. But that creates several problems.
What we need is a way to add these capabilities without putting them directly inside every application.
The Sidecar pattern solves this by running a separate helper process next to the main application.
The name comes from a motorcycle sidecar. It is attached to the motorcycle, travels wherever it goes, and adds extra functionality while remaining a separate unit.
The software version follows the same idea. The main application focuses on business logic, while the sidecar handles a supporting task, such as shipping logs, managing secrets, or proxying network traffic.
They run as separate processes, often in separate containers, but are deployed together on the same machine and share the same lifecycle. When an application instance starts, its sidecar starts with it. When that instance is removed, the sidecar is removed too. So every application instance gets its own sidecar.
Because the sidecar is a separate program, it can be written in a different language from the application and released on its own schedule. A sidecar written once can serve every service, whatever language that service uses.