SDSystem DesignConcepts to case studies
System DesignDSA
x
0/311
Part 1: Foundations
Part 2: APIs and Communication
Part 3: Caching
Part 4: Data and Storage
Part 5: Architecture
  • Service Discovery
  • API Gateway Pattern
  • Backend for Frontend (BFF)
  • Sidecar Pattern
  • Circuit Breaker
  • Bulkhead
  • Strangler Fig
  • Service Mesh
  • Database per Service
  • Timeouts and Deadlines
  • API Composition
  • Anti-Corruption Layer
  • Ambassador Pattern
  • Idempotent Consumer and Inbox Pattern
Part 6: Distributed Systems
Part 7: Advanced Data Topics
Part 8: Operations and Security
Part 9: Estimation and Interview Method
Part 10: Case Studies
System Design/Architecture/Microservices Patterns

Service Mesh

A layer of sidecar proxies that handles service-to-service traffic, security and metrics.

โฑ 14 min readAdvancedInterview FavouriteHas visualizer
SummaryConceptReal-Life ExampleWhy?Where?How It WorksStepsKey TermsPros & ConsMistakesReal WorldRead NextInterview Q&ACheat-Sheet

01Quick Summary

A service mesh is a layer that handles how services talk to each other. A small proxy sits next to every service and takes care of retries, timeouts, encryption and metrics, so the app code does not have to.

  • Each service gets a sidecar proxy. All traffic in and out of the service goes through it.
  • A control plane tells every proxy the rules: who may call whom, how many retries, where to send traffic.
  • You get security, reliability and visibility for every service call, in every language, without changing the code.

02Concept: What is it?

When you have many microservices, each one calls others over the network. Networks fail, so each call needs the same careful handling: a timeout, a retry, a circuit breaker, encryption, logging, and a way to find the other service. If every team writes this code in its own language and library, you get a lot of copies and a lot of mistakes.

A service mesh moves this work out of the app and into the infrastructure. The mesh has two parts:

  • Data plane: the proxies (for example Envoy) that sit beside each service and carry the real traffic.
  • Control plane: the brain (for example Istiod in Istio, or the Linkerd control plane) that holds the rules and the identities, and pushes settings to all proxies.

The app just calls payments as if it were a normal call. The local sidecar catches it, encrypts it, picks a healthy target, applies the timeout and retry rules, records metrics, and sends it on. The sidecar on the other side checks and decrypts it before passing it to the target service.

Data plane and control plane
๐Ÿง Control planerules, certificates, service list
โ‡ฃpushes config
Pod A
๐ŸงพOrders
๐Ÿ›ก๏ธSidecar
โ†”mTLS
Pod B
๐Ÿ›ก๏ธSidecar
๐Ÿ’ณPayments
The control plane sets the rules. The proxies in the data plane follow them for every call.
๐Ÿง The app stays simple
The service talks only to its own sidecar on the same machine. The sidecar does the hard network work. That is why one mesh can serve services written in Java, Go, Python and Node alike.

03Real-Life Example

๐ŸตA Phone Company for Your Services
Imagine a big office where 200 people need to call each other. Instead of every person learning how to dial, record, and keep calls private, each desk gets a personal assistant. When you say "call Sam", your assistant looks up Sam, dials, retries if the line is busy, speaks in a secret code only Sam's assistant understands, and writes down how long the call took. A manager upstairs sets the rules for all assistants: who may call whom, how often to retry, and when to send calls to the new phone line. You just talk.
The office
Service mesh
Each person at a desk
A service
The personal assistant
The sidecar proxy
Phone lines between assistants
Service-to-service network calls
The secret code between assistants
mTLS (encrypted, identity-checked traffic)
Trying a busy line again
Retries and timeouts
The manager upstairs with the rule book
The control plane
A call log kept by every assistant
Metrics, logs and traces for every call
One call, step by step
๐ŸงพOrders appcalls payments
โ†’โ†“
๐Ÿ›ก๏ธSidecar Afind, encrypt, retry
โ†’โ†“mTLS
๐Ÿ›ก๏ธSidecar Bcheck, decrypt
โ†’โ†“
๐Ÿ’ณPayments app

04Why Do We Need It?

๐Ÿ”’Zero-trust security
Every call is encrypted and both sides prove who they are. Rules say which service may call which.
๐Ÿ”Reliability for free
Timeouts, retries, and circuit breaking are set once in config and apply to every service.
๐Ÿ‘๏ธVisibility
Every call gives request counts, error rates, latency and trace data without code changes.
๐ŸšฆTraffic control
Canary releases, A/B tests and gradual rollouts by changing a percentage.
๐ŸŒOne way for all languages
No need to keep a client library in sync in every language and team.
๐ŸงชFault testing
Inject delays and errors on purpose to see how the system copes.
When many services talk to many services, a mesh gives every call the same security, reliability and visibility, outside the app code.

05Where Do We Use It?

