Gateway Architecture: Unified vs BFF vs Hierarchical Topology
Unified Gateway
A single gateway serves all clients: web, mobile, third party APIs. Simple to operate and reason about. However, different clients have different needs. Mobile needs compressed responses and fewer fields. Web needs full data. Third party APIs need stable interfaces. A unified gateway either serves lowest common denominator or becomes complex accommodating all variations.
Backend for Frontend (BFF)
Each client type gets its own gateway optimized for its needs. Mobile BFF handles compression, field filtering, and offline support. Web BFF handles rich data and real time features. Each BFF team owns their gateway, enabling independent deployment and client specific optimization. The cost is multiple gateways to operate and potential code duplication across BFFs.
Hierarchical Gateway
Multiple gateway layers. An edge gateway handles TLS termination, DDoS protection, and geographic routing. Regional gateways handle authentication and rate limiting. Service specific gateways handle aggregation. Each layer has specific responsibilities. This adds latency (1-3ms per hop) but enables specialized optimization at each layer.
Choosing an Architecture
Start with unified gateway. Move to BFF when client teams repeatedly conflict over gateway changes or when mobile and web requirements diverge significantly. Add hierarchical layers when operating at global scale with regional compliance requirements or when you need edge caching and DDoS protection separate from business logic.
GraphQL as Alternative
GraphQL lets clients request exactly the fields they need, potentially replacing some aggregation and BFF functionality. The gateway exposes a GraphQL schema; clients query for specific data. This shifts complexity from gateway aggregation to query resolution. Works well for read heavy workloads with varied client data needs.