How to Build a Scalable Reporting Service in a Microservice Architecture
To generate a user‑enriched order report in a microservice system, the article compares four approaches—direct DB access, REST data aggregation, batch pulling, and an event‑driven model—highlighting their trade‑offs in coupling, performance, scalability, and resilience, and recommends the event‑push solution.
Scenario Description
In a microservice architecture each service owns its own database, and Service A is not allowed to directly connect to Service B’s database.
There are two services: an order service and a user service.
The reporting requirement is to generate an order report that includes user information, which means data must be fetched from both services and joined.
Solution 1: Direct Database Connection
Connect directly to the order and user service databases, retrieve the needed data, and process it.
This is simple but breaks the microservice principle of isolation, and any change in database schema forces the reporting service to change, making it highly sensitive.
Solution 2: Data Aggregation via REST
Call the REST APIs of the two services to obtain the required data.
This avoids direct DB access but suffers from poor performance: the reporting service must frequently request the latest data, and as data volume grows the latency of all three services degrades.
Solution 3: Batch Data Pull
Create a dedicated database for the reporting service and use a scheduled job to batch‑pull data from the two services’ databases into its own store.
This improves performance but re‑introduces tight coupling and remains extremely sensitive to schema changes, although having its own database simplifies further processing.
Solution 4: Event‑Driven Push Model
When data tables in the order or user service change, an event is published to a message system (e.g., Kafka). The reporting service subscribes to relevant topics and writes the received data into its own database.
Benefits:
Loose coupling – business services and the reporting service have no direct API or DB calls.
Strong data consistency and near‑real‑time updates.
High performance – additional workers can be added to handle increased event throughput.
Excellent extensibility – new services only need to emit change events, enabling future analytics or additional reporting needs.
Source: Medium article
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
Java High-Performance Architecture
Sharing Java development articles and resources, including SSM architecture and the Spring ecosystem (Spring Boot, Spring Cloud, MyBatis, Dubbo, Docker), Zookeeper, Redis, architecture design, microservices, message queues, Git, etc.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
