Networking & Traffic Management

API Gateways & Service Discovery

A gateway centralizes cross-cutting concerns (auth, rate limiting, routing) at the edge of a microservices system, while service discovery lets services find each other as instances come and go.
  • API gateway: a single entry point handling auth, rate limiting (Rate Limiting Algorithms), request routing, and protocol translation, so individual services do not each reimplement them
  • Service discovery, client-side: the caller queries a registry directly and picks an instance itself (e.g. Netflix Eureka-style) — no extra hop, but couples every client to the registry
  • Service discovery, server-side: a load balancer or gateway queries the registry on the caller's behalf (e.g. via a sidecar or DNS-based discovery) — simpler clients, one more hop
  • The registry itself needs heartbeats/health checks — a stale entry pointing at a dead instance is worse than no entry at all
  • A gateway becomes a chokepoint exactly like a load balancer: it needs its own redundancy, and every request now pays its added latency, which should be measured, not assumed away
Server-side discovery through a gateway
The gateway looks up healthy instances in the registry on every request (or via a cached, periodically refreshed view of it)
Client-side vs server-side discovery
Client-sideServer-side
Who queries the registryThe calling service itselfA gateway or load balancer
Extra network hopNoYes
Client complexityHigher — needs discovery-aware client libraryLower — client just calls one address
CouplingClients coupled to registry APIClients decoupled; gateway coupled instead
Sources
  • System Design Interview – An Insider's Guide, Volume 2Ch. 1 — API Gateway
  • Designing Distributed Systems (2nd ed.)Ch. 6 — Ambassadors (service discovery patterns)