Forum: Ruby on Rails db vs filesystem

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Martin K. (Guest)
on 2006-02-10 12:57
(Received via mailing list)
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
###################################################################
Jeroen H. (Guest)
on 2006-02-10 13:51
(Received via mailing list)
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
David M. (Guest)
on 2006-02-10 15:41
(Received via mailing list)
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.
Tom M. (Guest)
on 2006-02-10 20:19
(Received via mailing list)
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.
Dylan S. (Guest)
on 2006-02-10 21:22
(Received via mailing list)
I've been using the "file_column" plugin, and recommend it for storing
images.  It's fast, and easy to setup.
This topic is locked and can not be replied to.