API gateway
Give clients one entry without centralizing every business rule.
The problem and the pattern
A gateway can terminate TLS, route traffic, and apply shared request policies. Service-specific authorization and data invariants still belong in the owning service. Keep the gateway observable and redundant because its failure can affect many capabilities.
Follow the flow
Make it concrete
This excerpt isolates the concept. Connect it to the booking API as you work through the exercise.
Client → gateway
/bookings → booking service
/billing → billing service
Gateway: routing, TLS, limits
Services: resource authorization and domain rulesTrade-offs
- A gateway simplifies client entry points.
- It can become a bottleneck or a release dependency.
- Use clear timeouts and avoid gateway-specific domain logic.
When to avoid it
Avoid deploying a gateway when one small service and a reverse proxy already cover the requirements.
Your turn
A gateway validates the token. May the booking service trust a user-supplied tenant header?
Reveal a worked answer
No. Forward identity only through a trusted, validated boundary and still enforce tenant membership and resource permission in booking. Strip or replace spoofable identity headers at the gateway.