Domain 4 of the DVA-C02 exam focuses on optimising performance and managing costs across AWS services. This concept matters because real-world applications can become slow or expensive if you do not design for efficiency, and the exam tests your ability to make smart trade-offs between speed and spending.
Jump to a section
First, a coffee shop opens for the morning rush and customers start pouring in, which leads to the barista having to make drinks as quickly as possible while keeping the queue from spilling out the door. This is exactly how performance optimisation and cost management work in AWS. When your application gets popular, too many user requests hit your systems at once, and you need to handle that traffic without breaking the bank.
Imagine the barista is your AWS Lambda function. Each coffee order is a request. The coffee machine is DynamoDB, storing the recipes. Now, if the barista makes every drink from scratch without reusing any steps, they waste time and energy. That is like paying for every single database read and write at full price. Instead, the barista could brew a big batch of coffee concentrate in the morning and store it in a thermos. That thermos is like a cache, keeping commonly needed data ready so you don't pay to fetch it every time.
Also, if the queue gets too long, the barista might make a few drinks ahead of time for the most popular orders. In AWS, this is provisioning read and write capacity units ahead of demand. But if the barista makes way too much coffee in advance and it goes cold, they have wasted resources and money. That is over-provisioning. The whole system works best when you balance speed, capacity, and cost — just like the barista does during the peak hour.
Performance optimisation and cost management in AWS is about making your applications run faster and cheaper without breaking. As a Developer Associate, you need to understand how to tune services like Lambda, DynamoDB, and caching tools to get the best results for your users and your budget.
Let us start with AWS Lambda. Lambda is a serverless compute service. 'Serverless' means you do not manage servers; you just upload your code (a function) and AWS runs it when an event triggers it, like an HTTP request. You pay only for the time your code actually runs. To optimise performance, you need to think about the 'cold start' — the first time a function runs, AWS has to set up a fresh container, which adds a tiny delay. For cost, you choose the right memory setting. Lambda charges by memory and duration. Doubling memory often doubles CPU speed, so a function with 1024 MB might finish in half the time of a 512 MB version, costing roughly the same. The trick is to test and find the sweet spot.
Next is DynamoDB. DynamoDB is a NoSQL database managed by AWS. 'NoSQL' means it does not use tables with rows and columns like a traditional database; it stores data as items in tables, accessed by a primary key. DynamoDB uses provisioned throughput: you set how many reads and writes per second you expect. If you set too high, you pay for unused capacity. If too low, requests get throttled (rejected). To optimise, you use auto-scaling — DynamoDB adjusts capacity based on actual traffic. You also partition tables carefully. Data in DynamoDB is spread across partitions on separate servers. A poor partition key (like a date that everyone queries) creates a 'hot partition' where one server is overwhelmed while others sit idle. Use a high-cardinality key (like a user ID) to spread requests evenly.
Caching is another major tool. A cache is a temporary storage layer that holds frequently accessed data so your application does not have to query the database every time. AWS offers ElastiCache, which supports Redis or Memcached. For example, a news website can cache the top stories for five minutes. Thousands of users trying to read that page only hit the cache, not DynamoDB. This saves money on read capacity units and makes the page load faster. The trade-off is that cached data might be stale — if a story updates every second, five-minute cache is too long. You set a 'Time to Live' (TTL) that tells the cache how long to keep each item.
Choosing compute resources wisely also affects cost. 'Elastic scaling' means your system can automatically grow or shrink based on demand. For instance, Amazon EC2 (Elastic Compute Cloud) lets you spin up virtual servers. You can set a 'scaling policy' to add servers when CPU reaches 70%, and remove them when it falls to 30%. This avoids paying for idle servers. For Lambda, you can use 'reserved concurrency' to guarantee a minimum number of concurrent executions, which avoids throttling but reserves capacity that costs even when idle.
Finally, monitoring is essential. 'CloudWatch' is AWS's monitoring service that collects metrics like CPU usage, request count, and latency. You set 'alarms' to alert you when costs exceed a budget. A 'cost anomaly detection' feature watches spending patterns and flags unexpected spikes. The core principle is to measure every resource, right-size it (choose the smallest instance or lowest capacity that meets performance), and use managed services that offload operational overhead. Every millisecond of latency saved and every unnecessary read eliminated directly reduces your bill and improves user experience.
Measure Current Performance and Cost
Use CloudWatch to collect metrics like Lambda duration, DynamoDB consumed throughput, and EC2 CPU utilisation. Also check AWS Cost Explorer to see which services cost the most. Without baseline numbers, you cannot know if a change improves or worsens anything.
Right-Size Compute Resources
For Lambda, increase memory in small increments (e.g., from 512 MB to 1024 MB) and measure response time. Choose the memory where cost per invocation is lowest. For EC2, switch to a smaller instance type if average utilisation is below 30%, or to a different family if bottlenecks are resource-specific.
Implement Caching Layer
Deploy ElastiCache Redis or DAX in front of DynamoDB. Configure the cache to store the most frequently accessed items. Set TTL based on how often data changes. Monitor cache hit rate in CloudWatch — aim for above 80%. This step reduces DynamoDB reads and lowers latency.
Configure Auto-Scaling and Capacity Management
For DynamoDB, enable auto-scaling with a target utilisation of 70%. For EC2, set up Auto Scaling groups with a dynamic scaling policy based on CPU or request count. For Lambda, use reserved concurrency to prevent a single function from consuming all account-level concurrency and causing other functions to throttle.
Set Cost Controls and Alerts
Apply cost allocation tags to all resources (e.g., 'Environment', 'Project'). Create a monthly budget in AWS Budgets with an alert at 80% and 100% of the budget. Set up a CloudWatch alarm on the 'EstimatedCharges' metric. Review the Cost Usage Report every week to spot anomalies early.
Sarah is a developer for a social media startup that hosts a photo-sharing app on AWS. The app lets users upload images and see a feed of their friends' recent posts. After launch, the app becomes popular, and several problems arise. First, the feed page loads slowly — users wait seconds for it to appear. Second, the monthly AWS bill tripled from $500 to $1500.
Sarah investigates. She opens CloudWatch and finds that the feed's API endpoint uses a Lambda function that queries DynamoDB for each user's friends and their recent posts. The function is configured with 256 MB memory, and each request takes 400 milliseconds. DynamoDB has 10 read capacity units and is hitting throttling errors — about 15% of requests fail.
Step by step, Sarah makes changes. She increases the Lambda memory to 1024 MB, which reduces response time to 150 milliseconds because the extra memory also boosts CPU. She adds a 'reserved concurrency' of 20 to prevent throttling during spikes. In DynamoDB, she switches the table from provisioned capacity to 'on-demand' mode temporarily so it automatically scales with traffic, but then re-enables auto-scaling with a minimum of 5 and maximum of 50 read capacity units to keep costs predictable.
Next, she implements caching. The feed data rarely changes within a minute, so she sets up ElastiCache with Redis. The Lambda function first checks the cache. If a feed item is in cache (a 'cache hit'), it returns it in 2 milliseconds. If not (a 'cache miss'), it queries DynamoDB. She sets a TTL of 60 seconds. Now, 80% of requests are cache hits, drastically reducing DynamoDB reads and making the feed load instantly.
Sarah also looks at cost. She notices the app stores user profile images in S3 (Simple Storage Service), but each time someone views a feed, the app retrieves the full resolution image. She adds a 'CloudFront' content delivery network (CDN) in front of S3. CloudFront stores cached copies of images on 'edge locations' (servers distributed around the world). Users download images from the nearest edge location, reducing latency and S3 data transfer costs.
Finally, she sets up a 'budget alert' in AWS Budgets to email her if monthly spending exceeds $1200. She also deletes unused 'snapshots' of old EC2 instances that were left over from development. Over the next month, the bill drops to $900, and load times improve from 4 seconds to 0.8 seconds. The system now handles peak traffic without errors.
The DVA-C02 exam tests 'Performance Optimization and Cost Management' primarily through scenario-based multiple choice questions. You get a description of an application with a problem — like high latency, high cost, or throttling — and four answers. They want you to pick the most effective and cheapest solution.
Exam topics they love to test: - 'Lambda provisioned concurrency' vs 'reserved concurrency' vs 'auto-scaling'. Provisioned concurrency warms a fixed number of environments to avoid cold starts. Reserved concurrency sets a maximum limit for a function, stopping it from using all account-level concurrency. Trap: they might describe a problem where cold starts cause delays for a few users, and the answer is 'use provisioned concurrency', but the correct answer is 'use reserved concurrency' if the real issue is throttling during a spike. - 'DynamoDB auto-scaling' vs 'on-demand capacity'. Auto-scaling adjusts provisioned capacity based on a target utilisation percentage (e.g., 70% consumed capacity). On-demand scales instantly but costs more per read/write. Trap: if an app has unpredictable traffic, on-demand is better, but they might trick you with 'use auto-scaling' because it sounds cheaper. Read carefully — on-demand is costlier per request but prevents throttling for unknown spikes. - 'ElastiCache Redis' vs 'DynamoDB Accelerator (DAX)'. DAX is a read cache specifically for DynamoDB; Redis is a general-purpose cache. The exam often tests which to use for reducing DynamoDB read latency. Trap: if the question says 'cached data must survive restarts', DAX loses data on restart but Redis can be configured with persistence — so Redis is better. - 'Cost allocation tags' — tagging resources (like 'env:production' or 'team:marketing') so you can track costs per department. The exam might ask how to reduce a specific team's bill, and the answer is 'apply cost allocation tags and use Cost Explorer'. - 'Right-sizing' EC2 instances: the exam gives CPU and memory utilisation metrics and asks which instance type to choose. Trap: they might suggest an instance family that is not optimised for the workload (e.g., compute-optimised for a memory-heavy database). Key definitions to remember: - 'Throughput' (reads/writes per second) - 'Latency' (time between request and response) - 'Concurrency' (number of requests being processed at the same time) - 'Time to Live (TTL)' (how long an item stays in cache) - 'Cold start' (first invocation delay for serverless functions) Expect at least 3-4 questions dedicated to this domain. They often combine services — for example, an API Gateway backed by Lambda that calls DynamoDB, and you need to optimise the whole chain.
Always match DynamoDB read and write capacity to actual traffic patterns using auto-scaling or on-demand mode, never static provisioned capacity without monitoring.
Use ElastiCache or DAX to cache DynamoDB query results, but set an appropriate TTL to balance freshness with reduced read costs.
Pick the smallest Lambda memory configuration that meets your response time goals, because doubling memory can halve duration and keep cost roughly equal.
Right-sizing EC2 instances by monitoring CPU, memory, and network utilisation can reduce costs by 30-60% without any performance loss.
Enable cost allocation tags and set budget alerts in AWS Budgets to catch unexpected spending before it escalates.
Provisioned concurrency for Lambda functions should only be used when cold starts cause measurable user-facing delays, not as a default setting.
These come up on the exam all the time. Here's how to tell them apart.
DynamoDB Auto-Scaling
Uses provisioned capacity with automatic adjustments based on a target utilisation percentage
Lower per-request cost than on-demand, but you pay for reserved minimum capacity even if idle
Best for predictable workloads with known traffic patterns
DynamoDB On-Demand
Automatically scales instantly and you pay only for actual reads and writes
Higher per-request cost, no idle capacity charges
Best for unpredictable workloads with high traffic variability
Lambda Provisioned Concurrency
Keeps a specified number of execution environments warm to eliminate cold starts
Costs money even when the environments are idle (no requests)
Useful for latency-sensitive functions where cold starts are unacceptable
Lambda Reserved Concurrency
Sets a maximum limit on how many concurrent invocations a function can have
No extra cost, but if all slots are used, new requests are throttled
Useful to prevent a single function from consuming all account concurrency and starving other functions
ElastiCache (Redis) General Cache
A general-purpose, in-memory data store that can cache any type of data
Supports complex data structures (lists, sets, sorted sets) and pub/sub messaging
Requires separate management and scales independently from DynamoDB
DynamoDB Accelerator (DAX)
A write-through cache specifically for DynamoDB tables — automatically syncs data on writes
Only works with DynamoDB and is tightly integrated, reducing setup complexity
Designed to reduce DynamoDB read latency to microseconds, but cache state lost on node failure
Mistake
Using the most expensive instance type always means better performance.
Correct
Performance depends on matching the instance type to the workload. A compute-optimised instance with high virtual CPUs might perform worse on a memory-bound application than a smaller memory-optimised instance. Always test actual workload patterns.
Beginners see price tiers as a linear quality scale, but AWS instance families are specialised for different tasks, and overspending does not guarantee speed.
Mistake
DynamoDB on-demand mode is always cheaper because you only pay for what you use.
Correct
On-demand is cheaper for unpredictable workloads with occasional spikes because you avoid paying for idle capacity. But for steady, predictable traffic, provisioned capacity with auto-scaling is significantly cheaper because you get a much lower per-request rate.
The name 'on-demand' sounds like a utility model where you pay only for use, but the pricing model is a premium rate for flexibility.
Mistake
Caching always reduces cost immediately because it reduces database reads.
Correct
Caching adds the cost of running the cache cluster (like ElastiCache nodes) and the compute time for cache lookups. If your application has a low cache hit rate (e.g., many unique queries), the cache overhead can increase total cost and latency.
Beginners think caching is a free performance boost and ignore the infrastructure cost and complexity.
Mistake
Lambda cold starts are always a bad thing and must be eliminated completely.
Correct
Cold starts add a few hundred milliseconds of latency, but for many applications (like batch processing or background jobs), that delay is tolerable. Completely eliminating cold starts with provisioned concurrency costs money even when idle, so it is only justified for latency-sensitive applications.
Beginners read about cold starts as a performance problem and assume it must be fixed universally, without evaluating the cost-benefit trade-off.
Mistake
Scaling up (using a larger instance) is always better than scaling out (using more smaller instances).
Correct
Scaling out is often better for high availability and fault tolerance because if one instance fails, others still serve traffic. Scaling up (vertical scaling) has a maximum hardware limit and creates a single point of failure. For cloud-native design, horizontal scaling is preferred.
The misconception comes from traditional on-premise thinking where adding more resource to one machine was physically easier than adding more machines.
Reveal each answer, then mark whether you got it right. Score 60%+ to unlock the next chapter.
On-demand capacity lets DynamoDB automatically scale reads and writes based on traffic, and you pay per request. Provisioned capacity lets you set a fixed number of reads/writes per second, and you pay a lower per-request rate but still pay for unused capacity. Use on-demand for unpredictable traffic; use provisioned with auto-scaling for steady, predictable workloads.
Increase the Lambda function memory, which also allocates more CPU and networking, reducing setup time. Use provisioned concurrency to keep a number of environments warm. Also, optimise your deployment package size and minimise dependencies — smaller packages start faster.
Yes. ElastiCache requires you to pay for the cache nodes (servers) running Redis or Memcached, plus data transfer costs. It is only cost-effective if your application benefits from many fewer DynamoDB reads, offsetting the cache node cost. Always calculate the break-even point.
A hot partition occurs when one partition key value is accessed far more than others, overloading a single physical partition. Fix it by designing a partition key with high cardinality (many unique values, like user ID), using a composite key, or adding a random suffix to the key to spread writes evenly.
Use AWS Budgets to set a cost budget with an alert threshold. For services like DynamoDB, consider on-demand capacity to handle spikes without human intervention. Use AWS Cost Anomaly Detection to be alerted about unusual cost patterns, and set a CloudWatch alarm on the 'EstimatedCharges' metric for the current month.
It depends. Many small functions improve modularity and allow independent scaling, but increase cold start overhead and management complexity. One large function reduces cold starts for related operations but can lead to high memory waste. For DVA-C02, remember to keep functions focused on a single task (favour small functions) but not too fine-grained.
You've just covered Performance Optimization and Cost Management Best Practices — now see how well it sticks with free DVA-C02 practice questions. Full explanations included, no account needed.
Done with this chapter?