Peek behind the scenes to learn about Amazon ElastiCache's design and architecture. See common design patterns of our Memcached and Redis offerings and how customers have used them for in-memory operations and achieved improved latency and throughput for applications. During this session, we review best practices, design patterns, and anti-patterns related to Amazon ElastiCache. We also include a demo where we enable Amazon ElastiCache for a web application and show the resulting performance improvements.
2. Contents
•
•
•
•
•
Caching: What’s all this then?
Amazon ElastiCache
Laziness, impatience, and hubris
From one to a dozen nodes
Memcached vs. Redis showdown
5. Death By 1000 Queries
•
•
•
•
•
Login, session
New messages, recent posts
Calls to Facebook, Twitter APIs
Your friends love the new Coldplay album!!!
Sudden viral traffic spikes
6.
7. cache (noun)
a group of things that have been stored in a secret
place because they are illegal or have been stolen
25. How To Cache It?
• Lazy population
• Write-through
• Timed refresh
26. Laziness is a Virtue
# Python
def get_user(user_id):
record = cache.get(user_id)
if record is None:
# Run a DB query
record = db.query("select * from users where id = ?", user_id)
cache.set(user_id, record)
return record
# App code
user = get_user(17)
27. Ship It
•
•
•
•
•
Most data is never accessed
Ensures cache is filled
Caches fail and scale
But cache miss penalty
Best approach for most data
28. Foresight is 20-20
# Python
def save_user(user_id, values):
record = db.query("update users ... where id = ?", user_id, values)
cache.set(user_id, record)
return record
# App code
user = save_user(17, {"name": "Nate Dogg"})
29. Laziness vs. Impatience
•
•
•
•
•
Ensures cache is always current
Write penalty vs. read penalty
But missing data on scale up
Plus excess data / cache churn
Still need lazy fetch too
30. Combo Move!
def save_user(user_id, values):
record = db.query("update users ... where id = ?", user_id, values)
cache.set(user_id, record, 300) # ttl
return record
def get_user(user_id):
record = cache.get(user_id)
if record is None:
record = db.query("select * from users where id = ?", user_id)
cache.set(user_id, record, 300) # ttl
return record
# App code
save_user(17, {"name": "Nate Diddy"})
user = get_user(17)
31. Timed Refresh
•
•
•
•
Run job to periodically update cache
Good for Top-N lists
Time-intensive rankings
Trending items