โ˜ธ๏ธKubernetes clusters
The most common home. Istio, Linkerd and Cilium Service Mesh run well there.
๐ŸงฉLarge microservice systems
Dozens or hundreds of services, many teams and many languages.
๐ŸฆRegulated industries
When every internal call must be encrypted and every access must be auditable (banks, health).
๐ŸšขGradual releases
Teams that ship canary or blue-green releases often use mesh traffic rules.
๐ŸŒMulti-cluster and multi-cloud
Connect services across clusters or regions with one set of rules.
โ˜๏ธManaged meshes
Cloud products such as AWS App Mesh, Google Cloud Service Mesh and Azureโ€™s Istio add-on run the control plane for you.

06Types / Parts / How It Works

The two planes

PartJobExamples
Data planeCarry real requests. Encrypt, route, retry, time out, and record metrics.Envoy proxy, Linkerd2-proxy
Control planeHold the rules and identities. Hand out certificates. Push config to every proxy.Istiod (Istio), Linkerd control plane, Consul

What the mesh can do

Traffic managementRouting, canary, retries, timeouts, circuit breaking, load balancing
SecuritymTLS, service identity, who-can-call-whom policies
ObservabilityMetrics, logs and distributed traces for every call
DiscoveryFind healthy instances of the service you want to call

Where the proxy lives

Sidecar model and sidecar-free model
Sidecar per pod
๐ŸงพApp
๐Ÿ›ก๏ธProxy
๐Ÿ’ณApp
๐Ÿ›ก๏ธProxy
Shared per node (ambient style)
๐ŸงพApp
๐Ÿ’ณApp
โ†“
๐Ÿ›ก๏ธNode proxyshared
Newer designs try to cut the cost of one proxy per service.
ModelHow it worksGood and bad
Sidecar proxyOne proxy container beside each service instanceStrong isolation per service. Uses CPU and memory for every pod, and adds two hops.
Node or ambient proxyA shared proxy per node (and optional per-namespace proxies), as in Istio ambient mode or CiliumLess resource use, simpler upgrades. A newer design with different trade-offs.
Proxyless (library based)gRPC or another library gets rules from the control plane, with no proxyLowest latency. Works only for supported languages.
VisualizerWith and without a mesh: retries, canary and mTLSRaise the failure rate of Payments and compare no mesh with the mesh. Add retries and watch failures drop and the call count rise. Move the canary slider to split traffic to a new version.
How do the services talk?
๐Ÿงพ
Orders
plain textโŸท
๐Ÿ’ณ
Payments
30% of calls fail
Orders calls Payments directly. Any retry, timeout or encryption must be coded inside each app.
The 100 calls (green = worked, amber = worked after a retry, red = failed)
Successful
70%
30 failed
Calls to Payments
100
0 extra from retries
Avg time per request
20 ms
one direct call
Canary to v2
n/a
needs a mesh or gateway
Traffic
๐Ÿ‘€
can be read or faked
Without a mesh, each failed call is a failed order unless every team wrote its own retry code. 30 of 100 requests failed. Switch to Service mesh to let the sidecars handle it.

A simplified, deterministic model (no random numbers). A call takes 20 ms, each sidecar pair adds about 2 ms, and every retry waits 10 ms. Real meshes also add timeouts, circuit breaking and rich metrics.

07How to Use It / Steps / Implementation

Adopting a service mesh

  1. 1
    Ask if you need one
    A mesh pays off with many services, many teams or strict security rules. For a handful of services, a library plus a gateway is often simpler.
  2. 2
    Pick a mesh
    Istio (many features), Linkerd (small and simple), Consul (works beyond Kubernetes), or Cilium (eBPF based). Check the support for your platform.
  3. 3
    Install the control plane
    Deploy it first, in a test cluster. Learn its settings and how it upgrades before touching production.
  4. 4
    Add a few services
    Enable the sidecar (often by labelling a namespace) for one or two non-critical services. Check that traffic still works.
  5. 5
    Turn on mTLS in permissive mode
    Allow both plain and encrypted traffic at first. Once every service has a proxy, switch to strict mode.
  6. 6
    Set sensible defaults
    Timeouts, a small number of retries with back-off, and circuit-breaking limits. Retry only safe (idempotent) calls.
  7. 7
    Use the dashboards
    Look at golden signals per service: request rate, errors, latency. This is often the first win.
  8. 8
    Roll out slowly
    Add more namespaces step by step, and plan upgrades for the mesh like any other critical system.
๐Ÿ’กRetries need idempotent calls
A retry can run a request twice. Only retry calls that are safe to repeat (reads, or writes with an idempotency key), or you may charge a customer two times.
โš ๏ธKeep retry budgets small
Three layers each retrying three times can create 27 calls from one request. Limit retries in one place, and use timeouts and back-off, so retries do not overload a service that is already struggling.

08Key Terms to Know

TermMeaning in easy words
Service meshAn infrastructure layer that manages and secures service-to-service calls
Data planeThe proxies that carry the real traffic
Control planeThe part that stores rules and identities and configures the proxies
SidecarA helper container that runs next to the app and handles its network traffic
EnvoyA popular open-source proxy used as the data plane in Istio and others
mTLSMutual TLS: both sides present certificates, so each side knows who the other is
East-west trafficCalls between services inside your system (the opposite of north-south, from outside users)
Traffic shifting / canarySending a chosen percentage of requests to a new version
Circuit breakingStop calling a failing service for a while, so it can recover
ObservabilityBeing able to see what the system does, through metrics, logs and traces
Service identityA cryptographic name (certificate) that proves which service is calling

