How it works · 15 of 49 Advanced

What are a service mesh and sidecars?

Networking moved out of the code

Service mesh & sidecars: A service mesh moves the networking code every service needs (retries, timeouts, encryption between services, metrics) out of the services and into a small proxy beside each one, the sidecar. Every call leaves through its own sidecar and arrives through the other's; a control plane sets the rules once for all of them, so a policy changes without redeploying any service. The price: every call passes two extra proxies, and every sidecar uses memory and CPU.

Loading the animation…

Say it like this A service mesh moves retries, timeouts, encryption and metrics out of every service into a sidecar proxy beside it, set once from a control plane, at the cost of two extra hops and memory per sidecar.

Under the hood — for builders
The source, in its words
Istio's docs: a service mesh that "layers transparently onto existing distributed applications", giving encryption, routing and monitoring "with few or no service code changes." Sidecar mode "deploys an Envoy proxy along with each pod"; Istio "uses a proxy to intercept all your network traffic."
What moves out of the service
Data plane: the proxies that carry the calls. Control plane: the part that holds the rules and pushes them to every proxy. Istio lists what the proxies take over:
What it costs: one vendor's benchmark
Linkerd's maker ran the same app with no mesh, with Linkerd and with Istio (Kinvolk's open benchmark harness, bare-metal Kubernetes, five 10-minute runs each). Median latency at 20 requests a second, and the worst call's added delay at 200:
Without sidecars
Istio's ambient mode replaces the per-service sidecar with "a per-node Layer 4 proxy, and optionally a per-namespace Envoy proxy for Layer 7 features": fewer proxies, less memory.
Measure it
Added latency per hop (p50 and p99) · memory and CPU per proxy × number of services · time to roll out a policy · share of calls on mutual TLS.
Watch out
A mesh is one more system to run and upgrade. Retries in the mesh and in the code multiply each other. Benchmarks from a mesh's maker favour that mesh: test your own traffic.
Sources
Istio, "What is Istio?", istio.io, version 1.32 · William Morgan, "Benchmarking Linkerd and Istio: 2021 Redux", linkerd.io, 29 Nov 2021 · both read in session.

What happens in the service mesh & sidecars animation, step by step?

Service mesh off or on: Mesh off

  1. Without a mesh, every service carries its own networking code: retries, timeouts, encryption, metrics, rewritten in each language.
  2. Changing one retry rule means editing and redeploying every service.
  3. Now switch the mesh on, top right.

Service mesh off or on: Mesh on

  1. Mesh on: the networking code peels off each service and becomes a sidecar bolted beside it. The service's own code is just the business.
  2. Every call leaves through its sidecar and arrives through the other's: encrypted, retried and measured there.
  3. Rules are set once in the control plane and pushed to every sidecar. No service is redeployed.
  4. The price: two extra proxies on every call, and memory for every sidecar. In Linkerd's own 2021 benchmark the median went from 6 to 14 ms, and to 26 ms with Istio.
  5. Worth it when many services, in many languages, need the same rules. Next: services split apart that still ship together.

What everyday example explains service mesh & sidecars?

Every car gets a sidecar that handles the road. The driver just drives; the sidecar reads the signs, keeps the distance and logs the trip, and the road authority updates every sidecar at once.

Why should a team care about service mesh & sidecars?

With dozens of services in several languages, retries, timeouts and encryption written into each one drift apart and every change is a fleet-wide redeploy. A mesh makes them one policy; measure its latency and memory before adopting it.