Tuesday, May 10, 2022

Pattern: API Composition


How to implement queries in a microservice architecture?


Implement a query by defining an API Composer, which invokes the services that own the data and performs an in-memory join of the results.

The following diagram illustrates how this pattern is implemented.

The diagram shows the following workflow:

  1. An API gateway serves the "/customer" API, which has an "Orders" microservice that tracks customer orders in an Aurora database.

  2. The "Support" microservice tracks customer support issues and stores them in an Amazon OpenSearch Service (successor to Amazon Elasticsearch Service) database.

  3. The "CustomerDetails" microservice maintains customer attributes (for example, address, phone number, or payment details) in a DynamoDB table.

  4. The “GetCustomer” Lambda function runs the APIs for these microservices and performs an in-memory join on the data before returning it to the requester. This helps easily retrieve customer information in one network call to the user-facing API, and keeps the interface very simple.

Resulting context

This pattern has the following benefits:

  • It is a simple way to query data in a microservice architecture
  • Some queries would result in inefficient, in-memory joins of large datasets.

This pattern has the following drawbacks:

You may also like

Kubernetes Microservices
Python AI/ML
Spring Framework Spring Boot
Core Java Java Coding Question
Maven AWS