AcademyCloudArchitecting Module 11
AcademyCloudArchitecting Module 11
© 2020, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Module overview
Sections Lab
1. Architectural need • Guided Lab: Streaming Dynamic Content
Using Amazon CloudFront
2. Overview of caching
3. Edge caching
4. Caching web sessions
5. Caching databases
Knowledge check
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 2
Module objectives
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 3
Module 11: Caching Content
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Caching as part of a larger architecture
Region VPC
Public subnet Private subnet Private subnet
Availability
Amazon
Zone 2
CloudFront
NAT gateway EC2 instances ElastiCache Amazon RDS Amazon EFS
for standby mount
Internet Memcached instance target
gateway
Application Amazon EC2 Amazon
Load Balancer Auto Scaling EFS
Amazon
Route 53 Public subnet Private subnet Private subnet
Availability
Zone 1
The capacity of the café’s infrastructure is constantly being overloaded with the same
requests. This inefficiency is increasing cost and latency.
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 6
Module 11: Caching Content
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Caching: Trading capacity for speed
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 8
Cache example (1 of 2)
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 9
Cache example (2 of 2)
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 10
What should you cache?
Relatively static and frequently accessed data—for example, a profile for your
social media website
Information that can be stale for some time, such as a publicly traded stock
price
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 11
Benefits of caching
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 12
Caching throughout the data journey
Data
</>
Web
Users content
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 13
• A cache provides high throughput, low-
Section 2 key latency access to commonly accessed
takeaways application data by storing the data in
memory
• When you decide what data to cache,
consider speed and expense, data and
access patterns, and your application’s
tolerance for stale data
• Caches can be applied and used
throughout various layers of technology,
including operating systems, networking
layers, web applications, and databases
14 © 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Module 11: Caching Content
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Network latency
Hop
Router
Hop Hop
Origin server
Hop
Router
Router
Hop
Hop
Client
Router Hop
User
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 16
Content delivery network (CDN)
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 17
Amazon CloudFront
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 18
What type of content can you cache in an
edge cache?
Dynamic Web
objects
Can be
cached!
Image
Can be Video
cached! Can be
cached!
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 19
How caching works in Amazon CloudFront
Edge
location
Cached copies
of objects
User requests content Origin server
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 20
How to configure a CloudFront distribution
• Access
MediaPackage MediaStore • Security
channel container • Cookie or
query-string
forwarding
Web server • Geo-restrictions
or other • Access logs
custom origin
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 21
How to expire content
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 22
Example: Video on demand streaming
AWS Cloud
Input video
converted Converted Dynamic
into multiple output stored stream
output formats in S3 bucket delivered
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 23
Example: Dynamically generated content
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 24
Example: DDoS mitigation
AWS Cloud
VPC
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 25
• Amazon CloudFront is a global CDN service that
Section 3 key accelerates the delivery of content, including static
and video, to users with no minimum usage
takeaways commitments.
• CloudFront uses a global network that comprises
edge locations and regional edge caches to deliver
content to your users.
• To use CloudFront to deliver your content, you
specify an origin server and configure a CloudFront
distribution. CloudFront assigns a domain name
and sends your distribution’s configuration to all of
its edge locations.
• You can use Amazon CloudFront to improve the
resilience of your applications that run on AWS
from DDoS attacks.
26 © 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Module 11 – Guided
Lab: Streaming
Dynamic Content
Using Amazon
CloudFront
27 © 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Guided lab: Scenario
In this lab, you use Amazon Elastic Transcoder to convert a source video into
multiple bitrates. You use Amazon CloudFront to deliver the dynamic,
multiple bitrate stream to a connected device by using Apple HTTP Live
Streaming (HLS) protocol.
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 28
Guided lab: Tasks
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 29
Guided lab: Final product
AWS Cloud
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 30
~ 30 minutes
Begin Module 11 –
Guided Lab: Streaming
Dynamic Content
Using Amazon
CloudFront
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 31
Guided lab
debrief:
Key takeaways
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 32
Module 11: Caching Content
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Session management: Sticky sessions
Sticky sessions
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 34
Instead of sticky sessions:
Persist sessions inside a distributed cache
AWS Cloud
Elastic Load
Availability Zone 1 Balancing Availability Zone 2
Loss of sessions
is a risk if sessions
Auto Scaling group are stored locally
Web server Web server on nodes
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 35
Instead of sticky sessions:
Persist sessions inside a DynamoDB table
AWS Cloud
Elastic Load
Availability Zone 1 Balancing Availability Zone 2
Loss of sessions
is a risk if sessions
Auto Scaling group are stored locally
Web server Web server on nodes
Persist sessions
in an Amazon
DynamoDB
database Amazon DynamoDB Amazon DynamoDB
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 36
Example: Storing session states for an online
gaming application
AWS Cloud
Availability Zone 1
Amazon
DynamoDB
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 37
• Sessions are used to manage user
Section 4 key authentication and store user data while
takeaways the user interacts with the application.
• You can manage sessions with sticky
sessions, which is a feature of Elastic Load
Balancing load balancers. Sticky sessions
route requests to the specific server that’s
managing the user’s session.
• You can also manage sessions by persisting
session data outside the web server
instance—for example, in a distributed
cache or DynamoDB table.
38 © 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Module 11: Caching Content
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
When should you cache your database?
You are concerned about You have a high volume of You would like to reduce
response times for your requests that are your database costs.
customer. inundating your database.
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 40
Using DynamoDB for state information
Use case: Online gaming application
Problem: Need faster DB response time
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 41
Amazon DynamoDB Accelerator
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 42
Using DynamoDB with DAX to accelerate
response time
DAX
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 43
Remote or side caches
Cache
2 Read
Application Database
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 44
Amazon ElastiCache
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 45
Redis and Memcached
Amazon
ElastiCache
ElastiCache ElastiCache
for Memcached for Redis
Scales up to 20 nodes Scales up to 250 nodes
per cluster per cluster
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 46
Memcached versus Redis comparison
Feature Memcached Redis
Persistence No Yes
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 47
ElastiCache components
Cache nodes
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 48
Caching strategies: Lazy loading
def get_user(user_id):
# Check the cache
record = cache.get(user_id)
if record is None:
# Run a DB query
record = db.query(“select * from users where id = ?”, user_id)
# Populate the cache
cache.set(user_id, record)
return record
Amazon
ElastiCache
Cache hit
1 Cache miss
2 Read
Application Database
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 50
Adding TTL
Application
servers
Cluster
X 2
After the TTL expires,
the application queries
the database for data.
Amazon
ElastiCache
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 51
Three-tier web hosting architecture
Amazon Amazon
Route 53 CloudFront
Region
Availability Zone A Availability Zone B
Elastic Load
Public subnet Balancing Public subnet
Amazon S3
Presentation layer
with web servers Auto Scaling group Auto Scaling group
Persistence layer
Amazon ElastiCache Primary DB instance Standby DB instance
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 52
• A database cache supplements your
Section 5 key primary database by removing
unnecessary pressure on it, typically in the
takeaways form of frequently accessed read data
• DAX is a fully managed, highly available,
in-memory cache for DynamoDB that
delivers a performance improvement of
up to 10 times—from milliseconds to
microseconds
• Amazon ElastiCache is a side cache that
works as an in-memory data store to
support the most demanding applications
that require sub-millisecond response
times
53 © 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Module 11: Caching Content
Module wrap-up
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Module summary
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 55
Complete the knowledge check
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 56
Sample exam question
A company is developing a highly available web application that uses stateless web
servers. Which services are suitable for storing session state data? (Select TWO.)
A. Amazon CloudWatch
B. Amazon DynamoDB
C. Elastic Load Balancing
D. Amazon ElastiCache
E. AWS Storage Gateway
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 57
Thank you
© 2020 Amazon Web Services, Inc. or its affiliates. All rights reserved. This work may not be reproduced or redistributed, in whole or in part, without prior written permission from Amazon
Web Services, Inc. Commercial copying, lending, or selling is prohibited. Corrections or feedback on the course, please email us at: [email protected]. For all other
questions, contact us at: https://aws.amazon.com/contact-us/aws-training/. All trademarks are the property of their owners.