Beginner LevelCloud Computing (AWS/GCP/Azure)
How does Serverless Architecture (AWS Lambda / GCP Cloud Run) handle Auto-Scaling and Cold Starts?
❓ Interview Prompt: Explain event-driven serverless execution, container cold start latency causes, Provisioned Concurrency, and connection pooling challenges.
Serverless architectures scale automatically from zero to thousands of concurrent executions in response to event triggers (HTTP API Gateway requests, SQS queue items, S3 bucket file uploads).
Cold Starts:
A Cold Start occurs when an incoming event targets a function with no active idle worker instances available. The cloud provider must:
1
Provision a new microVM container (e.g. AWS Firecracker).
2
Download the function deployment package.
3
Initialize the runtime (Node.js, Python, Java) and execute global initialization code.
Optimization & Mitigation Strategies:
•
Provisioned Concurrency: Keeps a requested number of execution environments pre-warmed and ready to respond instantly (sub-10ms latency).
•
Connection Reuse: Initialize heavy database connection pools (PostgreSQL/Redis) outside the function handler scope to reuse sockets across warm invocations.
Code Implementation Example
typescript
import { APIGatewayProxyHandler } from 'aws-lambda';
import { Pool } from 'pg';
// Initialize DB connection pool OUTSIDE the handler function
// Reused across warm executions!
const pool = new Pool({ connectionString: process.env.DATABASE_URL });
export const handler: APIGatewayProxyHandler = async (event) => {
const client = await pool.connect();
try {
const res = await client.query('SELECT NOW()');
return { statusCode: 200, body: JSON.stringify(res.rows[0]) };
} finally {
client.release();
}
};💡AWS Lambda handler reusing database connection pool across warm starts.
🎯 Interview Key Takeaway
Initialize database connection pools outside the Lambda handler function scope to reuse sockets across warm executions.
#Cloud#AWS Lambda#Serverless#DevOps#Beginner
Back to all Cloud Computing (AWS/GCP/Azure) Questions→