How do you request information from multiple microservices?

How do you request information from multiple microservices?

Summary

  1. Keep the local storage of all data needed to serve client requests.
  2. Maintain consistency of that storage by subscribing to changes from upstream microservices.
  3. Don’t call other microservices synchronously. Asynchronous calls (calls which are done in the background and where you don’t wait for a response) are OK.

What happens when you query multiple rows in a microservice?

If you’re joining multiple rows of data across microservices, you’ll run into the n+1 problem. The n+1 problem is where each row in the results leads to an additional query (in this case to another microservice). One solution for this is to add a bulk query API, so you can fetch the additional data for all the rows at once.

Do you need to be online to query other microservices?

Other microservices don’t need to be online to query their data (as long as the data is already replicated). The data integration with other services is separate from the implementation of the microservice API. As data access between microservices is done through data replication, these queries don’t need to be part of your remote (e.g. REST) API.

What kind of database do I need for microservices?

Other services might need a NoSQL database such as MongoDB, which is good at storing complex, unstructured data, or Neo4J, which is designed to efficiently store and query graph data. Use a (single) database that is shared by multiple services. Each service freely accesses data owned by other services using local ACID transactions.

How to implement a query that retrieves data from multiple services?

As a result, it is no longer straightforward to implement queries that join data from multiple services. Also, if you have applied the Event sourcing pattern then the data is no longer easily queried. How to implement a query that retrieves data from multiple services in a microservice architecture?