0
0
AWScloud~5 mins

Why serverless architecture matters in AWS - Performance Analysis

Choose your learning style9 modes available
Time Complexity: Why serverless architecture matters
O(n)
Understanding Time Complexity

We want to see how the work done by serverless functions changes as more requests come in.

How does the number of function calls grow when the number of users or events increases?

Scenario Under Consideration

Analyze the time complexity of the following operation sequence.


// AWS Lambda function triggered by events
exports.handler = async (event) => {
  // Process each record in the event
  for (const record of event.Records) {
    await processRecord(record); // Calls another service or DB
  }
  return 'Done';
};

async function processRecord(record) {
  // Simulate processing
  return Promise.resolve();
}
    

This code runs a serverless function that processes each incoming event record one by one.

Identify Repeating Operations

Identify the API calls, resource provisioning, data transfers that repeat.

  • Primary operation: Processing each event record inside the Lambda function.
  • How many times: Once per event record received in the batch.
How Execution Grows With Input

As the number of event records increases, the function processes more records one after another.

Input Size (n)Approx. Api Calls/Operations
1010 processRecord calls
100100 processRecord calls
10001000 processRecord calls

Pattern observation: The number of operations grows directly with the number of event records.

Final Time Complexity

Time Complexity: O(n)

This means the work grows in a straight line as more events come in.

Common Mistake

[X] Wrong: "The function runs once no matter how many events arrive."

[OK] Correct: Each event record triggers processing, so more records mean more work inside the function.

Interview Connect

Understanding how serverless functions scale with input helps you design systems that handle growth smoothly.

Self-Check

"What if the function processed all records in parallel instead of one by one? How would the time complexity change?"