views:

150

answers:

1

Does anyone have ideas for a strategy to push content to a CDN upon deployment?

The key issue I'm facing is that we have a site that is available in various contexts: local development, development server, staging, then finally live.

The liver version of the site needs to load assets from a domain, which will be pointed to a CDN: assets.domain.com.

However, we will have numerous references to the assets pointing to a relative folder, e.g. /images/ in css, possibly in js, and in HTML & source.

Our new site will use capistrano for deployment and it may be that we can hook in another build tool (apache ant?) or some custom script to search / replace paths.

I am wondering if anyone has had to deal with this issue before and what solutions you put in place to automate managing the CDN in terms of pushing content up to the CDN and managing html & css references to assets in the CDN.

Thanks

Imanc

+1  A: 

Generally speaking, CDNs use pull-based caching, not push-based replication.

This is because pushing a large (considering all of their customers) amount of content into any significant number of distributed nodes is a difficult distributed systems problem, and anticipating future traffic patterns to optimise that distribution is even more difficult.

While some (e.g., Akamai) do offer the ability to invalidate content in the network, it's usually considered a 'panic switch' rather than something that you can integrate into your deployment process.

Some may also offer 'staging servers' that you can push your content onto, but it really isn't going into the CDN; rather, the CDN will just pull content from their own servers as traffic happens. This might be adequate for what you want (usually they offer FTP, SSH and other interfaces).

Otherwise, your best bet is to wait for the TTLs you've set (e.g., Cache-Control: max-age) to time out and the content to get refreshed, when the content is backwards-compatible, or to change the URLs when it isn't.

Mark Nottingham
Many thanks, Mark. I guess I need to actually get some documentation for a CDN and figure out how we can make it work with our deployment process. At the beginning we're going to be mapping an assets sub domain back to our web server and using that for CDN content. This gives us a contingency plan for if the site needs to scale. In this situation we would need to push data to it, perhaps using a shell script and rsync and in the deployment process we would have to scan css files etc. to map local directory assets e.g. /assets/images/img1.jpg to assets.mydomain.com/assets.