In developing an e-commerce platform, you might see separate services for orders, payments, and logistics. To retrieve comprehensive order details, querying each of these services individually is necessary. API composition is the solution for this scenario, wherein a composer acts as an intermediary, streamlining communication between the client and the various microservices.
An API gateway functions as the central coordinator within an architecture, serving as the initial interface for user requests. It efficiently directs requests to the suitable services and consolidates the responses before relaying them back to the user. Well-known choices for API gateways include KrakenD and Kong, alongside managed options from providers like AWS, Google, and Microsoft.
When interacting with multiple services, API gateways have the option to process requests either sequentially or in parallel. Although parallel requests appear more efficient, they require substantial resources and are constrained by the available cores. Understanding the specific use cases is needed to determine the appropriate method for handling requests. There is no one-size-fits-all here.
API composition also improves user experience by minimizing the number of round trips between client and server. Instead of requiring multiple requests for various services, the client can consolidate these into a single request, leading to reduced latency and more efficient data utilization for the end user.
In complex systems, multi-level API composition is adopted where a composer interacts with multiple services. For instance, if an order service requires supplementary information from both the seller and inventory services, this interaction can complicate response times and impact performance, particularly in large-scale applications.
API composition is a simple implementation and serves as a centralized point of interaction for users. It effectively conceals the underlying complexity of multiple APIs, enhances security measures, and allows for the restructuring of responses in the composer layer, which can mitigate poor design choices.
While API composition offers numerous benefits, it also presents several drawbacks. Notably, it can result in increased memory consumption and potential service downtime, impacting overall availability. Additionally, ensuring transactional data consistency can be challenging, and the maintenance required for the composer can add to operational overhead. Under heavy load, API composition may also turn into a performance bottleneck.