Dashboard
Courses
Problems
Badges
Theme
Sign inStart free
Courses/Distributed Architecture
Lesson 3 of 24

API gateways and service mesh

Centralise cross-cutting concerns at the edge with a gateway and between services with a mesh.

18 min read

The API gateway: one front door

With 40 services you do not want every client to know 40 hostnames, or every service to reimplement authentication. An API gateway is the single entry point for north-south traffic (clients to your system). It terminates TLS, authenticates tokens, applies rate limits and quotas, routes by path or header to the right service, and emits uniform access logs and metrics. It can also aggregate several backend calls into one response for a mobile client (the backend-for-frontend pattern).

  • Keep it thin: routing and policy, not business logic
  • Run it stateless and horizontally scaled behind a load balancer
  • Store rate-limit counters in a shared cache so limits hold across instances

The gateway as a dependency

Every request now passes through the gateway, so it adds latency (typically 1 to 5 ms) and is a potential single point of failure. Run it across availability zones with enough headroom to absorb the largest expected spike. Cache token validation: verifying a JWT signature locally takes microseconds, while calling an auth service per request adds a hop and couples your availability to it. Validate locally, and fetch signing keys periodically. Keep short token lifetimes, such as 15 minutes, so revocation does not need a per-request check.

Service mesh: east-west traffic

Inside the system, services call each other (east-west traffic). A service mesh such as Istio or Linkerd puts a sidecar proxy next to every instance. The sidecars handle mutual TLS, retries with budgets, timeouts, circuit breaking, load balancing and per-call telemetry, configured centrally rather than in each codebase. The cost is an extra proxy hop on each side of every call, roughly a millisecond or less, plus memory and CPU for thousands of sidecars and a control plane to operate.

Retries can take you down

If three layers each retry three times, one failing call becomes 27 attempts at the bottom layer, exactly when it is already struggling. Retry at one layer only, with exponential backoff and jitter, and cap retries to a budget such as 10% of requests. Set timeouts that shrink as you go deeper, so the caller does not give up while the callee keeps working. In SystCode, place an api_gateway in front of your services and watch the Feedback panel attribute rejected requests to the rate limit rather than to overloaded backends.

Key takeaways

  • A gateway centralises auth, rate limiting, routing and observability for client traffic
  • A mesh does the same for service-to-service calls via sidecars, at the cost of an extra hop
  • Retry at one layer with backoff, jitter and a budget to avoid retry storms
  • The gateway is on every request path: scale it and spread it across zones

Sign in to track lessons and earn badges.

Monolith vs microservicesData modelling for scale

Challenge checkpoint

Course: 0/24 lessons · 0/10 challenges0%

Build it on the canvas, pass the review (70+) and mark it complete to count it toward the course badge.

  1. 2/10Design an API Gateway PlatformCentralise authentication, routing, rate limiting and observability for 40 services without making the gateway a bottleneck.Medium
All 10 challenges →