Service Mesh Motivation: Libraries, API Gateway, and Circuit Breaking
Why Kubernetes alone is not enough
Kubernetes is primarily a deployment and orchestration platform (see Container Orchestration and Kubernetes and Kubernetes Services Ingress and Reverse Proxy). Out of the box, its built-in networking features for connecting services are deliberately basic:
- DNS-based service discovery (resolving service names to ClusterIPs).
- Simple Layer 3/Layer 4 load balancing (distributing TCP/UDP packets across backend Pod IP addresses).
That works for basic connectivity, but it is not adequate for production service-to-service communication when an application grows into hundreds of live microservices.
From embedded libraries to an “evolving zoo” of microservices
In traditional monolithic applications, common cross-cutting utilities—creating/handling log files, parsing and creating JSON (marshalling/unmarshalling), or specific algorithms—lived inside embedded code libraries. Updating a library meant recompiling and redeploying the entire application.
In a microservices architecture (see Microservices Architecture and Libraries vs Services), each application delegates tasks to independent live microservices over network APIs. A microservice can evolve and be updated without recompiling its callers as long as the interface (API) stays stable. However, while older SOA (Service-Oriented Architecture) infrastructures were centrally designed upfront by architects, modern microservices are developer-driven:
- Evolution becomes “clone and evolve, the best will survive”—more chaotic, less homogeneous, and harder to track without a central architectural blueprint (which drives the need for a software catalog, noted in the slides as outside this deck’s scope).
- Production systems at companies like Amazon and Netflix form dense dependency graphs of hundreds or thousands of live service instances (see Microservices Costs Traffic and Eventual Consistency).
At this scale, developers and infrastructure operators face recurring service-to-service communication problems:
- Security: Controlling who can talk to whom (authentication and authorization).
- Client-side load balancing: Intelligently picking healthy upstream replicas.
- Target version/flavor selection: Routing to specific versions (
v1,v2,v3) or environments (dev,stag,prod). - Fault tolerance: Consistent timeouts and retries.
- Circuit breaking: Isolating failing services before they trigger cascading outages.
- Observability, monitoring, and tracing: Understanding what happens across distributed calls.
Circuit breaking
Problem and everyday analogy
If Service B becomes slow or unresponsive and Service A keeps sending requests and waiting for timeouts, Service A’s threads or connection pools fill up. Failures cascade backward through the call graph until the entire system collapses (cascading failure).
- Everyday analogy: Just like an electrical circuit breaker in a house trips to cut power to a faulty appliance before the wiring catches fire, a software circuit breaker cuts off calls to a failing service. (Limit of the analogy: a software circuit breaker does not merely sit dead until manually flipped—it is coupled with automated feedback such as alerts, restarting the faulty instance, or rerouting traffic to healthy replicas.)
Mechanism
- A circuit breaker wraps calls to a target service in a dedicated monitor object.
- It tracks failures and slow responses. Once failures pass a configured threshold, the circuit breaker trips (opens).
- While tripped, all further calls return an error immediately without attempting the protected network call, preventing wasted resources and giving the failing service breathing room to recover.
- Detection triggers feedback actions—at minimum an alert, or automated remediation such as restarting the faulty service or rerouting calls to a working instance.
Common confusion: Circuit Breaker vs. Kubernetes health check
A Kubernetes liveness/readiness probe typically checks a simple endpoint (e.g.,
GET /health). A struggling service may still return200 OKon/healthin milliseconds while taking 30 seconds or timing out on real, complex business requests. Because a circuit breaker monitors actual live traffic behavior (latency and error thresholds), it catches degradation that Kubernetes health monitors miss.
Dynamic request routing
Rather than hardcoding endpoints or duplicating deployments manually, dynamic request routing lets operators direct requests to specific service versions (v1, v2, v3) and environments (dev, stag, prod) via declarative rules.
- Worked example (PDF p. 9 / printed slide 10): A
Service A (v1, Prod)instance sends a request toService B. Instead of hitting one undifferentiated pool,Service A’s local service mesh sidecar consults the routing rules and splits traffic dynamically—sending 80% toService B (v1, Prod)and 20% toService B (v2, Stag)to test the new version safely.
Comparing three architectural solutions for common functions
Every microservice needs cross-cutting capabilities such as authentication, rate-limiting, logging, caching, monitoring, and security. The slides compare three ways to provide them:
Solution #1: Embed common features in each microservice
Every microservice embeds libraries for authentication, rate-limiting, logging, caching, and monitoring directly in its own codebase.
- Why this fails at scale:
- Code duplication & bloated services: Services cease to be truly “micro” and turn into mini-monoliths that are hard to maintain.
- Recompilation required: Updating a shared capability requires modifying and recompiling services individually.
- Inconsistent global behavior: Enforcing a uniform logging format or turning on detailed debugging across the whole infrastructure requires touching each service separately.
- Polyglot language barrier: Services written in different languages (Java, Python, Go, C++) require separate library implementations, making identical behavior across languages hard to guarantee.
Solution #2: Central API gateway
All interactions—both external client calls and internal service calls—are routed through a single central API gateway that enforces authentication, rate-limiting, caching, logging, monitoring, and security.
- Exact 8-hop interaction trace (PDF p. 14 / printed slide 15): Suppose a mobile client needs
Service A, andService Amust callService Bto answer:(1)Client asks API gateway forService A.(2)API gateway forwards the request toService A.(3)Service Aasks API gateway forService B.(4)API gateway forwards the request toService B.(5)Service Bsends its answer back to API gateway.(6)API gateway forwardsService B’s answer toService A.(7)Service Asends its final answer to API gateway.(8)API gateway returns the final answer to the Client.
- Tradeoffs: Centralized control is simple to manage for North-South traffic (external clients entering or leaving the cluster), but it does not scale for East-West (internal service-to-service) traffic. Every internal call bounces through the central gateway, turning it into a performance bottleneck and single point of congestion—and developers must update the gateway whenever any microservice is added or removed.
Solution #3: Dedicated Service Mesh layer
Instead of putting infrastructure logic inside application code (#1) or inside one central middleman (#2), a service mesh places a lightweight proxy beside every service (deployed either as a sidecar proxy per Pod/workload or a per-host proxy) and manages those proxies from a global controller (control plane).
- Analogy — Personal Assistants + an Office Manager: Imagine 200 specialists (microservices). Instead of each specialist learning encryption, retries, and phone directories (#1) or passing every single note through one front-desk clerk (#2), each specialist gets a personal assistant (local proxy) at their desk. One Office Manager (global controller) writes the rulebook and distributes it to the assistants, without ever touching the messages themselves. When Specialist A needs Specialist B, Assistant A calls Assistant B directly. (Limit of the analogy: unlike a human calling an assistant, the microservice is completely unaware its local proxy exists—the operating system intercepts traffic transparently.)
- Exact interaction trace (PDF p. 16 / printed slide 17):
(1a -> 1b)Client requestsService A→ intercepted byService A’s local proxy → delivered toService A.(2a -> 2b -> 2c)Service AcallsService B→ goes toService A’s proxy → sent directly toService B’s proxy → delivered toService B. (Notice the Global Controller only pushes configuration arrows down to the two proxies; it is never in the request path.)(3a -> 3b -> 3c)Service BanswersService B’s proxy →Service A’s proxy →Service A.(4a -> 4b)Service AanswersService A’s proxy → Client.
| Dimension | #1 Embedded Libraries | #2 Central API Gateway | #3 Service Mesh |
|---|---|---|---|
| Where cross-cutting logic lives | Inside each service’s code | One central proxy box | Distributed proxies beside services (or nodes) |
| Language-agnostic apps? | No (separate libs per language) | Yes | Yes |
| Scales for East-West traffic? | Yes, but painful to update | No (central bottleneck, extra hops) | Yes (direct proxy-to-proxy hops) |
| Global policy updates | Hard (edit & recompile every service) | Easy (centralized) | Easy (Control Plane pushes config) |
| Best traffic fit | Tiny / homogeneous apps | North-South edge traffic | Large-scale East-West microservices |
Common confusion: North-South vs. East-West traffic
An API Gateway and a Service Mesh are complementary, not mutually exclusive: API Gateways (or Istio
Gateways) handle North-South traffic entering/leaving the cluster, while a Service Mesh handles East-West communication among internal microservices.
Retrieval
- Suppose
InventoryServicestill responds200 OKto Kubernetes’/healthprobe in 2 ms, while its/reserveendpoint hangs for 25 seconds due to a locked database table. Why won’t Kubernetes stopCheckoutServicefrom hanging too, and how does a circuit breaker solve this?
Kubernetes’ health check only probes a simple URL (/health), which succeeds even when complex business requests stall. A circuit breaker wraps actual live calls fromCheckoutServicetoInventoryService; once failures/timeouts hit a threshold, the breaker trips and immediately returns an error without callingInventoryService, preventing thread/connection exhaustion and cascading failure while triggering alerts or rerouting. - Trace what happens to a request
Client -> Service A -> Service Bunder Solution #2 (central API Gateway) versus Solution #3 (Service Mesh), and explain why Solution #2 breaks down as microservices grow.
Under a central API Gateway, every hop traverses the gateway (Client -> GW -> A -> GW -> B -> GW -> A -> GW -> Client, 8 hops total), making the gateway an East-West bottleneck that must also be updated whenever services are added or removed. Under a Service Mesh,A’s proxy talks directly toB’s proxy (A -> Proxy A -> Proxy B -> B), while the global controller stays out of the data path and only pushes rules. - Why is embedding shared logging, auth, and retry libraries inside every microservice (Solution #1) especially problematic in a polyglot company?
Each service becomes bloated and must be recompiled whenever a library changes, turning microservices back into hard-to-maintain mini-monoliths. Worse, teams using different languages (e.g., Go, Java, Python) must maintain separate library implementations, making uniform behavior (such as identical log formats or retry policies) and cluster-wide runtime toggles (e.g., enabling debug logs) difficult.
Source: Lecture 13 - Service Mesh and Istio, PDF pages 2–16 (printed slides 3–17).