Request and response mapping in AWS - Time & Space Complexity
When using request and response mapping in AWS, it is important to understand how the number of mapping operations affects performance.
We want to know how the time to process mappings grows as the number of requests or mapping rules increases.
Analyze the time complexity of the following mapping operations.
// Example of request and response mapping in API Gateway
{
"requestTemplates": {
"application/json": "mapping logic for request"
},
"responseTemplates": {
"application/json": "mapping logic for response"
}
}
// Each request triggers these mappings before forwarding or returning data
This sequence shows how each incoming request and outgoing response is transformed by mapping templates.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Applying request and response mapping templates for each API call.
- How many times: Once per request and once per response, repeating for every API call.
Each API call requires processing the mapping templates once for the request and once for the response.
| Input Size (n) | Approx. API Calls/Operations |
|---|---|
| 10 | 20 mapping operations (10 requests + 10 responses) |
| 100 | 200 mapping operations |
| 1000 | 2000 mapping operations |
Pattern observation: The number of mapping operations grows directly with the number of API calls.
Time Complexity: O(n)
This means the time to process mappings grows linearly with the number of API calls.
[X] Wrong: "Mapping templates run once and then apply to all requests without extra cost."
[OK] Correct: Each request and response is processed separately, so mapping happens every time, adding cost per call.
Understanding how request and response mappings scale helps you design APIs that perform well as traffic grows.
"What if we added caching to reduce mapping operations? How would the time complexity change?"