際際滷

際際滷Share a Scribd company logo
HTTP Caching FTW
A Brief Project Retrospective
Phil Harvey
Web Developer/Architect
The Lampo Group, Inc. (Dave Ramsey)
http://developwithpurpose.com
Background
 Hosted by Dave Ramsey
 Focuses on real life & money
 Nationally syndicated radio program
 On the radio for over 20 years
 4.5 million weekly listeners
The Dave Ramsey Show
What Could Be Next?
Online Video Channel
 Take the Dave Ramsey Show to a new
format (online video)
 HD video
 Accessible via mobile and web
User Experience:
Native iOS App
HTTP Caching For The Win - REST Fest 2013
HTTP Caching For The Win - REST Fest 2013
 HyperBek HAL+JSON
 Hypermedia-aware HAL+JSON client
 Open Source
 Apple NSURLConnection APIs
 Accepts gzipped encoded response bodies
 Only base API URL is hard coded
iOS App
Supporting Architecture
Media Platform
(Channel Programming, MetaData)
Media Service/API
(Content Metadata)
Content Delivery Network
(Streaming, On Demand Video)
iOS Native Client, Web App Client
Apache
Memcached
Lampo Media Service
Media Service
 Read-only (GET requests)
 REST API
 Hypermedia-Driven
 HAL+JSON media type
 Abstracts away media vendor-specific feed API
 Strategically bundles/unbundles responses
 Responds faster than media vendor API
 Java/Spring MVC/Tomcat
Launch Week Stats
Approx. 20k app downloads within first 24h
Approx. 73TB video served per day by CDN
Average RPM to Media
Service...
(RPM = Requests Per Minute)
6-8 RPMs
Wait thats not quite right or is it?
HTTP Caching For The Win - REST Fest 2013
Challenge:
Stale cache causes
requests to block until
fresh content is served
Solution:
stale-while-revalidate
HTTP Cache-Control Extensions for Stale Content
 RFC5861
 Authored by Mark Nottingham
 Extends HTTP/1.1 Cache-Control header
Cache-Control:
stale-while-revalidate={max-stale-seconds},
stale-if-error={max-stale-seconds}
HTTP Caching
GET /feed
Cache-Control: stale-while-revalidate=300,
stale-if-error=300

GET /media/channel/tdrs/
Cache-Control: max-age=300
ETag: "5247caf6a9a327864ee1-
3ac0af56e4267cc39593"
Media Platform
(Channel Programming, MetaData)
Media Service/API
(Content Metadata)
Content Delivery Network
(Streaming, On Demand Video)
iOS Native Client, Web App Client
Apache
Memcached
(from the Vendors feed API)
Challenge:
Flaky Last-Modified
response headers
Solution:
Generate ETag based on
vendor response
(using MurmurHash3)
Why MurmurHash3
 Super fast (vs MD5, SHA1)
 Generally low collisions/highly distributive
 Java implementation readily available
(Google Guava library)
One more thing...
Media Service Today
Implementation fully bundles all resources in
root resource by default, via HAL+JSONs
_embedded feature
Media Service Tomorrow
Once HTTP/2.0 is available, all resources can
be unbundled, and clients will transparently
fallback to link relations and GET requests
Questions? Comments?
Cache is King
Resources
 MNots Caching Tutorial: http://www.mnot.net/cache_docs/
 MNots stale-while-revalidate/stale-if-error: http://tools.ietf.
org/html/rfc5861
 RedBot: http://redbot.org (explains caching headers in English)
 MurmurHash3: http://en.wikipedia.org/wiki/MurmurHash
 HyperBek Objective-C Library: https://bitbucket.
org/dcutting/hyperbek
 HTTP/2.0 WG: http://datatracker.ietf.org/wg/httpbis/charter/
Thanks!
Twitter: @philharvey
Email: phil.harvey@daveramsey.com

More Related Content

HTTP Caching For The Win - REST Fest 2013