When an application is slow, users leave. The AWS DVA-C02 exam asks how to make your application faster. Let's cover key topics from Lambda optimization to caching strategies.
Lambda Concurrency Optimization
What is Concurrency?
Concurrency is the number of Lambda function instances running simultaneously at a given moment. If 100 users send requests at the same time, Lambda runs 100 instances simultaneously.
The default limit is 1,000 per region. When exceeded, throttling occurs (429 error). Think of it like a fully booked restaurant that cannot seat more customers.
Two Concurrency Strategies
Reserved Concurrency: Pre-allocates fixed capacity for a specific function. Protects important functions from being blocked by other functions consuming all available capacity.
Provisioned Concurrency: Pre-warms execution environments, eliminating cold starts (the extra startup time on first invocation). It incurs additional cost.
Lambda Memory Optimization
Allocating more memory also increases CPU and network bandwidth.
Interesting fact: doubling memory can halve execution time — keeping costs the same or even lower.
AWS Lambda Power Tuning automatically tests multiple memory configurations and finds the optimal size.
Caching Strategies
Caching stores frequently used data in fast storage to avoid fetching from a slow source every time. Like keeping frequently used books on your desk rather than deep in the library.
| Target | Service | Purpose | |--------|---------|---------| | API responses | CloudFront | Cache at global edge servers, reduce latency | | DB reads | ElastiCache (Redis) | Cache frequently read data in memory | | DynamoDB | DAX | DynamoDB-dedicated cache, microsecond responses | | API Gateway | API Gateway Cache | Cache responses per stage |
Messaging Optimization
SNS Filter Policies
Each subscriber receives only relevant messages. For example, the order service receives only "type=order" messages. Reduces unnecessary processing cost and load.
SQS Batch Size
Configure how many messages Lambda fetches at once. More messages per batch = fewer invocations = lower cost.
Example: 100 messages, batch size 10 = 10 invocations (vs 100 with batch size 1).
Identifying Bottlenecks
X-Ray: Visualizes latency between services CloudWatch Logs Insights: Analyzes slow queries and error patterns Lambda Insights: Monitors memory, execution time, and cold starts
Exam Key Points
"Eliminate Lambda cold starts" -- Provisioned Concurrency
"Prevent Lambda throttling" -- Reserved Concurrency
"Find optimal Lambda memory" -- Lambda Power Tuning
"Global API caching" -- CloudFront
"DynamoDB microsecond cache" -- DAX
"Receive only matching messages" -- SNS Filter Policies
"Reduce Lambda invocations" -- Larger SQS batch size
"Visualize bottlenecks" -- X-Ray Service Map
More memory = more CPU = potentially shorter execution time