Search code examples
architecturemicroservicesapi-design

Best Practices for Handling Data collecting Microservices Architecture


I'm facing a design challenge that I'd like some guidance on. Our system consists of multiple services, including a Users service and a Books service.

The Books service holds information about various books, and the Users service manages user (author) information. One of the requirements is to display the most popular books along with their authors' details.

I am pondering over the best approach to aggregate this data:

Should the Books service directly call the Users service to fetch author details? This seems like it could create tight coupling between the services.

Or should the frontend be responsible for making separate calls to each service and then combine the data? This might increase the complexity on the client side

I am looking for best practices on how to handle such cross-service data aggregation in a microservices environment. How do others handle similar scenarios, and what are the trade-offs for each approach?

Any insights, experiences, or recommendations would be greatly appreciated!.

Currently I didn't implement anything, I want the best practice.


Solution

  • Generally this is actually easier to handle client-side. If the author service is down (or not scaling, etc), you can still show the list of most popular books. Also, you can do interesting things like cache author details longer in the client because they probably change very infrequently, whereas "most popular books" would expire regularly.

    You get a lot of resiliency in decoupling these services and having the UI talk to them independently. If this gets too complicated to manage in the front-end, consider a BFF pattern to simplify it for the UI consumers.