09Pros, Cons and Trade-offs

โœ… Pros
  • Encryption and identity for all calls
  • Retries, timeouts and circuit breaking without app code
  • Metrics and traces for every call
  • Works for any language
  • Safe, gradual rollouts with traffic splitting
โš ๏ธ Cons
  • Extra CPU and memory for the proxies
  • A little added latency on every call
  • Complex to learn, run and upgrade
  • A hard-to-debug extra layer in the request path
  • Can be too much for small systems

Trade-offs

ChoiceWe gainWe lose
Service meshUniform security, reliability and visibilityExtra layer, resources and operations work
Libraries in each appNo extra proxy, lowest latencyA copy per language and a lot of upgrade work
Sidecar modelStrong isolation and many featuresResource cost per pod, and two extra hops per call
Ambient / node proxyLess overhead, easier adoptionA newer design with fewer years of use
Strict mTLSStrong securityEvery client must join the mesh or be handled as an exception
Many retriesMore calls succeedMore load on a struggling service, and a risk of duplicates

10Common Problems and Mistakes

Common mistakes

  1. Adopting a mesh too early. With five services the cost is often higher than the gain.
  2. Stacking retries. App, sidecar and gateway each retry, and one failure turns into a flood (a retry storm).
  3. Retrying unsafe calls. Non-idempotent writes may run twice.
  4. Ignoring the resource cost. Hundreds of sidecars use real memory and CPU. Set resource limits.
  5. Skipping the permissive phase. Switching to strict mTLS at once can break services that are not in the mesh yet.
  6. Treating the control plane as unimportant. If it is down, existing proxies keep working with old config, but nothing new can change. Run it in a highly available way.
  7. No upgrade plan. Proxies and the control plane need regular updates for security fixes.

Things to watch

๐ŸขLatency
Each sidecar adds a small delay, often a few milliseconds. Measure it for chatty call chains.
๐ŸงฉDebugging
A failure can come from the app, the proxy or the policy. Learn the proxy logs and dashboards.
๐Ÿ“ˆConfig sprawl
Hundreds of rules become hard to reason about. Keep them in Git and review changes.
๐Ÿ”Certificate expiry
mTLS depends on short-lived certificates that the control plane rotates. Watch that rotation.

11Real-World Examples

๐ŸšขIstio
Started by Google, IBM and Lyft. Uses Envoy proxies and a rich control plane. Very feature rich.
๐ŸชถLinkerd
A CNCF project known for being light and simple, with its own small Rust proxy.
๐ŸงญEnvoy
Created at Lyft and now a CNCF project. It is the proxy inside many meshes and gateways.
๐ŸCilium
Uses eBPF in the Linux kernel to give mesh features with little or no sidecar.
๐Ÿ”—Consul
From HashiCorp. A mesh that can span Kubernetes, virtual machines and several data centres.
โ˜๏ธCloud meshes
Managed offerings from the big clouds run the control plane for you.
๐Ÿ“Note
Products and their features change quickly. Check the current docs of any mesh before you choose it.
Mini case: safe release of Payments v2
๐ŸงพOrders
โ†’โ†“
๐Ÿ›ก๏ธSidecartraffic rule
โ†’โ†“90%
๐Ÿ’ณPayments v1
โ†“10%
๐Ÿ†•Payments v2canary
Mesh proxy Stable version Canary version
The mesh sends 10% of calls to the new version. If errors rise, the rule goes back to 0%.

12Related Topics to Read Next

Microservicesโ†’

The setting where a mesh makes sense.

Sidecar Patternโ†’

The way each mesh proxy is attached to its service.

Circuit Breakerโ†’

A mesh can apply circuit breaking to every call.

Service Discoveryโ†’

Proxies need to find healthy instances to call.

API Gateway Patternโ†’

A gateway handles traffic from outside, a mesh handles calls between services.

Idempotencyโ†’

Retries are safe only when a call can be repeated.

13Interview Questions with Short Answers

14Quick Revision Cheat-Sheet

  • โœ”What: a layer that manages service-to-service calls using a proxy beside each service.
  • โœ”Planes: data plane = proxies (Envoy). Control plane = rules, certificates, config (Istiod).
  • โœ”Gives: mTLS, retries, timeouts, circuit breaking, canary routing, metrics and traces.
  • โœ”Traffic: east-west (service to service). A gateway handles north-south (users to services).
  • โœ”Cost: extra CPU, memory and a few ms per call, plus operations work.
  • โœ”Careful: retry only idempotent calls, and keep retry budgets small.
  • โœ”Tools: Istio, Linkerd, Consul, Cilium, managed cloud meshes.
  • โœ”One line: โ€œMove the hard parts of networking out of the app and into a shared proxy layer.โ€
โ† Previous
Strangler Fig
Next โ†’
Database per Service