Course contents

11. Microservices Lesson 10 of 10

Service Mesh

See sidecar proxies carry every call with mTLS, retries and telemetry, how the control plane configures them, and what each extra hop costs.

15 minAdvanced9 steps
Loading the interactive simulation…
Loading the knowledge check…

Summary

  • Without a mesh, every service re-implements retries, TLS and telemetry in its own language and library.
  • A mesh puts a proxy beside every workload (the data plane); a control plane pushes config and certificates and is not on the request path.
  • Proxies give mutual TLS with workload identities, retries, timeouts, balancing and ejection, and the same metrics for every service.
  • A control-plane outage freezes configuration; traffic keeps flowing with the last known config.
  • Every call pays extra proxy hops, and every pod pays for its proxy; sidecarless and proxyless modes reduce that cost.
Deep diveHow it works, trade-offs, failure modes, misconceptions and the interview angle.

What it is

A service mesh is an infrastructure layer that handles service-to-service communication. A proxy runs next to every workload (classically as a sidecar container in each pod) and intercepts its inbound and outbound traffic. Together these proxies form the data plane. A control plane configures them: routes, endpoints, policies and the certificates that give each workload an identity. Istio (with Envoy) and Linkerd are the best-known implementations.

Why it exists

Once a system has dozens of services, every one of them needs the same networking features: timeouts, retries, load balancing, encryption and authentication between services, and metrics and traces. Built into each application, these get re-implemented per language and per library version, configured differently, and changed only by redeploying. A mesh moves them into infrastructure that is configured centrally and behaves the same for every service.

How it works

  1. Interception. The application sends a plain request to its destination; traffic is redirected (iptables rules or an eBPF/CNI equivalent) to the local proxy. Applications usually need no code change.
  2. Outbound proxy. The caller's proxy resolves the destination service to its current endpoints (pushed by the control plane), picks one with its balancing algorithm (round robin, least requests, consistent hash), applies timeouts and retries, and opens or reuses a connection.
  3. Mutual TLS. Between pods, the two proxies authenticate each other with certificates issued by the mesh's certificate authority, typically carrying a SPIFFE identity derived from the workload's service account. Authorization policies can then allow "Web may call Cart" by identity rather than IP. Connections are reused, so the handshake is per connection, not per request.
  4. Inbound proxy. The callee's proxy terminates TLS, enforces policy, records metrics and passes the request to the application over localhost.
  5. Control plane. It watches the cluster (services, endpoints, policy resources), computes each proxy's configuration and streams it (xDS for Envoy). It also rotates short-lived certificates. It is never on the request path, so a short outage freezes configuration but does not stop traffic.
  6. Failure handling. Proxies eject endpoints that fail (outlier detection on consecutive errors, plus Kubernetes readiness removing pods from endpoint lists) and can retry failed calls on another endpoint.
  7. Telemetry. Every proxy emits the same metrics per caller and callee and can create trace spans. To join spans into one trace, applications must forward trace context headers such as traceparent.

When to use it

  • Many services in several languages that need consistent retries, timeouts, encryption and telemetry.
  • Zero-trust requirements: encrypt and authenticate all service-to-service traffic with workload identities and policies.
  • Traffic management without redeploying: canary releases by weight, header-based routing, fault injection for testing.

When not to

  • A handful of services in one language: a shared client library or framework middleware is cheaper and simpler.
  • Latency-critical paths with very deep call graphs, where per-hop overhead adds up, unless a lighter data plane is used.
  • Teams without capacity to operate and upgrade another distributed system; a misconfigured mesh can take down all traffic at once.

Trade-offs

Choice You gain You pay
Sidecar mesh Uniform features, no code changes, per-workload policy A proxy per pod (CPU, memory), two extra hops per call, injection and upgrade complexity
Sidecarless (e.g. Istio ambient) mTLS and L4 with a per-node proxy; L7 proxies only where needed Newer model; shared per-node proxy; L7 features need extra waypoint proxies
Proxyless gRPC No extra hop; clients take mesh config (xDS) directly gRPC only; features limited to what the client library supports
Libraries instead of a mesh Lowest overhead, full control Per-language implementations that drift; changes need redeploys

Alternatives

  • Client libraries and middleware for retries, timeouts and metrics, with TLS from a platform or ingress.
  • API gateway for north-south traffic (clients into the system); a mesh is mainly east-west (service to service).
  • eBPF-based networking (e.g. Cilium) for L3/L4 policy, encryption and observability in the kernel, sometimes with an L7 proxy per node.
  • Platform-managed networking in a managed container service that provides mTLS and service discovery.

