Problem
How to implement queries in a microservice architecture?
Solution
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:
-
An API gateway serves the "/customer" API, which has an "Orders" microservice that tracks customer orders in an Aurora database.
-
The "Support" microservice tracks customer support issues and stores them in an Amazon OpenSearch Service (successor to Amazon Elasticsearch Service) database.
-
The "CustomerDetails" microservice maintains customer attributes (for example, address, phone number, or payment details) in a DynamoDB table.
-
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: