CDN Rerouting on 404 (file not yet in synch with original storage)

Posted by Alan Ristic on Server Fault See other posts from Server Fault or by Alan Ristic
Published on 2010-02-11T09:34:52Z Indexed on 2010/03/17 16:01 UTC
Read the original article Hit count: 303

Filed under:
|
|
|

Here is the problem. I've setup my app(on EC2) to store uploaded images directly on Amazon S3. I'd like to be able to serve static files(cdn) from my 'home' server so I wrote script that does sync from S3. But there is a window of (at least) one minute in synch.

Now I see two solutions on the problem of pics not been available on 'home' server here: 1.I write script on EC2 (where the app resides) to fetch from DB pics that have status of "not-yet-synch", which is default state when user uploads picture. The script then does a ping to picture and if it gets OK response, updates DB from "not-yet-synch" to "synch".

2.Prefered solution would be to let apache (in this case) redirect request for an image if it sees 404 (e.g. doesent find image requested) to S3. This way I wouldn't need script from solution 1.

So what approach do you suggest I take in solving this redundancy problem? Or what is practice in production environments?

To further clarify; I'd like so serve images first from 'home' server, if that fails serve them from S3.

Tnx, Alan

© Server Fault or respective owner

Related posts about cdn

Related posts about static-content