Failure modes

  • Bad configuration pushed everywhere: a wrong route or policy reaches every proxy within seconds. Roll out config changes gradually and validate them.
  • Retry storms: retries at the mesh and in the application multiply load; use retry budgets and one retry layer.
  • Control-plane outage: no new endpoints or certificates; a long one leads to stale routing and expiring certificates.
  • Proxy resource limits: an under-provisioned sidecar becomes the bottleneck or is OOM-killed with its pod.
  • Startup and shutdown ordering: the app starts sending before its proxy is ready, or the proxy exits before in-flight requests finish.
  • Broken traces: applications that do not forward trace headers produce disconnected spans.

In production

Start with mTLS in permissive mode, then enforce it namespace by namespace. Set timeouts and retries per route, with retry budgets. Size proxies with resource requests and monitor their CPU and memory. Run the control plane highly available and upgrade it with canary revisions. Use the mesh's golden-signal metrics for SLOs per service, and make trace-context forwarding part of every service template. Measure the latency overhead on your own call graph rather than relying on published numbers.

Common misconceptions

  • "The control plane routes the traffic." Only the proxies carry requests; the control plane configures them.
  • "A mesh gives distributed tracing for free." It gives spans; applications still forward trace headers.
  • "Mesh retries make every call reliable." They are safe only for idempotent calls and can amplify overload.
  • "A mesh is required for microservices." It is one way to get consistent networking; libraries or platform features may be enough.

Interview angle

Bring up a mesh when the design has many services and needs consistent security and observability, and explain the split: sidecar proxies in the data plane, a control plane distributing configuration and certificates. Name the features (mTLS identities, retries, timeouts, outlier detection, telemetry), then the costs: per-hop latency, a proxy per pod, operational complexity. Mentioning that control-plane outages freeze configuration rather than stop traffic, and that sidecarless or proxyless modes exist, shows depth.

Model assumptions

Parts of this lesson are simulated and parts are scripted. Simulated by the queueing engine: users sending 150 requests per second to Web (5 ms of work), which calls two Cart pods (8 workers, 40 ms each). Without a mesh, a Kubernetes Service is modelled as an L4 balancer picking a pod at random. With a mesh, Web's sidecar is modelled as a balancer with 1 ms of processing and active health checks every 300 ms (two failures to eject), standing in for outlier detection, and each Cart pod's sidecar as a small server with 1 ms of work; in-pod hops take 0.5 ms and pod-to-pod hops 1 ms. The engine applies proxy processing on the request direction only. Scripted (hand-placed packets): control-plane configuration and certificate pushes, the TLS 1.3 handshake between sidecars, a sidecar retrying on the other pod, and telemetry export. The engine does not model TLS, configuration, proxy retries or telemetry. Numbers show behaviour and orders of magnitude, not benchmarks.

