# How to handle uploaded files in HA cluster?

**URL:** <https://www.ruby-forum.com/t/how-to-handle-uploaded-files-in-ha-cluster/134643>\
**Category:** Rails\
**Created:** [April 13, 2008, 10:17am UTC](https://www.ruby-forum.com/t/how-to-handle-uploaded-files-in-ha-cluster/134643 "2008-04-13T10:17:33Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![durchanek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5f8ce5/32.png) [@durchanek](https://www.ruby-forum.com/u/durchanek)\
**Post date:** [April 13, 2008, 10:17am UTC](https://www.ruby-forum.com/t/how-to-handle-uploaded-files-in-ha-cluster/134643/1 "2008-04-13T10:17:33Z")

</div>

Hi,  
i am planning to build HA cluster for rails applications, using  
guideline

> **[How to build a state-of-the-art rails cluster](https://www.slideshare.net/tim.lossen.de/how-to-build-a-stateoftheart-rails-cluster)**
>
> How to build a state-of-the-art rails cluster Tim Lossen Infopark AG, Berlin You mean ... like this? System X â€¢ Virginia Tech â€¢ 1100 x App...

from Tim Loosen.

Database replication should be easy with MySQL, I am currently using  
master-slave replication for backups, so configuring master-master  
wouldn’t be a big deal (as I hope). But I am wondering how to handle  
file uploads?  
First way which come into me mind was cross-exporting upload  
directories via NFS and slightly modifying file\_column plugin.  
Another way is to store files in database, so MySQL replication will  
be used and than perform some way of caching (reading big files from  
database again and again doesn’t look like a good idea to me).

Any ideas how to solve this?

Regards

Láïa

---

<div class="post-metadata">

**Author:** ![durchanek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5f8ce5/32.png) [@durchanek](https://www.ruby-forum.com/u/durchanek)\
**Post date:** [April 13, 2008, 3:43pm UTC](https://www.ruby-forum.com/t/how-to-handle-uploaded-files-in-ha-cluster/134643/2 "2008-04-13T15:43:03Z")

</div>

Use Amazon S3.

Then you are clustering DB but don’t need to cluster/replicate FS.

It’s not a good idea to keep files in the DB as a rule. Of course, you  
_can_, but you’d have to really think through it.

-Danimal

---

<div class="post-metadata">

**Author:** ![durchanek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5f8ce5/32.png) [@durchanek](https://www.ruby-forum.com/u/durchanek)\
**Post date:** [April 13, 2008, 8:51pm UTC](https://www.ruby-forum.com/t/how-to-handle-uploaded-files-in-ha-cluster/134643/3 "2008-04-13T20:51:30Z")

</div>

On Apr 13, 2008, at 1:16 AM, durchanek wrote:

> First way which come into me mind was cross-exporting upload  
> directories via NFS and slightly modifying file\_column plugin.  
> Another way is to store files in database, so MySQL replication will  
> be used and than perform some way of caching (reading big files from  
> database again and again doesn’t look like a good idea to me).
> 
> Any ideas how to solve this?

Never _ever_ store images in the database especially if you are doing  
replication or master master, sotring images in the db is very  
inefficient and will completely hose replication on the regular.

NFS can work but has locking issues and is not POSIX compliant and is  
also fairly slow. If you have a SAN then you can use GFS from the red  
hat cluster suite to get a posix compliant clustered filesystem.

Cheers-

- Ezra Z.  
– Founder & Software Architect  
– removed\_email\_address@domain.invalid  
– [EngineYard.com](http://EngineYard.com)

---

<div class="post-metadata">

**Author:** ![durchanek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5f8ce5/32.png) [@durchanek](https://www.ruby-forum.com/u/durchanek)\
**Post date:** [April 14, 2008, 12:46pm UTC](https://www.ruby-forum.com/t/how-to-handle-uploaded-files-in-ha-cluster/134643/4 "2008-04-14T12:46:53Z")

</div>

Thanks for replication explanation. GFS looks like a good way, but I  
think that it has two drawbacks:

- introducing another single-point-of-failure
- SAN requirement

I would like to make this happen with two servers only + loadbalancer  
and pretty low-cost - applications are not heavy loaded, but failover  
would be a great feature.  
Is there eg. some way how to replicate directory via rsync/SSH/  
whatever through daemon? There will be only a minimum file-upload  
operations, so having not-so-realtime replication of files would be  
sufficient.

Cheers

Láïa

---

<div class="post-metadata">

**Author:** ![durchanek](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/5f8ce5/32.png) [@durchanek](https://www.ruby-forum.com/u/durchanek)\
**Post date:** [April 14, 2008, 3:05pm UTC](https://www.ruby-forum.com/t/how-to-handle-uploaded-files-in-ha-cluster/134643/5 "2008-04-14T15:05:22Z")

</div>

On Mon, 2008-04-14 at 03:46 -0700, durchanek wrote:

> operations, so having not-so-realtime replication of files would be  
> sufficient.

How about using something like:

> **[mogilefs](https://github.com/mogilefs/)**
>
> mogilefs has 6 repositories available. Follow their code on GitHub.
