Lambda with API Gateway pattern in AWS - Time & Space Complexity
When using Lambda with API Gateway, we want to know how the number of requests affects the work done.
We ask: How does the system handle more users calling the API?
Analyze the time complexity of the following operation sequence.
// API Gateway receives HTTP request
// API Gateway triggers Lambda function
// Lambda processes request and returns response
// API Gateway sends response back to client
This sequence shows how each API call triggers a Lambda function to handle it.
Identify the API calls, resource provisioning, data transfers that repeat.
- Primary operation: Lambda function invocation triggered by API Gateway request
- How many times: Once per each API request received
Each new API request causes one Lambda invocation, so the work grows directly with the number of requests.
| Input Size (n) | Approx. Api Calls/Operations |
|---|---|
| 10 | 10 Lambda invocations |
| 100 | 100 Lambda invocations |
| 1000 | 1000 Lambda invocations |
Pattern observation: The number of Lambda calls grows linearly as requests increase.
Time Complexity: O(n)
This means the total work grows in direct proportion to the number of API requests.
[X] Wrong: "Lambda runs once and handles all requests at the same time."
[OK] Correct: Each request triggers a separate Lambda run, so work grows with requests, not fixed.
Understanding this helps you explain how serverless scales and costs relate to usage, a key cloud skill.
"What if the Lambda function called another Lambda inside it for each request? How would the time complexity change?"