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:

  1. Security: Controlling who can talk to whom (authentication and authorization).
  2. Client-side load balancing: Intelligently picking healthy upstream replicas.
  3. Target version/flavor selection: Routing to specific versions (v1, v2, v3) or environments (dev, stag, prod).
  4. Fault tolerance: Consistent timeouts and retries.
  5. Circuit breaking: Isolating failing services before they trigger cascading outages.
  6. 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

  1. A circuit breaker wraps calls to a target service in a dedicated monitor object.
  2. It tracks failures and slow responses. Once failures pass a configured threshold, the circuit breaker trips (opens).
  3. 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.
  4. 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 return 200 OK on /health in 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 to Service B. Instead of hitting one undifferentiated pool, Service A’s local service mesh sidecar consults the routing rules and splits traffic dynamically—sending 80% to Service B (v1, Prod) and 20% to Service 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:
    1. Code duplication & bloated services: Services cease to be truly “micro” and turn into mini-monoliths that are hard to maintain.
    2. Recompilation required: Updating a shared capability requires modifying and recompiling services individually.
    3. Inconsistent global behavior: Enforcing a uniform logging format or turning on detailed debugging across the whole infrastructure requires touching each service separately.
    4. 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, and Service A must call Service B to answer:
    1. (1) Client asks API gateway for Service A.
    2. (2) API gateway forwards the request to Service A.
    3. (3) Service A asks API gateway for Service B.
    4. (4) API gateway forwards the request to Service B.
    5. (5) Service B sends its answer back to API gateway.
    6. (6) API gateway forwards Service B’s answer to Service A.
    7. (7) Service A sends its final answer to API gateway.
    8. (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):
    1. (1a -> 1b) Client requests Service A → intercepted by Service A’s local proxy → delivered to Service A.
    2. (2a -> 2b -> 2c) Service A calls Service B → goes to Service A’s proxy → sent directly to Service B’s proxy → delivered to Service B. (Notice the Global Controller only pushes configuration arrows down to the two proxies; it is never in the request path.)
    3. (3a -> 3b -> 3c) Service B answers Service B’s proxy → Service A’s proxy → Service A.
    4. (4a -> 4b) Service A answers Service A’s proxy → Client.
Dimension#1 Embedded Libraries#2 Central API Gateway#3 Service Mesh
Where cross-cutting logic livesInside each service’s codeOne central proxy boxDistributed proxies beside services (or nodes)
Language-agnostic apps?No (separate libs per language)YesYes
Scales for East-West traffic?Yes, but painful to updateNo (central bottleneck, extra hops)Yes (direct proxy-to-proxy hops)
Global policy updatesHard (edit & recompile every service)Easy (centralized)Easy (Control Plane pushes config)
Best traffic fitTiny / homogeneous appsNorth-South edge trafficLarge-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

  1. Suppose InventoryService still responds 200 OK to Kubernetes’ /health probe in 2 ms, while its /reserve endpoint hangs for 25 seconds due to a locked database table. Why won’t Kubernetes stop CheckoutService from 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 from CheckoutService to InventoryService; once failures/timeouts hit a threshold, the breaker trips and immediately returns an error without calling InventoryService, preventing thread/connection exhaustion and cascading failure while triggering alerts or rerouting.
  2. Trace what happens to a request Client -> Service A -> Service B under 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 to B’s proxy (A -> Proxy A -> Proxy B -> B), while the global controller stays out of the data path and only pushes rules.
  3. 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).