The aggregator pattern is one of the most practical solutions for a common microservices headache: a client needs data that lives in five different services, but you do not want that client making five separate network calls. In a Spring Boot ecosystem, the aggregator pattern lets you build a single service that fans out to multiple downstream microservices, combines their responses, and returns one clean, consolidated payload. This article walks through the concept, the trade-offs, and a complete aggregator pattern microservices Spring Boot example you can adapt to your own project And it works..
What Is the Aggregator Pattern in Microservices?
The aggregator pattern is a service composition pattern. A dedicated aggregator service sits between the consumer and several backend microservices. When a request arrives, the aggregator:
- Decomposes the request into multiple calls to different services.
- Invokes those services, ideally in parallel.
- Combines the results into a single response model.
- Returns that unified response to the caller.
Think of it as a chef in a kitchen. The customer does not walk to the grill, the salad station, and the pastry counter separately. They place one order, and the kitchen coordinates everything and delivers one plate.
A typical example is a product detail page in an e-commerce system. The page needs:
- Product basics (name, description, price) from the Product Service
- Stock availability from the Inventory Service
- Customer ratings from the Review Service
- Shipping estimates from the Shipping Service
Without aggregation, the frontend makes four calls, handles four failure modes, and stitches everything together. With an aggregator, the frontend makes one call to /api/products/{id}/details and receives a single ProductDetailResponse Worth knowing..
Why the Aggregator Pattern Matters
The pattern solves several real problems at once:
- Reduced chatty communication. Mobile clients on slow networks benefit enormously from fewer round trips.
- Lower latency. Parallel downstream calls mean total response time approaches the slowest call rather than the sum of all calls.
- Encapsulation of backend complexity. Clients do not need to know that inventory lives in a separate service or that reviews are stored in a different database.
- Centralized resilience logic. Timeouts, retries, fallbacks, and caching are implemented once in the aggregator instead of in every client.
- Consistent response contracts. You can shape the payload for each consumer without changing the underlying services.
The trade-off is that the aggregator becomes a critical path component. On top of that, if it goes down, the composite endpoint goes down. It also adds a network hop, so you must design it carefully with timeouts and circuit breakers.
When to Use the Aggregator Pattern
Use it when:
- A single user action requires data from three or more services.
- The consumer is a UI, mobile app, or third-party API that should not know about internal service topology.
- You need to transform or trim downstream payloads before exposing them.
- You want a Backend-for-Frontend (BFF) layer made for a specific client.
Avoid it when:
- The data comes from a single service — a plain proxy or direct call is simpler.
- The aggregation requires distributed transactions or strong consistency across services.
- Latency budgets are extremely tight and the extra hop is unacceptable.
Aggregator Pattern Microservices Spring Boot Example
Let us build a product-aggregator-service that combines data from three downstream services: product-service, inventory-service, and review-service.
Step 1: Set Up the Project
Create a Spring Boot project with the reactive web starter, which gives you WebClient for non-blocking HTTP calls.
org.springframework.boot
spring-boot-starter-webflux
org.springframework.boot
spring-boot-starter-actuator
Define the downstream URLs in application.yml so they are configurable per environment:
services:
product:
url: http://product-service:8081
inventory:
url: http://inventory-service:8082
review:
url: http://review-service:8083
Step 2: Define the DTOs
Each downstream service has its own model. The aggregator maps them into a single response object.
public public record ProductDto(Long id, String name, String description, double price) {}
public record InventoryDto(Long productId, int availableQuantity, String warehouse) {}
public record ReviewDto(Long productId, double ratingScore, ratingCount) {}
public record ProductDetailResponse(
Long id,
String name,
String description,
double price,
boolean inStock,
int availableQuantity,
double averageRating,
int ratingCount
) {}
Step 3: Create the Aggregator Service with WebClient
The service holds a WebClient and issues the three calls. Consider this: using Mono. zip runs them concurrently and waits for all results.
@Service
public class ProductAggregatorService {
private final WebClient productClient;
private final WebClient inventoryClient;
private final WebClient reviewClient;
public ProductAggregatorService(WebClient.Consider this: builder builder,
@Value("${services. product.Think about it: url}") String productUrl,
@Value("${services. inventory.url}") String inventoryUrl,
@Value("${services.review.url}") String reviewUrl) {
this.productClient = builder.Practically speaking, baseUrl(productUrl). That's why build();
this. inventoryClient = builder.baseUrl(inventoryUrl).build();
this.Day to day, reviewClient = builder. baseUrl(reviewUrl).
public Mono getProductDetails(Long productId) {
Mono productMono = productClient.Also, uri("/products/{id}", productId)
. retrieve()
.get()
.bodyToMono(ProductDto.
Mono inventoryMono = inventoryClient.get()
.uri("/inventory/{id}", productId)
.retrieve()
.bodyToMono(InventoryDto.