0% found this document useful (0 votes)
115 views58 pages

AcademyCloudArchitecting Module 11

Uploaded by

Gursharan Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
115 views58 pages

AcademyCloudArchitecting Module 11

Uploaded by

Gursharan Singh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

AWS A cad emy Clou d A rc h itec tin g

Module 11: Caching Content

© 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

At the end of this module, you should be able to:


• Identify how caching content can improve application performance and reduce
latency
• Identify how to design architectures that use edge locations for distribution and
distributed denial of service (DDoS) protection
• Create architectures that use Amazon CloudFront to cache content
• Recognize how session management relates to caching
• Describe how to design architectures that use Amazon ElastiCache

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 3
Module 11: Caching Content

Section 1: Architectural need

© 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

NAT gateway EC2 instances ElastiCache Amazon RDS Amazon EFS


Users Static for primary mount
website Memcached instance target
on S3
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 5
Café business requirement

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

Section 2: Overview of caching

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Caching: Trading capacity for speed

• Is a high-speed data storage layer


• Stores a subset of data
• Increases data retrieval
performance
• Reduces the need to access the
underlying slower storage layer

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 8
Cache example (1 of 2)

Travel time = 30 minutes

Your house Hardware


store

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 9
Cache example (2 of 2)

Travel time = 2 minutes

Your house Storage unit Hardware


store

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 10
What should you cache?

Data that requires a slow and expensive query to acquire

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

Improves application Reduces response Reduces database


speed latency access time

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 12
Caching throughout the data journey

Data

</>

Desktop Mobile Internet Application Database


or edge server

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

Section 3: Edge caching

© 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)

• Is a globally distributed system of caching servers


• Caches copies of commonly requested files (static content)
• Delivers a local copy of the requested content from a nearby cache edge or
Point of Presence
• Improves application performance and scaling

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 17
Amazon CloudFront

• Is the Amazon global CDN


• Is optimized for all delivery use cases, with a
multi-tier cache by default and extensive
flexibility
• Provides an extra layer of security for your
architectures
Amazon • Supports WebSockets and HTTP or HTTPS
CloudFront
methods

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 18
What type of content can you cache in an
edge cache?

Secure User input

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

1. Request is routed to the 2. Non-cached content is


most optimal edge location retrieved from the origin server

Edge
location

Cached copies
of objects
User requests content Origin server

4. Data is transferred to the 3. Origin server sends content


user to the edge location for caching

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 20
How to configure a CloudFront distribution

1. You specify an 2. You configure


the distribution
3. CloudFront
4. CloudFront sends
origin server assigns a your distribution’s
domain configuration to
name edge locations

S3 bucket EC2 instance

• 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

• Time to Live (TTL) –


• Fixed period of time (expiration period)
• Set by you
• GET request to origin from CloudFront uses If-Modified-Since header
• Change object name –
• Header-v1.jpg becomes Header-v2.jpg
• New name forces immediate refresh
• Invalidate object –
• Last resort: inefficient and expensive

© 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

Source AWS Elemental Amazon S3 Amazon User mobile


content MediaConvert CloudFront device

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 23
Example: Dynamically generated content

Use case: Map tiles


Problem: Need faster DB response time

User submits request to look at


a section of a map
(not cacheable)

Amazon Elastic Load EC2 instances


CloudFront Balancing run your
application

Application processes user request


and dynamically generates content
(cacheable)

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 24
Example: DDoS mitigation

AWS Cloud
VPC

Public subnet Private subnet


DDoS
attack X
AWS WAF Amazon Security group Security group
CloudFront

Elastic Load Web application


Balancing EC2 instances
Amazon
Users Route 53

© 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.

Amazon Elastic Amazon


Transcoder CloudFront

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 28
Guided lab: Tasks

1. Create an Amazon CloudFront distribution


2. Create an Amazon Elastic Transcoder pipeline
3. Test playback of the dynamic (multiple bitrate) stream

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 29
Guided lab: Final product

AWS Cloud

Input file is used to Transcoded (HLS) Dynamic


create an Elastic output stored in stream
Transcoder job S3 output bucket delivered

S3 input Amazon Elastic S3 output CloudFront User mobile


bucket with Transcoder bucket streaming device
.mp4 media file distribution

© 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

Section 4: Caching web sessions

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Session management: Sticky sessions

Feature that enables a load balancer to


Elastic Load Balancing route a request to the specific server that
manages the user’s session.

• Use client-side cookies


• Are cost-effective
• Speed up retrieval of sessions
• Have disadvantages –
• Loss of sessions when you have an instance failure
• Limit scalability: Uneven load distribution and
increased latency

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

Cache cluster Cache cluster


Persist sessions
CACHE CACHE CACHE CACHE
in a distributed
cache

© 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

Auto Scaling group Auto Scaling group


Amazon
DynamoDB

Game requests Web server Game server


Availability Zone 2
Players Elastic Load
Balancing

Amazon
DynamoDB

Web server Game server

© 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

Section 5: Caching databases

© 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

Session state information


stored in Amazon DynamoDB

Millisecond-scale response time

Amazon Application Web Game


CloudFront Load Balancer servers servers

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 41
Amazon DynamoDB Accelerator

Fully managed, highly available, in-memory cache


for DynamoDB

• Extreme performance (microsecond-scale response time)


• Highly scalable
• Fully managed
• Integrated with DynamoDB
Amazon • Flexible
DynamoDB • Secure
Accelerator

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 42
Using DynamoDB with DAX to accelerate
response time

Session state information


stored in Amazon DynamoDB

Microsecond-scale response time

DAX

Amazon Application Web Game


CloudFront Load Balancer servers servers

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 43
Remote or side caches

Cache hit: Data found in cache


Cache miss: Data not found in cache

Cache

2 Read

Application Database

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 44
Amazon ElastiCache

ElastiCache provides web applications with an


in-memory data store in the cloud.

• Works an in-memory data store and cache


• Offers high performance
• Is fully managed
• Is scalable
Amazon
• Supports Redis and Memcached
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

Sub-millisecond latency Yes Yes

Ability to scale horizontally for writes and storage Yes No

Multi-threaded performance Yes No

Advanced data structures No Yes

Sorting and ranking datasets No Yes

Publish/subscribe messaging No Yes

Multi-AZ deployments with automatic failover No Yes

Persistence No Yes

© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 47
ElastiCache components

Cluster • A node is the smallest block


of an ElastiCache deployment

• Each node has its own DNS


name and port

• A cluster is a logical grouping of


Amazon one or more nodes
ElastiCache

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 3 Write Database


© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 49
Caching strategies: Write-through
def save_user(user_id, values):
# Save to DB
record = db.query(“update users…where id = ?”, user_id, values)
# Push into cache
cache.set(user_id, record, 300) # TTL
return record
Amazon
ElastiCache

Application Database
© 2020 Amazon Web Services, Inc. or its Affiliates. All rights reserved. 50
Adding TTL

Application
servers

A TTL value is added to


1 Database
each application write.

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

Private subnet Private subnet


Elastic Load
Application layer with Auto Scaling group Balancing Auto Scaling group
backend servers

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

In summary, in this module, you learned how to:


• Identify how caching content can improve application performance and reduce latency
• Create architectures that use Amazon CloudFront to cache content
• Identify how to design architectures that use edge locations for distribution and
distributed denial of service (DDoS) protection
• Recognize how session management relates to caching
• Describe how to design architectures that use Amazon ElastiCache

© 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.

You might also like