Service Mesh vs API Gateway
What you'll learn: How service meshes and API gateways complement each other by managing traffic at different boundaries of your architecture.
Two Tools, Two Traffic Zones
After learning what a service mesh is, you might wonder: "Don't API gateways already handle traffic routing and security?" The key distinction lies in where each operates and what traffic they manage.
An API Gateway sits at the edge of your infrastructure, acting as the front door for external clients (browsers, mobile apps, third-party services). It handles:
- North-south traffic (entering/leaving your cluster)
- Authentication and rate limiting for external users
- Protocol translation (REST to internal services)
- Public-facing API management
A Service Mesh operates inside your cluster, managing communication between your own microservices. It handles:
- East-west traffic (service-to-service within the cluster)
- Mutual TLS between internal services
- Fine-grained routing, retries, and circuit breaking
- Internal observability and tracing
Analogy: Building Security
Think of an API gateway as your building's front desk: it checks IDs, manages visitor badges, and directs guests to the right floor. The service mesh is the internal badge system: it controls which employees can access which rooms, tracks movement between departments, and ensures secure communication within the building.
When You Need Both
Most production architectures use both:
- API Gateway handles the public internet → your cluster boundary
- Service Mesh handles your microservice → microservice interactions
They're complementary layers: the gateway protects and routes external traffic, while the mesh provides sophisticated internal traffic management you learned about in the previous lesson.
Key Takeaway: API gateways manage external (north-south) traffic at your cluster boundary, while service meshes manage internal (east-west) traffic between microservices—use both for complete traffic control.