Overview
Data aggregation is one of KrakenD’s most powerful features. It allows you to merge responses from multiple backend services into a single unified response, reducing the number of client requests and network overhead.Example: GitHub User Profile
The/git/{user} endpoint demonstrates aggregation by combining:
- GitHub user profile data
- User’s repository list
Try It
Configuration
Here’s the complete endpoint configuration fromconfig/krakend/krakend.json:
Key Features
1. Field Filtering with allow
The allow list acts as a whitelist, only passing through specified fields:
2. Field Mapping
Rename fields in the response usingmapping:
blog field becomes website in the final response.
3. Response Grouping
Thegroup parameter nests the backend response under a specific key:
user in the aggregated response:
4. Collection Handling
Mark array responses withis_collection:
repos key.
Response Structure
Without KrakenD, the client would need 2 separate requests:GET https://api.github.com/users/krakendGET https://api.github.com/users/krakend/repos
/git/krakend returns:
Benefits
- Reduced Client Complexity - One request instead of multiple
- Lower Latency - Parallel backend calls
- Data Privacy - Filter sensitive fields
- Response Shaping - Transform data to match client needs
- Network Efficiency - Smaller payload sizes
Advanced Aggregation
For more complex transformations, see:- Sequential Calls - Use data from one call in another
- Concurrent Requests - Optimize parallel execution