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.
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}
}'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