High-Performance and Cost-Optimised Scenarios
Answer scenario questions on caching strategies, data lake query optimisation, Reserved vs Spot trade-offs, and read replica architectures.
High-Performance and Cost-Optimised Scenarios is a free AWS Solutions Architect lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the AWS Solutions Architect learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Scenario 1: Caching to Reduce Database Load
Scenario: A news website's RDS MySQL database serves 90% read traffic for article content that changes at most once an hour. Database CPU averages 80%, costs are rising, and latency is 200ms per query. Solution: Add an ElastiCache Redis cluster in front of RDS using the lazy loading (cache-aside) pattern. Application checks cache first — on a cache hit, return the cached article in <1ms. On a miss, query RDS, return the result, and write it to the cache with a 1-hour TTL. Expected result: 90% cache hit rate, RDS CPU drops to under 20%, latency drops to under 5ms for cached responses.
import boto3, json
elasticache = boto3.client('elasticache')
redis_client = None # assume redis-py client connected to ElastiCache endpoint
def get_article(article_id):
cache_key = 'article:' + str(article_id)
# Check cache first
cached = redis_client.get(cache_key)
if cached:
return json.loads(cached) # cache hit: <1ms
# Cache miss: query RDS
article = rds_query('SELECT * FROM articles WHERE id = %s', article_id)
# Write to cache with 1-hour TTL
redis_client.setex(cache_key, 3600, json.dumps(article))
return articleScenario 2: CloudFront for Static Asset Delivery
Scenario: Users in Asia Pacific experience 2-4 second load times for a web application hosted on EC2 in us-east-1. The application serves large static assets (images, JS, CSS). Solution: Place a CloudFront distribution in front of the ALB. Configure a cache behaviour for the /static/* path with a long TTL (e.g., 1 week) so static files are cached at CloudFront edge locations near users in Asia. Dynamic API requests bypass caching with TTL=0. Asian users load static assets from a Singapore or Tokyo edge location in under 100ms instead of waiting for round trips to us-east-1.
# CloudFront origin for ALB + separate behaviour for static assets
aws cloudfront create-distribution --distribution-config '{
'Origins': {
'Quantity': 1,
'Items': [{
'Id': 'alb-origin',
'DomainName': 'my-alb.us-east-1.elb.amazonaws.com',
'CustomOriginConfig': {"HTTPSPort": 443, "OriginProtocolPolicy": "https-only"}
}]
},
'CacheBehaviors': {
'Quantity': 1,
'Items': [{
'PathPattern': '/static/*',
'DefaultTTL': 604800,
'MaxTTL': 604800
}]
},
'DefaultCacheBehavior': {"DefaultTTL": 0}
}'Scenario 3: Right-Sizing with Compute Optimizer
Scenario: A company has 500 EC2 instances, many provisioned 3 years ago with large instance types. Their AWS bill is high but they do not know which instances are over-provisioned. Solution: Enable AWS Compute Optimizer (free, uses 14 days of CloudWatch metrics). Compute Optimizer analyses each instance's actual CPU, memory, network, and disk utilisation and provides recommendations to right-size. A t3.xlarge running at 8% CPU average would be recommended to downsize to t3.small. Applying recommendations across 500 instances typically reduces EC2 costs by 20–40%.
# Enable Compute Optimizer at account level
aws compute-optimizer update-enrollment-status \
--status Active
# Get EC2 instance recommendations
aws compute-optimizer get-ec2-instance-recommendations \
--filters Name=Finding,Values=OVER_PROVISIONED \
--query 'instanceRecommendations[*].{Instance: instanceArn, Current: currentInstanceType, Recommended: recommendationOptions[0].instanceType}' \
--output tableScenario 4: Spot Instances for Batch Processing
Scenario: A genomics company runs nightly batch jobs that take 8 hours and can be retried if interrupted. EC2 On-Demand costs $10,000 per month for these jobs. Solution: Use EC2 Spot Instances for the batch processing fleet. Spot Instances are unused EC2 capacity available at up to 90% discount. For interruption-tolerant batch jobs, use AWS Batch which automatically re-queues failed Spot jobs and uses a mixed fleet (Spot + minimal On-Demand fallback). Expected savings: 70–90% reduction in compute costs — from $10,000 to $1,000–3,000 per month.
# AWS Batch compute environment with Spot instances
aws batch create-compute-environment \
--compute-environment-name spot-genomics \
--type MANAGED \
--state ENABLED \
--compute-resources '{
"type": "SPOT",
"bidPercentage": 60,
"minvCpus": 0,
"maxvCpus": 256,
"instanceTypes": ["optimal"],
"subnets": ["subnet-1a", "subnet-1b"],
"securityGroupIds": ["sg-batch"],
"instanceRole": "arn:aws:iam::123456789012:instance-profile/ecsInstanceRole",
"spotIamFleetRole": "arn:aws:iam::123456789012:role/AmazonEC2SpotFleetRole"
}' \
--service-role arn:aws:iam::123456789012:role/AWSBatchServiceRoleScenario 5: DynamoDB On-Demand for Variable Traffic
Scenario: A gaming leaderboard uses DynamoDB with provisioned throughput. During game launches, traffic spikes 50x and the table throttles requests. Outside launches, throughput is near zero — provisioned capacity is wasted. Solution: Switch DynamoDB to On-Demand capacity mode. On-Demand scales instantly to any throughput without manual capacity planning, and charges per request rather than per provisioned unit. You pay only for the requests you make — no idle capacity cost between launches. On-Demand trades slightly higher per-request cost for guaranteed no-throttle and zero capacity management.
# Switch existing DynamoDB table to On-Demand mode
aws dynamodb update-table \
--table-name Leaderboard \
--billing-mode PAY_PER_REQUEST
# Verify the change
aws dynamodb describe-table \
--table-name Leaderboard \
--query 'Table.BillingModeSummary.BillingMode'Scenario 6: S3 Intelligent-Tiering for Unpredictable Access
Scenario: A company stores millions of user-generated images in S3 Standard. Access patterns vary unpredictably — some images are accessed daily, others not for months. They want to reduce storage costs without managing lifecycle policies manually. Solution: Use S3 Intelligent-Tiering. It automatically moves objects between tiers based on access patterns: Frequent Access (Standard), Infrequent Access (30+ days not accessed), Archive Instant Access (90+ days), and Archive Access (90+ days, opt-in). There are no retrieval fees within Intelligent-Tiering. The monitoring charge is $0.0025 per 1,000 objects per month — negligible for large datasets.
# Move objects to Intelligent-Tiering via lifecycle policy
aws s3api put-bucket-lifecycle-configuration \
--bucket user-images-bucket \
--lifecycle-configuration '{
"Rules": [{
"ID": "AutoTier",
"Status": "Enabled",
"Filter": {},
"Transitions": [{
"Days": 0,
"StorageClass": "INTELLIGENT_TIERING"
}]
}]
}'Scenario 7: Athena vs Redshift Trade-off
Scenario: A startup wants to query S3 data lake tables. They run about 10 ad hoc queries per week. A vendor proposes Amazon Redshift with a dc2.large cluster. Solution for a startup: Start with Amazon Athena — zero infrastructure cost, pay only for data scanned (~$5/TB). 10 queries per week on well-partitioned Parquet data might cost under $5/month. Redshift dc2.large costs ~$180/month continuously. Redshift becomes cost-effective only when query concurrency is high (50+ queries/day) or sub-second response is required. The keyword 'ad hoc, infrequent' firmly points to Athena.
# Athena cost estimate for 10 queries/week:
# Assume each query scans 5 GB of Parquet data
# 10 queries x 5 GB = 50 GB / week = 200 GB / month
# Athena cost: 200 GB x $0.005/GB = $1.00 / month
#
# Redshift dc2.large cost: $0.25/hr x 24hr x 30days = $180/month
#
# For 10 queries/week -> Athena saves $179/month
# Breakeven: when queries scan >36 TB/month or concurrency >50/day -> use RedshiftScenario 8: EBS Volume Type Selection
Scenario: A relational database server requires 64,000 IOPS with consistent low latency. The current gp3 EBS volume is hitting its IOPS ceiling. Solution: Upgrade to io2 Block Express (EBS volume type designed for I/O-intensive databases). io2 Block Express supports up to 256,000 IOPS per volume and sub-millisecond latency. It is more expensive than gp3 ($0.125/GB + $0.065/provisioned IOPS/month) but the only EBS option that meets 64,000+ IOPS requirements. For latency-critical database workloads where gp3's 16,000 IOPS ceiling is insufficient, io2 is the only viable EBS choice.
# Create io2 Block Express volume with 64,000 IOPS
aws ec2 create-volume \
--volume-type io2 \
--size 500 \
--iops 64000 \
--availability-zone us-east-1a \
--encrypted
# EBS volume type IOPS limits summary:
# gp3: up to 16,000 IOPS (default 3,000, configurable)
# io1: up to 64,000 IOPS (on Nitro instances)
# io2 Block Express: up to 256,000 IOPS
# st1 (throughput HDD): no IOPS focus, max 500 MB/s throughput
# sc1 (cold HDD): lowest cost, 250 MB/s max, rarely accessed dataScenario 9: Reserved Instances for Steady Workloads
Scenario: A company runs 20 r6i.4xlarge EC2 instances continuously for a production application and expects no change in requirements for 3 years. Their current On-Demand spend is $80,000/year for these instances. Solution: Purchase 3-year Standard Reserved Instances (or Compute Savings Plans) with All Upfront payment for the maximum discount. Standard Reserved Instances offer up to 72% discount versus On-Demand. The instances run 24/7 with predictable workload — the classic profile for Reserved Instances. Expected cost reduction: $80,000 × 0.72 = $22,400/year vs. $80,000/year On-Demand — saving $57,600/year.
# Reserved Instance purchase decision matrix:
# On-Demand: No commitment, highest price, any workload
# 1-yr RI (All Up): 40% discount, 1-yr commitment, specific instance type
# 3-yr RI (All Up): 60-72% discount, 3-yr commitment, best for stable workloads
# Compute Savings Plan: 66% max discount, flexible instance family/size/Region
# EC2 Spot: 90% discount, interruptible, batch/stateless only
#
# Rule: if usage > 70% of the time for >1 year -> buy RI or Savings Plan
# Rule: if usage < 50% -> stick with On-Demand
# Rule: if usage pattern is steady 3yr -> 3yr RI All Upfront maximises savingsScenario 10: Lambda vs EC2 Cost for Variable Traffic
Scenario: A company runs a REST API on a t3.micro EC2 instance costing $8/month. The API receives 1 million requests/month, each taking 100ms to process. The team asks if Lambda would be cheaper. Analysis: Lambda pricing: 1,000,000 requests × $0.0000002 = $0.20 (request cost) + 1,000,000 × 0.1s × 128MB memory × rate = ~$1.67 (compute cost) = ~$1.87/month. Lambda is cheaper than EC2 for this low-traffic API. As traffic grows above ~40 million requests/month, EC2 becomes cheaper. Use the Lambda Cost Calculator to find the break-even for each workload.
# Lambda vs EC2 cost rough break-even calculation:
# Lambda costs: $0.20 per 1M requests + $0.0000166667 per GB-second
# At 128 MB memory, 100ms duration:
# GB-seconds per request = 0.128 GB x 0.1s = 0.0128 GB-s
# Cost per request = $0.0000166667 x 0.0128 = $0.000000213 compute
# + $0.0000002 request fee = $0.000000413 total per request
#
# EC2 t3.micro: $0.0104/hr x 720 hrs = $7.49/month
# Break-even: $7.49 / $0.000000413 = ~18 million requests/month
# Below 18M requests/month -> Lambda cheaper
# Above 18M requests/month -> EC2 cheaper (if utilisation is high)Scenario 11: Global Accelerator for Dynamic APIs
Scenario: A global API serving users in Europe, US, and Asia experiences inconsistent latency because traffic traverses unpredictable internet paths. CloudFront was considered but the API responses are dynamic (non-cacheable). Solution: Use AWS Global Accelerator. It provides two static anycast IP addresses globally. User traffic enters the AWS global backbone at the nearest AWS edge location and travels over AWS's private network to the origin in the target Region — avoiding the congested public internet middle-mile. Global Accelerator improves dynamic API response time by 20-60% and provides instant failover when a Region endpoint becomes unhealthy.
# Create a Global Accelerator for an ALB
aws globalaccelerator create-accelerator \
--name my-api-accelerator \
--ip-address-type IPV4 \
--enabled
# Add a listener and endpoint group pointing to ALB
aws globalaccelerator create-listener \
--accelerator-arn arn:aws:globalaccelerator::123:accelerator/abc \
--protocol TCP \
--port-ranges '[{"FromPort": 443, "ToPort": 443}]'
# Endpoint group in us-east-1 with ALB
aws globalaccelerator create-endpoint-group \
--listener-arn arn:aws:globalaccelerator::123:listener/xyz \
--endpoint-group-region us-east-1 \
--endpoint-configurations '[{"EndpointId": "arn:aws:elasticloadbalancing:...", "Weight": 100}]'Quick Check
Test your understanding of AWS Solutions Architect (SAA-C03) concepts from this lesson.
Lesson Recap
In this lesson you worked through scenarios covering: ElastiCache lazy loading to reduce RDS CPU from 80% to 20%, Spot Instances and AWS Batch for 70-90% batch job cost savings, Athena for infrequent ad hoc queries versus Redshift for high-concurrency analytics, and S3 Intelligent-Tiering for unpredictable access patterns without retrieval fees. Next up is the final capstone: a timed mixed-domain mini exam to measure your readiness.
Frequently asked questions
Is the “High-Performance and Cost-Optimised Scenarios” lesson free?
Yes — the full text of “High-Performance and Cost-Optimised Scenarios” is free to read here on the web, and the AWS Solutions Architect course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the AWS Solutions Architect course, upgrade to CoddyKit PRO.
What will I learn in “High-Performance and Cost-Optimised Scenarios”?
Answer scenario questions on caching strategies, data lake query optimisation, Reserved vs Spot trade-offs, and read replica architectures. You practise AWS Solutions Architect with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start AWS Solutions Architect?
No prior experience is required. AWS Solutions Architect on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “High-Performance and Cost-Optimised Scenarios” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this AWS Solutions Architect lesson?
Yes. Every AWS Solutions Architect lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Secure Architecture Scenarios
- Resilient and Highly Available Architecture Scenarios
- High-Performance and Cost-Optimised Scenarios
- Mixed Domain Full-Length Mini Exam