Overview
This endpoint demonstrates KrakenD’s sequential processing capability, where the response from the first backend call is used as input for the second backend call. HTTP Method:GETEndpoint:
/sequential
What It Demonstrates
- Sequential Processing: Executes backend calls in order, not in parallel
- Response Chaining: Uses data from the first response in the second request
- Dynamic URL Construction: Builds the second URL using values from the first response
- Multi-step Data Fetching: Implements lookup patterns (e.g., get ID, then fetch details)
Request Example
Expected Response
How It Works
Step 1: Fetch Hotel Data
First, KrakenD calls the hotels endpoint: Backend URL:http://fake_api/hotels/1.json
Response:
destination_id is allowed):
Step 2: Fetch Destination Data
Then, KrakenD uses thedestination_id from Step 1 to construct the second URL:
Backend URL: http://fake_api/destinations/123.json
Response:
Step 3: Merge Responses
KrakenD merges both responses:Backend Services Called
1. Hotels Service
- Host:
http://fake_api(inherited from global config) - URL Pattern:
/hotels/1.json - Allowed Fields:
destination_id - Purpose: Fetches the hotel record to extract the destination ID
2. Destinations Service
- Host:
http://fake_api(inherited from global config) - URL Pattern:
/destinations/{resp0_destination_id}.json - Purpose: Fetches full destination details using the ID from Step 1
- Variable:
{resp0_destination_id}is replaced with the value from the first response
KrakenD Configuration
Key Configuration Options
Sequential Processing
- Default Behavior: KrakenD executes backend calls in parallel
- With
sequential: true: Backends are called in order - Requirement: Necessary for response chaining to work
Response Variable Syntax
{resp[N]_field_name}
resp[N]: References the Nth backend response (0-indexed)field_name: The field to extract from that response- Example:
{resp0_destination_id}getsdestination_idfrom the first backend
Field Filtering
- Reduces memory usage
- Makes the chaining intent clear
- Prevents field conflicts in the merged response
Response Merging
KrakenD merges all backend responses: First Backend:Use Cases
- ID Lookup Patterns: Fetch ID from one service, details from another
- Multi-step Workflows: Order processing, booking confirmations
- Reference Resolution: Expand foreign keys into full objects
- Dependent Queries: Second query depends on first query results
- Legacy System Integration: When APIs aren’t designed for parallel access
Performance Considerations
Trade-offs
Advantages:- Enables complex data fetching patterns
- Reduces client complexity
- Allows single-request workflows
- Higher latency (sequential, not parallel)
- First call failure blocks second call
- Increased gateway processing time
When to Use
✅ Use Sequential Calls When:- Second call truly depends on first response
- Data relationships require it
- Total calls are few (2-3)
- Calls are independent (use parallel aggregation instead)
- Many steps are needed (consider async patterns)
- Low latency is critical