The lesson as textEvery step of the simulation, written out.
  1. 1. Every service solves networking itself

    Users send 150 requests per second to Web, which calls the Cart service. Cart runs as two pods behind a Kubernetes Service, an L4 balancer that picks a pod per connection; here, per request, at random.

    It works, but everything beyond “deliver the bytes” lives in application code: timeouts, retries, TLS between services, metrics and tracing. With services written in Go, Java and Python, each team re-implements those with its own library, and they drift apart.

    Scene: Users call Web, which calls the Cart service through a Kubernetes Service that spreads requests over two Cart pods. Requests succeed.

    Key idea: Without a mesh, retries, encryption and telemetry are re-implemented in every service and language.

  2. 2. A proxy next to every service

    A service mesh moves that logic out of the application into a sidecar proxy (typically Envoy) in every pod. Web sends a plain request to localhost; its sidecar picks a Cart pod, and the Cart pod’s own sidecar receives it and hands it to Cart. Applications are unchanged.

    The cost is visible in the metrics: every call now passes two extra proxies, and the average latency rises by about 2 ms in this model (1 ms of work in each proxy). It sounds small, but it is paid on every hop: a request that crosses five services pays it five times. Sidecars also cost CPU and memory in every pod.

    Scene: Each pod now has a sidecar proxy. Web’s requests go to its local sidecar, across to a Cart pod’s sidecar, and from there to Cart. Everything works; the average latency is about 2 milliseconds higher.

    Key idea: The data plane is a proxy beside every service; it adds a little latency to every call, on every hop.

  3. 3. The control plane configures the proxies

    Thousands of proxies need routes, endpoints, policies and certificates. The control plane (e.g. Istio’s istiod, Linkerd’s control plane) watches the cluster and pushes configuration to every sidecar over a streaming API (xDS for Envoy), and issues each workload a short-lived certificate for its identity.

    Crucially, it is not on the request path: the request packets still flow only through the data plane. The packets from the control plane are configuration updates. *Scripted illustration on top of the simulated traffic.*

    Scene: A control plane sends configuration and certificates to all three sidecars. User requests keep flowing through the sidecars only, never through the control plane.

    Key idea: Control plane: decides and distributes config and certificates. Data plane: the proxies that carry every request.

  4. 4. The control plane goes down

    The control plane fails. Requests keep flowing, with no errors: each proxy keeps the last configuration and certificates it received.

    What stops is change: new pods are not added to the proxies’ endpoint lists, policy updates do not arrive, and certificates are not renewed. A long control-plane outage eventually hurts (expired certificates, stale endpoints), so it is run highly available, but a short one is invisible to users.

    Scene: The control plane is offline. The sidecars keep routing requests with their last configuration and nothing fails.

    Key idea: A control-plane outage freezes configuration; the data plane keeps serving with what it has.

  5. 5. Mutual TLS between proxies

    The control plane is back. Between pods, the sidecars speak mutual TLS: both sides present a certificate, so Cart knows the caller *is* Web (an identity such as spiffe://cluster.local/ns/shop/sa/web), not just some IP address. Authorization policies can then say “only Web may call Cart”.

    With TLS 1.3 the handshake takes one round trip: ClientHello; the server’s certificate and Finished, with a request for the client’s certificate; then the client’s certificate and Finished, immediately followed by the encrypted request. Connections are reused, so the handshake is paid per connection, not per request. The hop inside each pod stays plain localhost traffic. *Scripted illustration.*

    Scene: Web’s request goes to its sidecar in plain text. The Web sidecar and Cart A’s sidecar exchange a TLS 1.3 handshake with certificates on both sides, then the encrypted request crosses, and Cart A’s sidecar passes it to Cart A over localhost. The answer returns the same way.

    Key idea: Sidecars give every service an identity and encrypt traffic between pods, without application changes.

  6. 6. A pod crashes; the proxy ejects it

    Traffic is back. One second in, pod B crashes (Cart and its sidecar). For a moment Web’s sidecar still sends it half the requests, and those fail.

    Then the sidecar’s health checks notice two failures in a row and eject pod B: from then on every request goes to pod A and the errors stop. In a real mesh the proxy also ejects endpoints that keep returning errors (outlier detection), and Kubernetes removes the pod from the endpoint list the control plane pushes.

    Scene: Cart pod B crashes. Requests sent to it fail for a short time until Web’s sidecar ejects it; afterwards all requests go to pod A and succeed.

    Key idea: The data plane removes bad endpoints quickly; the errors you see are the detection window.

  7. 7. The proxy retries on the other pod

    Pod B is back. The mesh can also retry for the application, configured once in a routing rule. Here pod B answers 503; Web’s sidecar retries the call on pod A, which succeeds, and Web never sees the failure.

    Retries belong only on idempotent calls (GET, or requests with an idempotency key), with a small attempt limit and a retry budget; otherwise every layer of retries multiplies load on a struggling service. *Scripted illustration.*

    Scene: Web’s request goes to pod B, which answers with an error. Web’s sidecar retries on pod A, which succeeds, and only the successful answer reaches Web.

    Key idea: Mesh retries are configuration, not code; keep them for idempotent calls and bound them.

  8. 8. Uniform telemetry from every proxy

    Because every request crosses a proxy, the mesh reports the same golden signals for every service, whatever its language: request rate, error rate and latency per caller and callee. Each sidecar exports metrics, and spans for distributed traces, to the telemetry backend; the applications send nothing.

    One catch: proxies cannot connect spans across a service on their own. The application must forward the trace headers (traceparent) from the incoming request to its outgoing calls, or each hop shows up as a separate trace. *Scripted telemetry packets on top of the simulated traffic.*

    Scene: User requests flow through the sidecars, and each sidecar periodically sends metrics and trace spans to the telemetry backend. The applications send no telemetry themselves.

    Key idea: Proxies give consistent metrics and spans for free; tracing still needs apps to propagate headers.

  9. 9. What a mesh costs and buys

    A mesh buys uniform traffic management (retries, timeouts, balancing, ejection), security (mTLS identities, authorization policies) and telemetry for every service, configured centrally instead of coded per language.

    It costs a proxy per pod (CPU, memory), a few milliseconds per hop, a control plane to run and upgrade, and a new layer to debug. Newer data planes reduce the cost: sidecarless modes such as Istio ambient (a per-node proxy for mTLS, optional L7 proxies per service) and proxyless gRPC clients that take mesh configuration directly. A mesh pays off with many services and languages; with a handful, a good client library may be enough.

    Scene: Users call Web; sidecars carry every call to the two Cart pods with mTLS, a control plane configures them, and they report telemetry. Everything is healthy.

    Key idea: A mesh moves networking concerns from code to infrastructure, at a per-hop and operational cost.