esc
  • WorkflowsPages
  • Case studiesPages
  • Machine Learning FoundationsLearn
  • AI EngineeringLearn
  • AI Guardrails & Red TeamingLearn
  • UI/UXLearn
  • Design SystemsLearn
  • Production System DesignLearn
  • Book a callContact
  • Download ResumeContact
Let’s talk

I’ll build the agent for it.

Sidecar: A Helper Container That Runs Beside Your App, Not Inside It

Learn how a sidecar helper runs next to your main app, why teams use one, and what it costs in resources, complexity, and delay.

In short

A sidecar is a separate process or container deployed next to your main application, running as a helper beside it rather than inside it.

10 min readFree

What you will learn

This lesson teaches the sidecar pattern, a cloud design pattern you will meet often in system design. You will learn what a sidecar is, how it runs beside your main app, why teams use one, and when it is the wrong choice. By the end, when someone says 'add a sidecar', you should know what that means and what it costs.

Key words

Sidecar
A helper process or container that runs next to your main app. It shares the app's host and life cycle, but it is a separate program.
Main application
The program that does the core work of your product, such as the rules for a shop's checkout.
Host
The machine or virtual server where programs run.
Container
A packaged program with everything it needs to run, kept separate from other programs on the same machine.
Kubernetes
A system that runs and manages containers across one or more machines.
Pod
In Kubernetes, the smallest group of containers that Kubernetes places together. The containers in a pod share a network address and can share storage.
Life cycle
The stages a program goes through, from start to stop.
Cross-cutting concern
A job that many parts of a system need, such as logging, encryption, or settings, but that is not the core business task.
Proxy
A middleman program that receives network traffic and forwards it on, often after checking or changing it.
TLS
Transport Layer Security, the encryption used when two programs talk over a network, such as in HTTPS.
Telemetry
Data a running system reports about itself, such as request counts, timings, and error logs.
Service mesh
A layer made of proxies placed beside each service, plus a control part that tells those proxies what to do.

How does a sidecar run?

A sidecar is a separate process or container that you deploy next to your main application. The name comes from the small seat bolted to a motorcycle. The seat is not the bike, but it travels with the bike and is built and retired with it. A sidecar works the same way. It is its own program, yet it is tied to the app it helps.

Why the same host and the same pod?

The sidecar runs on the same host as the app. In Kubernetes, the usual layout is one pod with two containers: the app container and the helper container. Both containers can reach the same network address, and they can read the same shared storage volume. That is how a helper can see the log files an app writes. Tools in this space describe the same layout, with one main container and one helper container inside a single pod.

Shared life cycle

Each copy of the app gets its own copy of the sidecar, and the two are created and retired together. Kubernetes offers native sidecar containers that start before the main container and stop after it. So the helper is ready when the app begins and is still running while the app shuts down. Even with this shared life cycle, you can update the helper's program without changing the app's code.

Why do teams use sidecars?

Many jobs are needed by almost every service but are not the core business task. These are cross-cutting concerns. Logging, encryption, monitoring, and settings are common examples. Design guidance from Microsoft says a sidecar lets you attach these common functions to a service without writing them into the service's code. Four benefits stand out.

  • Business code stays focused

    The checkout code can keep to checkout rules. Logging, encryption, and metrics live in the helper, so the code that handles orders is smaller.

  • Any language can be used

    A sidecar runs in its own runtime. A Java app, a Python app, and a Go app can all use the same helper, so none of them needs its own matching library.

  • One helper serves many services

    A team can build one helper and attach it to every service. When the helper is improved and redeployed, each service that uses it gets the change without editing its own code.

  • Clear ownership

    A platform team can own the helper while product teams own their apps. Azure guidance lists a separate team owning a component as a reason to choose this pattern.

Worked example: a checkout service with an Envoy sidecar

