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 ye...
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
● HyperBek HAL+JSON
○ Hypermedia-aware HAL+JSON client
○ Open Source
● Apple NSURLConnection APIs
○ Accepts gzipped encode...
Supporting Architecture
Media Platform
(Channel Programming, MetaData)
Media Service/API
(Content Metadata)
Content Delivery Network
(Streaming, O...
Lampo Media Service
Media Service
● Read-only (GET requests)
● REST API
○ Hypermedia-Driven
○ HAL+JSON media type
○ Abstracts away media vendo...
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… that’s not quite right… or is it?
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 h...
HTTP Caching
GET /feed
Cache-Control: stale-while-revalidate=300,
stale-if-error=300
…
GET /media/channel/tdrs/
Cache-Cont...
Media Platform
(Channel Programming, MetaData)
Media Service/API
(Content Metadata)
Content Delivery Network
(Streaming, O...
(from the Vendor’s 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 a...
One more thing...
Media Service Today
Implementation fully bundles all resources in
root resource by default, via HAL+JSON...
Questions? Comments?
“Cache is King”
Resources
● MNot’s Caching Tutorial: http://www.mnot.net/cache_docs/
● MNot’s stale-while-revalidate/stale-if-error: http:...
Thanks!
Twitter: @philharvey
Email: phil.harvey@daveramsey.com
HTTP Caching For The Win - REST Fest 2013
HTTP Caching For The Win - REST Fest 2013
HTTP Caching For The Win - REST Fest 2013
Upcoming SlideShare
Loading in …5
×

HTTP Caching For The Win - REST Fest 2013

1,246 views

Published on

My five minute talk given at REST Fest 2013 in Greenville, SC.

Published in: Technology
0 Comments
2 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,246
On SlideShare
0
From Embeds
0
Number of Embeds
50
Actions
Shares
0
Downloads
0
Comments
0
Likes
2
Embeds 0
No embeds

No notes for slide

HTTP Caching For The Win - REST Fest 2013

  1. 1. HTTP Caching FTW A Brief Project Retrospective
  2. 2. Phil Harvey Web Developer/Architect The Lampo Group, Inc. (Dave Ramsey) http://developwithpurpose.com
  3. 3. Background
  4. 4. ● 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
  5. 5. What Could Be Next?
  6. 6. Online Video Channel ● Take the Dave Ramsey Show to a new format (online video) ● HD video ● Accessible via mobile and web
  7. 7. User Experience: Native iOS App
  8. 8. ● 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
  9. 9. Supporting Architecture
  10. 10. 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
  11. 11. Lampo Media Service
  12. 12. 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
  13. 13. Launch Week Stats Approx. 20k app downloads within first 24h Approx. 73TB video served per day by CDN
  14. 14. Average RPM to Media Service... (RPM = Requests Per Minute)
  15. 15. 6-8 RPMs Wait… that’s not quite right… or is it?
  16. 16. Challenge: Stale cache causes requests to block until fresh content is served
  17. 17. Solution: stale-while-revalidate
  18. 18. 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}
  19. 19. 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"
  20. 20. 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
  21. 21. (from the Vendor’s feed API) Challenge: Flaky Last-Modified response headers
  22. 22. Solution: Generate ETag based on vendor response (using MurmurHash3)
  23. 23. Why MurmurHash3 ● Super fast (vs MD5, SHA1) ● Generally low collisions/highly distributive ● Java implementation readily available (Google Guava library)
  24. 24. One more thing... Media Service Today Implementation fully bundles all resources in root resource by default, via HAL+JSON’s _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
  25. 25. Questions? Comments?
  26. 26. “Cache is King”
  27. 27. Resources ● MNot’s Caching Tutorial: http://www.mnot.net/cache_docs/ ● MNot’s 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/
  28. 28. Thanks! Twitter: @philharvey Email: phil.harvey@daveramsey.com

×