Resilience & Service PatternsAPI Gateway PatternsHard⏱️ ~3 min

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.

🎯 When To Use: Unified for simple systems with homogeneous clients. BFF when client teams need independence and have distinct requirements. Hierarchical for global scale with regional requirements.

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.

💡 Key Takeaways
Unified gateway is simple but forces lowest common denominator or complex client specific logic
BFF gives each client type its own optimized gateway, enabling independent deployment at cost of operational complexity
Start unified; move to BFF when client teams conflict over changes; add hierarchical layers for global scale
📌 Interview Tips
1Explain the evolution: start unified, split to BFF when mobile and web teams conflict, add edge layer for global scale
2Mention GraphQL as an alternative that lets clients specify exact fields needed, reducing BFF complexity
3Note hierarchical latency cost: 1-3ms per gateway hop, acceptable for the specialization benefits at scale
← Back to API Gateway Patterns Overview