2

I'm trying to design an application that uses the microservices architecture. The service would have an api gateway, a user service and then a seperate service for each analytic source.

For example, lets say I had twitter analytics data and instagram analytics data. There would be a seperate microservice for twitter analytics data and instagram analytics data. These microservices would handle oauth for that service, storing data and pulling data. My question is this: how would I request data from one service, lets say the user service, and then based on data from the user service, make a request to the instagram service and twitter service to request analytics info for that user.

However what would happen if I had n amount of services that I needed to request to? Like let's say a user needs analytics data from facebook, instagram, twitter and tiktok. How would I handle making a seperate request to each and then combine into a single response for the client?

I was thinking of using an api gateway as I've read that you can support request fanning-out to multiple microservices. I'm exactly sure how to do that however I found this article from aws outlining the different strategies.

I've also read over this question that says "You should implement endpoints in the services to facilitate these two requests. If you're making n requests, you've done it wrong". So now I'm not even sure if I'm on the right track.

Am I approaching this the correct way?

1 Answer 1

4

I think the solution to the above problem will be the usage of CQRS design pattern.

The idea will be a single service that listens to the events in Twitter analytics and Instagram analytics and save those details in a database. Once the data is stored we can hit this service to get the required data.

Eventually we are introducing an intermediatory service which will listen to the events in those analytics services and save them to a database. Now we can avoid multiple api calls by making a single api call to this particular service which will give you the required details.

I think this might be of some help !!.

References : https://microservices.io/patterns/data/cqrs.html#:~:text=How%20to%20implement%20a%20query%20that%20retrieves%20data,published%20by%20the%20service%20that%20own%20the%20data. https://medium.com/design-microservices-architecture-with-patterns/cqrs-design-pattern-in-microservices-architectures-5d41e359768c

Sign up to request clarification or add additional context in comments.

4 Comments

thank you for the response. What happens if I have 20 services connected? Also woundn't that be a bottleneck if all read operations go to a single service?
Yeah you are right that single service will have the view db and which will have all the details from the 20 microservices. So basically your concrete classes inside the intermediate service will be responsible for the business logic and thus give you the required response.
And how would I sync the view db? I was thinking a message broker like rabbit mq would delivery an event to the CQRS service with the data which it would then insert into the view db. Is that a good approach?
Yeah you are right. Rabbit mq or Kafka might do the job.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.