# \[OT\] sync of static resources in shared-nothing architecture

**URL:** <https://www.ruby-forum.com/t/ot-sync-of-static-resources-in-shared-nothing-architecture/76168>\
**Category:** Rails\
**Created:** [November 16, 2006, 11:39am UTC](https://www.ruby-forum.com/t/ot-sync-of-static-resources-in-shared-nothing-architecture/76168 "2006-11-16T11:39:23Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [November 16, 2006, 11:39am UTC](https://www.ruby-forum.com/t/ot-sync-of-static-resources-in-shared-nothing-architecture/76168/1 "2006-11-16T11:39:23Z")

</div>

If we have the setup 1 balances N web-servers 1 database server, and  
users my upload resources like an image, how do you sync the public  
directories?

– fxn

---

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [November 16, 2006, 3:03pm UTC](https://www.ruby-forum.com/t/ot-sync-of-static-resources-in-shared-nothing-architecture/76168/2 "2006-11-16T15:03:53Z")

</div>

From my recent blog post on the topic, [http://www.bencurtis.com/](http://www.bencurtis.com/)  
archives/2006/11/how-to-handle-uploaded-files-with-rails/, use rsync:

rsync -cure ssh /source/path/ destination\_server.com:/destination/path/

Assuming you can log in to the other box via SSH keys, this rsync  
command can be put in a cron job or triggered by a directory watcher  
to keep one or more other hosts in sync with the master upload  
directory.

–  
Building an e-commerce site with Rails?  
[http://www.agilewebdevelopment.com/rails-ecommerce](http://www.agilewebdevelopment.com/rails-ecommerce)

---

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [November 16, 2006, 5:06pm UTC](https://www.ruby-forum.com/t/ot-sync-of-static-resources-in-shared-nothing-architecture/76168/3 "2006-11-16T17:06:34Z")

</div>

> If we have the setup 1 balances N web-servers 1 database server, and  
> users my upload resources like an image, how do you sync the public  
> directories?

While our users don’t upload content, our content folks do. Our setup  
looks like this:

N web servers  
1 content admin server (same as web, just dedicated to our staff)  
1 master media server  
4 media slaves

When staff upload an image/video/pdf/flash/etc via the content admin  
server it then re-posts it to the master media server which stores on  
disk, then “tickles” (via curl) each of the slaves to request that url.  
The slaves are configured with an error handler such that if they don’t  
have the the resource they fetch it from the master and then redirect to  
itself.

This way 99% of the time images are immediately spread to all the  
slaves,  
but on the off chance they aren’t, the slaves can still fetch it when  
someone requests it.

We’ve found that curl is fast enough that the fetch-then-redirect-to-m  
yself isn’t noticable…

-philip

---

<div class="post-metadata">

**Author:** ![fxn](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/f/77aa72/32.png) [@fxn](https://www.ruby-forum.com/u/fxn)\
**Post date:** [November 16, 2006, 4:02pm UTC](https://www.ruby-forum.com/t/ot-sync-of-static-resources-in-shared-nothing-architecture/76168/4 "2006-11-16T16:02:45Z")

</div>

You might also consider putting the shared static resources on an  
central file store, and mounting that volume by NFS on all your web  
servers. With Lingr ([http://www.lingr.com](http://www.lingr.com)), for example, images that  
users upload go onto an NFS-mounted volume that physically lives on the  
database server.
