Getting to Second Base With Your CDN

Web Performance
Location: Regency 2 Level: Intermediate
Average rating: ***..
(3.31, 13 ratings)

You’ve got a CDN in place, now what? Static objects are the low-hanging fruit that satisfies immediate needs. You’re probably using a CDN either because the bandwidth is cheaper, or you want your media assets to load faster. So what’s next?

1. Measure your performance. How much bandwidth are you serving from origin, and how much has been offloaded to your CDN? You need to have metrics in place to show the results of ongoing optimizations.

2. Tweak your cache TTLs. If you’ve started with short TTLs because your images, CSS, and JavaScript files switch on occasion, think about making these TTLs very long and implement a strategy for purging items from cache or modifying URLs to force your CDN to pick up new versions when you push code changes.

3. Cache dynamic objects. Static objects are very easy to serve and typically very fast, so your major savings by moving to a CDN is in bandwidth. Dynamic objects are more CPU intensive, so caching these has a bigger impact on the performance of your servers. Think hard about what pages you can or cannot cache (search results, Ajax page fragments, etc.).

4. Cache whole pages. How much content on your pages really changes from user to user? Consider moving user-specific logic to small Ajax calls (i.e. personalization) and cache entire pages. How about ad templates with dynamic code in them? Move this logic to client-side JavaScript.

5. Inspect origin hits. Review how many times your CDN is requesting supposedly cacheable files. Are any slipping through the cracks? Are you double-paying for bandwidth… i.e. every request goes back to your origin, costing you origin bandwidth plus CDN bandwidth? Have you forgotten cache-control headers on some requests? Very large files and infrequently accessed files don’t always stick around on the CDN, so they cause origin hits more often. There may be some big surprises in your server logs.

6. Using proper HTTP headers saves bandwidth. When serving dynamic objects, inspect the if-modified-since request headers and respond with “not modified” whenever possible. This saves origin bandwidth costs and reduces origin response time.

7. Use multiple CDNs. This can be considered a redundancy approach, but can also be a big cost-saver. Stick to a high-performance CDN for your premium and hot content — pages that get requested often or have major advertising or sponsorships around them. Find a cheaper CDN for your archives and non-sponsored content. (I did this at Heavy.com making use of Akamai for premium content, and direct access to Amazon S3 for non-sponsored, even before the announcement of their CloudFront service.) Make sure you can measure each CDN and origin separately, and build controls so you can tweak this easily.

8. Review CDN documentation. Each vendor is different. After you’ve gotten past your initial implementation, take a look back over any additional features you glossed over the first time. There may be some gems in there.

9. Engage your vendor. CDNs are out there fighting for business and need to differentiate themselves from being a commodity industry by providing advanced features and responding to customers. Find your technical contact and have a discussion with them about your application and infrastructure. Tell them what additional features you want, even if they seem absurd.

Photo of Mike Brittain

Mike Brittain

Etsy

Mike Brittain is the Engineering Architect at CafeMom, the largest social networking site for mothers. Mike has been working with front-end and back-end technologies for the last 11 years, specializing in LAMP stacks, start ups, and more recently, cloud computing. He spends much of his day building foundational tools for other developers on the team, working closely with the operations group, managing servers, monitoring performance, and daydreaming about that next big ski trip.

Comments on this page are now closed.

Comments

Picture of Mike Brittain
Mike Brittain
07/16/2009 6:42am PDT

@Vitaly: Mainly the point there is that you want almost all of your requests to serve from cache on the CDN. You pay for delivery between the CDN and the end-user.

If you do not cache your assets well on the CDN, or fail to cache them at all, then with every request for a file you are paying for bandwidth to (1) deliver the asset from your origin server to the CDN and (2) for the delivery from the CDN to the end user. That’s the “double” payment.

When you cache assets properly, the cost of delivery from your origin server to the CDN should be negligible next to the cost from the CDN to the end user.

This applies when using your CDN as a reverse-proxy or “origin pull”.

Vitaly Karasik
07/13/2009 7:47pm PDT

Thanks for great presentation!

Unfortunately, I didn’t understand about which case/solution you speak in “Avoid double paying” slides. Can Mike or someone explain this point?

Thank in advance, Vitaly

Igor Minar
06/25/2009 7:43am PDT

I agree, this topic and Mike deserved a lot more time for the interesting presentation.

Picture of Mike Brittain
Mike Brittain
06/24/2009 5:04am PDT

I’ve posted some tips on selecting a CDN vendor on my site. A little more content that couldn’t be squeezed into my short time slot.

Picture of John Masseria
John Masseria
06/23/2009 8:49am PDT

Great session, I wish Mike had been given more time to talk about all the points he wanted to discuss!

  • Keynote Systems
  • Google
  • Shopzilla
  • Aptimize
  • Facebook
  • NeuStar
  • Rackspace Cloud
  • Schooner Information Technology
  • SoftLayer
  • SpringSource
  • Sun Microsystems

Sponsorship Opportunities

For information on exhibition and sponsorship opportunities at the conference, contact Sharon Cordesse at scordesse@oreilly.com

Download the Velocity Sponsor/Exhibitor Prospectus

Media Partner Opportunities

Download the Media & Promotional Partner Brochure (PDF) for information on trade opportunities with O'Reilly conferences or contact mediapartners@ oreilly.com

Press and Media

For media-related inquiries, contact Maureen Jennings at maureen@oreilly.com

Velocity Newsletter

To stay abreast of conference news and to receive email notification when registration opens, please sign up for the Velocity Conference newsletter (login required)

Contact Us

View a complete list of Velocity contacts