Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to build reporting in Microservices Architecture? [closed]

While doing a POC around Microservices architecture; one of the challenges that I need to explain it that how to obtain reporting data from different services in an effecient way?

I would appreciate guiding me in the right direction.

like image 497
A. Ahmed Avatar asked Mar 21 '19 04:03

A. Ahmed


People also ask

How do you create a report in microservices?

There are four main techniques for handling reporting in a microservices architecture: the database pull model, HTTP pull model, batch pull model, and finally the event-based push model.

What is the main reason for reporting being a challenge with a microservice architecture?

The complexity of microservice design forces the developers to plan and act more carefully. The external API communication in microservice architecture leads to an increased risk of attacks. It can be challenging to switch between them in the development and deployment processes.

What is the best way to communicate between microservices?

The two commonly used protocols are HTTP request/response with resource APIs (when querying most of all), and lightweight asynchronous messaging when communicating updates across multiple microservices. These are explained in more detail in the following sections.


1 Answers

If the data spans over multiple microservices then it depends on the business use case. In my opinion there are couple of ways to do it

Approach 1 query microservices dbs (not a preferred approach)

If your microservices are not very load intensive then you may query the data from all the services databases at off peak time and insert records into your warehouse database. This is not preferred approach since you are still putting additional load to services but it's easier . Also the reporting data may not be in realtime.

Approach 2 Event sourcing/CQRS

This approach is very preferred since your write and read models are completely separate. In brief the way if works is events generated by your different microservices will also be updating your read models called materialized view. If you have requirement where your reporting data requires near real time data then this is the way to go forward. You can shape your reporting model as you like and you can create multiple reporting models using events. But this is complex approach and require application design accordingly. However the benefits are countless. You may want to reach more about Event Sourcing and CQRS if you are interested.

Approach 3 have read only replicas

If you are using cloud services you can create readonly replicas of your databases and can use them for reporting. this is widely accepted approach since you are not impacting transactional databases. but this may be expensive since you are paying for additional databases.

like image 159
Imran Arshad Avatar answered Jan 03 '23 14:01

Imran Arshad