# Db vs filesystem

**URL:** <https://www.ruby-forum.com/t/db-vs-filesystem/53580>\
**Category:** Rails\
**Created:** [February 10, 2006, 11:57am UTC](https://www.ruby-forum.com/t/db-vs-filesystem/53580 "2006-02-10T11:57:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkrauskopf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c37758/32.png) [@mkrauskopf](https://www.ruby-forum.com/u/mkrauskopf)\
**Post date:** [February 10, 2006, 11:57am UTC](https://www.ruby-forum.com/t/db-vs-filesystem/53580/1 "2006-02-10T11:57:36Z")

</div>

Hello mailinglist!

We are currently building a largish community-site, where users are  
going to receive diskspace to upload files and share with each other.

Now we have to decide whether to put these files on the filesystem, or  
in the db as blobs.

The pros and cons we have summed up so far is:

–db–  
faster than filesystem (according to some)  
easier to separate from the webservers, since they only need one  
datastorage that way  
easier to tie to userid and such  
damn big databasedumps

–filesystem–  
faster than db (according to some)  
easily handles big files  
extra complexity to tie users to filenames and directories outside the  
db

Do any of you guys have any experience with this, or for that matter  
any instinctive reactions to the problem?

regards,  
//Martin K.

–  
###################################################################  
A woman is like your shadow; follow her, she flies; fly from her, she  
follows.  
– Chamfort  
###################################################################

---

<div class="post-metadata">

**Author:** ![mkrauskopf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c37758/32.png) [@mkrauskopf](https://www.ruby-forum.com/u/mkrauskopf)\
**Post date:** [February 10, 2006, 12:51pm UTC](https://www.ruby-forum.com/t/db-vs-filesystem/53580/2 "2006-02-10T12:51:38Z")

</div>

Martin K. wrote:

> –db–  
> Do any of you guys have any experience with this, or for that matter  
> any instinctive reactions to the problem?

In the PHP world I have done both options, on mysql and postgresql. I  
have slight preference for filesystem storage. Getting your db and  
database wrappers to play nicely with blobs, can be a little toughbut it  
might be trivial in Rails. And yes, your db backups become very big.  
It’s also nice to be able to ls through the files. I can hardly imagine  
storing and loading blobs from a db is faster. You have to encode/decode  
the whole thing and possibly load it from an external db server as  
opposed to just serving them directly or reading them in from a  
non-documentroot location.

That said, we have a few production sites running that store blobs in  
the database and we generally don’t have any problems. And it is nice to  
not have to worry about folder permissions etc.

HTH

Jeroen

---

<div class="post-metadata">

**Author:** ![mkrauskopf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c37758/32.png) [@mkrauskopf](https://www.ruby-forum.com/u/mkrauskopf)\
**Post date:** [February 10, 2006, 2:41pm UTC](https://www.ruby-forum.com/t/db-vs-filesystem/53580/3 "2006-02-10T14:41:36Z")

</div>

This topic comes up every month or so on this list, so search through  
the archives and you’ll find plenty of discussion of the pros vs. cons  
and various people’s opinions.

A quick summary:

- there are pros and cons (as you’ve already surmised) and no clear  
cut best/worst approach for all situations
- in general most people’s preferences seem to come down to what  
they’ve done before, or how comfortable they are dealing with blobs  
vs. filesystem access in general
- AFAIK, no-one’s released a killer plugin/engine to make one solution  
much easier/faster/simpler/better than the other.

Regards

Dave M.

---

<div class="post-metadata">

**Author:** ![mkrauskopf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c37758/32.png) [@mkrauskopf](https://www.ruby-forum.com/u/mkrauskopf)\
**Post date:** [February 10, 2006, 7:19pm UTC](https://www.ruby-forum.com/t/db-vs-filesystem/53580/4 "2006-02-10T19:19:38Z")

</div>

On Feb 10, 2006, at 2:57 AM, Martin K. wrote:

> damn big databasedumps
> 
> –filesystem–  
> faster than db (according to some)  
> easily handles big files  
> extra complexity to tie users to filenames and directories outside  
> the db
> 
> Do any of you guys have any experience with this, or for that matter  
> any instinctive reactions to the problem?

I agree with the others that there isn’t a clear winner.

I personally prefer the DB route, _unless_ those files need access  
through  
other means, such as WebDAV, SFTP, SCP, etc.

That said, I don’t think the complexity to tie users to filenames and  
directories outside the DB is a big issue if you handle it correctly,  
namely be putting ALL logic to do so where it belongs, in the MODEL.

In fact, you’ll know for certain that you’ve done this properly if you  
can alter just the model and DB schema and SWITCH the storage method  
without altering any controller or view code.

That is the power of OO and MVC programming! Objects mask the  
implementation details from the parts that don’t need to know. 🙂

–  
– Tom M.

---

<div class="post-metadata">

**Author:** ![mkrauskopf](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/c37758/32.png) [@mkrauskopf](https://www.ruby-forum.com/u/mkrauskopf)\
**Post date:** [February 10, 2006, 8:22pm UTC](https://www.ruby-forum.com/t/db-vs-filesystem/53580/5 "2006-02-10T20:22:29Z")

</div>

I’ve been using the “file\_column” plugin, and recommend it for storing  
images. It’s fast, and easy to setup.
