Topic 150 / Advanced
Service mesh
Chapter 9.3 · Communication Topologies
What and why
One sidecar (→ 149) solves cross-cutting concerns for one service; running that same sidecar next to every service in the fleet, with one control plane configuring all of them consistently, is a service mesh. It moves mTLS, retries, timeouts, traffic routing and telemetry out of every application entirely and into infrastructure, configured once. Builds on: → 149 (sidecar and ambassador).
Diagram
┌────────────── control plane ──────────────┐
│ (central config: routing rules, mTLS │
│ certs, retry policy — pushed to every │
│ sidecar) │
└──────────────────┬─────────────────────────┘
│ configures
┌───────────────┬──────────────┼──────────────┬───────────────┐
▼ ▼ ▼ ▼ ▼
[Service A + [Service B + [Service C + [Service D + [Service E +
sidecar] ◄──► sidecar] ◄──► sidecar] ◄──► sidecar] ◄──► sidecar]
every service-to-service call now goes sidecar-to-sidecar
How it works
- Deploy a sidecar (→ 149) next to every service instance in the fleet, not just one.
- Every service-to-service call is intercepted by the local sidecar and routed sidecar-to-sidecar, not application-to-application directly.
- A control plane pushes consistent configuration to every sidecar: mTLS certificates (every call encrypted and mutually authenticated by default), retry and timeout policy (→ 152), traffic-splitting rules.
- Telemetry — latency, error rate, call graph — is collected uniformly from every sidecar, giving one consistent view of the whole fleet without any service instrumenting itself.
- Application code calls other services exactly as it would without a mesh; the mesh is transparent — which is also why a misconfigured mesh is hard to notice until a call fails.
Practical example
(illustrative). Rolling out a new retry policy for 40 services used to mean 40 pull requests across 40 repositories, each in a different state of being deployed. With a mesh, the same policy is one control-plane change, applied to every sidecar within seconds, with no application redeploy.
When to use it
- Use when: the fleet is large enough (dozens of services) that keeping cross-cutting behavior consistent across many codebases has become its own maintenance burden.
- Avoid when: there are a handful of services — a mesh's control plane, sidecar overhead, and operational learning curve cost more than the inconsistency it would prevent; an API gateway (→ 41) at the edge plus a shared library per service covers most of the same ground.
- Failure scenarios: the control plane itself becomes a single point of failure for the entire fleet's networking; the added sidecar hop on every call adds latency that, multiplied across a long call chain, becomes significant; debugging now requires understanding both the application and the mesh layer.
- Simpler alternative: an API gateway (→ 41) for edge concerns plus a shared library or convention for service-to-service concerns, scaling the mesh in only when fleet size actually demands it.
Practice
(Decision kind — judge 3–5 scenarios and defend the choice; 15 min). For four fleets — (a) 3 services, one team; (b) 15 services, three teams, inconsistent retry logic already causing incidents; (c) 60 services, ten teams, every team using a different HTTP client library; (d) 3 services but a strict requirement for mutual TLS on every internal call — decide mesh or no mesh, and name the one fact that drove each decision.
Done when every "no mesh" decision names the simpler alternative that covers the same need, and every "mesh" decision names the specific inconsistency or scale problem it solves.
Key takeaway
A service mesh is sidecars fleet-wide plus one control plane — it buys fleet-wide consistency for security, resilience and telemetry, at the cost of a new infrastructure layer to run and understand. Done when you can: decide, for a stated fleet size and pain point, whether a mesh earns its cost. Used next in → 151 (circuit breaker), → 152 (retry and timeout) — mechanisms a mesh can also enforce at the proxy layer.
References
A pattern language for microservices — see references.md.
Source directory