1. How does Serverless Architecture (AWS Lambda / GCP Cloud Run) handle Auto-Scaling and Cold Starts?
❓ Context: 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:
Optimization & Mitigation Strategies:
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();
}
};Initialize database connection pools outside the Lambda handler function scope to reuse sockets across warm executions.