Nimrodshn
Nimrodshn

Reputation: 971

Microservices: Filtering across different services

In my current project, we have two micro services with two different DB instances which both have tables that refer to the same underlying resource (albeit named differently), that is, the resources table in service A's DB is called foo while in service B's DB it is called bar.

Writes are sent using both services and each service is responsible of writing to the other service on update/write/delete (ignoring network / DB failures for now.)

Each service is responsible for different information on the resource and thus each table contains different columns containing different information of the same resource. For example: service A has attribute health_state while service B has attribute [and column] archived.

We would like to allow the user to filter by both services columns / attributes - i.e. GET /foo?search="health_state='unhealthy' and archived='false'". How would one go about doing that?

We had initially thought of having one micro service be the "frontend" to the other and support search in A for fields of both services. And then A would send the relevant search fields to B and join the results in A's DB. This is one option that might not scale well if the result set of B is massive, this is because A requires all the archived resources (in the example above) in order to do the join. In addition the search query might be very complicated to parse. If we do take this approach are there any suggestions on how to do that at scale?

Keep in mind porting our application to something like CQRS as mentioned here seems like a massive change (there are currently 10K+ rows in the corresponding DB's).

Appreciate you're responses!

Upvotes: 3

Views: 1727

Answers (1)

Jitesh Shivnani
Jitesh Shivnani

Reputation: 351

You could perhaps look at GraphQL. You can stitch the output of 2 different apps together to produce result. This is a pretty well known scalable solution and you can apply caching at graphql server as well to increase performance.

https://graphql.org/ is great starting point.

I would also suggest you relook at service design because filtering for the same resource should be typically done in the same service unless it is a channel service. If data can be accessed in near real time then indexing the data in elastic search and then retrieving is also another option.

Upvotes: -2

Related Questions