Study Guide: Optimizing Application Resource Usage (AWS DVA-C02)
Optimize application resource usage
Optimizing Application Resource Usage
This guide covers Domain 4, Task 3 of the AWS Certified Developer - Associate (DVA-C02) exam. It focuses on maximizing application performance while minimizing infrastructure costs through rightsizing, caching, and efficient messaging.
Learning Objectives
After studying this guide, you should be able to:
- Define and manage concurrency in serverless and containerized environments.
- Profile application performance to identify bottlenecks using AWS tools.
- Determine the minimum memory and compute power required for a given workload.
- Optimize messaging patterns using Amazon SNS subscription filter policies.
- Implement caching strategies at the CDN (CloudFront) and application (ElastiCache) levels.
Key Terms & Glossary
| Term | Definition | Real-World Example |
|---|---|---|
| Concurrency | The number of requests that your application can handle at the same time. | A Lambda function handling 1,000 simultaneous API calls. |
| Profiling | The process of measuring the space (memory) or time complexity of program code. | Using Amazon CodeGuru or X-Ray to find which function takes the most time. |
| TTL (Time to Live) | The duration for which a resource is stored in a cache before expiring. | Setting a CloudFront image to expire after 24 hours. |
| Lazy Loading | A caching strategy that loads data into the cache only when necessary (on a miss). | Checking Redis for a user profile; if not found, fetch from DynamoDB and save to Redis. |
| Rightsizing | Matching instance types and sizes to your workload performance and capacity requirements. | Switching from a t3.large (unused CPU) to a t3.small to save 75% in costs. |
The "Big Idea"
[!IMPORTANT] Optimization is a continuous loop, not a one-time task. It follows the formula: Efficiency = Performance / Cost. The goal is to reach the "Goldilocks Zone" where resources are not wasted (over-provisioned) but performance is not degraded (under-provisioned).
Formula / Concept Box
Lambda Resource Scaling
In AWS Lambda, Memory is the primary lever for performance. Increasing memory proportionally increases CPU power and network bandwidth.
| Memory (MB) | CPU Share | Cost per 1ms |
|---|---|---|
| 128 MB | Smallest share | Lowest |
| 1,769 MB | Equivalent to 1 vCPU | Moderate |
| 10,240 MB | Max (approx 6 vCPUs) | Highest |
Hierarchical Outline
- Performance Profiling & Bottlenecks
- Application Logs: Using CloudWatch Logs Insights to query for high-latency entries.
- AWS X-Ray: Identifying service-to-service integration bottlenecks.
- Compute Optimization
- EC2 Selection: Choosing between Compute Optimized (
Cfamily) vs. Memory Optimized (Rfamily). - Lambda Tuning: Finding the "Sweet Spot" where increased memory reduces execution time enough to lower total cost.
- EC2 Selection: Choosing between Compute Optimized (
- Messaging Optimization
- Subscription Filters: Offloading message filtering from the application code to the SNS infrastructure.
- Caching Strategies
- Edge Caching: Amazon CloudFront using Request Headers as cache keys.
- Application Caching: Amazon ElastiCache (Redis/Memcached) for database offloading.
Visual Anchors
Caching Logic Flowchart
Lambda Performance Curve (TikZ)
\begin{tikzpicture} % Axes \draw [->] (0,0) -- (6,0) node[right] {\small Memory (MB)}; \draw [->] (0,0) -- (0,4) node[above] {\small Execution Time / Cost};
% Execution Time Curve (Blue)
\draw [thick, blue] (0.5,3.5) to[out=-80, in=170] (5,0.5);
\node [blue] at (5.5,0.8) {\small Time};
% Cost Curve (Red)
\draw [thick, red] (0.5,0.5) -- (5,3);
\node [red] at (5.5,3.2) {\small Cost};
% Optimal Point
\draw [dashed] (2.2,0) -- (2.2,1.5);
\node at (2.2,-0.4) {\small "Sweet Spot"};\end{tikzpicture}
Definition-Example Pairs
-
Subscription Filter Policy
- Definition: A JSON object that defines which messages a subscriber receives based on the message attributes.
- Example: An SNS topic sends "Order" messages. The "Shipping" SQS queue uses a filter policy
{"status": ["paid"]}so it doesn't process unpaid orders, saving compute cycles.
-
CloudFront Header Caching
- Definition: Forwarding specific headers to the origin and using them as part of the cache key.
- Example: A site serves different content for mobile vs. desktop. By caching based on the
User-Agentheader, CloudFront stores two versions of the page at the edge.
Worked Examples
Example 1: Lambda Memory Optimization
A Lambda function currently uses 128 MB of memory and takes 10 seconds to complete. You increase the memory to 512 MB, and the execution time drops to 2 seconds.
- Old Cost Basis: $128 MB \times 10,000 ms = 1,280,000 units$
- New Cost Basis: $512 \text{ MB} \times 2,000 \text{ ms} = 1,024,000 \text{ units}$
- Result: By increasing memory, the function is 5x faster and 20% cheaper because the duration decreased more significantly than the memory price increased.
Example 2: Subscription Filtering
You have a fan-out architecture where an SNS topic receives 1,000,000 messages/day. Only 10% are relevant to a specific SQS queue.
- Without Filters: The Lambda attached to SQS triggers 1M times, checks the message body, and discards 900k of them. (High cost, high Lambda concurrency usage).
- With Filters: SNS discards 900k messages. The Lambda triggers only 100k times. (90% cost savings on compute).
Checkpoint Questions
- How does Amazon CloudFront determine a "cache hit" if multiple headers are forwarded?
- What AWS tool allows you to visualize the latency between a Lambda function and an upstream DynamoDB table?
- True or False: Increasing Lambda memory always increases the total cost of execution.
- Describe the difference between Lazy Loading and Write-Through caching strategies.
▶Click to see answers
- CloudFront includes the specified headers in the Cache Key. If headers vary, CloudFront creates separate cache entries for each unique combination.
- AWS X-Ray (Service Maps and Trace Timelines).
- False. If the duration decreases significantly (due to more CPU/bandwidth), the total cost () may decrease.
- Lazy Loading only caches data when requested (on a miss). Write-Through updates the cache every time data is written to the database (ensuring data is never stale but potentially wasting cache space).