This article delves into the critical challenge of API composition in service-based architectures, where data for a single user interface is distributed across multiple microservices. It explores various techniques and their associated trade-offs, including client-side composition, API gateways, Backends for Frontends (BFF), GraphQL, and edge composition, covering implications for latency, caching, availability, and team ownership.
Read original on ByteByteGoIn modern microservice architectures, presenting a unified view to users often requires combining data from several disparate services. This process, known as API composition, is fundamental for building responsive and efficient user interfaces. The core problem arises when a single UI element (e.g., a user profile with recent orders) needs data from multiple independent services, each owning its specific domain data.
When a frontend application interacts with multiple backend services directly, it faces the challenges of over-fetching (retrieving more data than needed) and under-fetching (requiring multiple round-trips for related data). The location where this composition occurs significantly impacts performance, resilience, and operational complexity.
Key System Design Considerations
Choosing an API composition technique involves trade-offs in latency, availability, caching efficiency, versioning across frontends, and team ownership. For instance, moving composition server-side often reduces total load time for clients on weak connections by replacing many expensive client-to-server trips with one expensive client-to-server trip and many cheap intra-datacenter trips. Availability needs careful consideration, especially when one of the aggregated services fails. Caching strategies also differ significantly based on the composition layer's location.