Here is a hypothetical setup. A Node.js checkout service runs in a Kubernetes pod. The team uses Istio, a service mesh that manages traffic between services. Istio adds a proxy beside each app container. The proxy is Envoy, a fast program that receives network traffic and forwards it. Istio's control part sends Envoy its settings. Follow the path of one checkout request.

  1. 1

    The app runs alone

    The checkout code listens on a local port and handles cart and payment rules. It contains no encryption code, no retry loop, and no metrics code.

  2. 2

    The mesh adds the proxy

    When the pod starts, Istio adds the Envoy container to the same pod. Network rules then send traffic through Envoy first, so the app does not need to know the proxy exists.

  3. 3

    Envoy encrypts the traffic

    Calls between services use mutual TLS. In this setup, both sides present proof of identity and the traffic is encrypted. The checkout code sends ordinary requests, and Envoy does the encryption at each end.

  4. 4

    Envoy retries failed calls

    If a call to the payment service fails in a way the rules allow to retry, Envoy tries again. The checkout code needs no retry loop. Which failures are safe to retry is a topic for another lesson.

  5. 5

    Envoy reports metrics

    Envoy counts requests and measures how long they take, then sends those numbers to a monitoring system. Istio's proxies collect and report telemetry on mesh traffic.

  6. 6

    The team changes the helper alone

    If the team upgrades Envoy or changes a routing rule, it does not edit or rebuild the checkout code. Istio's control part pushes the new settings to the proxies while the system runs.

Tip

Before you add a sidecar, ask two questions. Can this job run without reading the app's private data? Will many services need the same job? If both answers are yes, a sidecar is a strong candidate.

Try it: a logging helper in miniature

Real sidecars are separate programs, which is hard to show in one short script. This script copies the idea. The app function only writes plain text lines to a shared list, which stands in for a shared volume. The helper reads those lines and prints them as JSON records. The app function never uses a JSON library.

Python
import json

shared_log = []  # stands in for a volume both containers can read

def app_handle_request(path):
    # the main app only writes a plain line
    shared_log.append(f"GET {path} 200")

def sidecar_ship_logs():
    # the helper reads the plain lines and formats them as JSON
    shipped = []
    for line in shared_log:
        method, path, status = line.split()
        record = {"method": method, "path": path, "status": int(status)}
        shipped.append(json.dumps(record, sort_keys=True))
    return shipped

app_handle_request("/cart")
app_handle_request("/checkout")
for record in sidecar_ship_logs():
    print(record)

Output

{"method": "GET", "path": "/cart", "status": 200}
{"method": "GET", "path": "/checkout", "status": 200}

Notice that the app function knows nothing about JSON. If the team changes the log format, it changes only the helper. That is the core benefit of the pattern, shown on a small scale.

What are the trade-offs and when should you not use one?

A sidecar is not free. Each one adds cost and moving parts, so weigh the gains against these costs before you choose it.

  • Extra resources for every instance

    Each app copy gets its own helper, which uses its own CPU and memory. Istio's proxy is known to use CPU and memory. Set resource limits so the helper cannot starve the app. Resource contention between tenants is a separate topic for another lesson.

  • More to deploy and debug

    You now ship two programs where you had one. Reading logs or running commands needs the container name, and each upgrade has two parts to check.

  • A small latency hop

    Calls between the app and its helper cross a process boundary. An arXiv study of etcd deployment on Kubernetes and Istio found that Istio does more work per request and has lower throughput than native Kubernetes. This hurts apps that talk to their helper many times for each request.

  • Poor fit for tiny apps or separate scaling

    A small app can spend more on helpers than it gains. If the helper must scale on its own schedule, a separate service is the better choice.

A library is sometimes the better tool. Azure guidance notes that language-specific libraries integrate more deeply and add less network overhead. Prefer a library when one language dominates and the job is small. Choose a sidecar when many languages must share one behavior, or when a separate team owns that behavior.

Check your understanding

Quick check

Your company has a Java service, a Python service, and a Go service. All three must ship logs to one central system in the same format. You do not want to write a logging library three times. What could you deploy beside each service, and what is one cost?

Knowing when to skip one

Sidecars suit shared jobs in larger systems. They suit small systems less well. Check the size of the app and the cost of each copy before you agree to add one.

Quick check

A team runs a tiny app on one small host. It returns a single page and does very little work. A colleague wants a sidecar to handle logging and metrics. What is the strongest reason to hold off?

Key takeaways

  • What it is

    A sidecar is a helper program or container placed beside your app. It shares the host or pod and starts and stops with the app.

  • Why teams use it

    It moves logging, encryption, metrics, and settings out of business code. It works across languages and can serve many services from one helper.

  • What it costs

    Each copy uses resources, adds deployment steps, and can add a small delay. It fits poorly with tiny apps and with parts that must scale on their own.

Sources

How is this lesson?

Last updated on 18 November 2026

Learn with me

Every lesson is free. I add new ones as I learn. Have a question, or want help with your own work? Book a short call.