Quote:
|
Originally Posted by amthomas
but I would still appreciate reasons as to why it is good to store multimedia, specifically images, in a db.
|
Well, everyone claims that there are no good reasons for storing images and such in the RDBMS. So I guess my position that there are perfectly good reasons for storing binary data in the RDBMS is a minority position.
Mind you, it's a position that every single DBMS vendor happens to agree with, given that they all took the time to add BLOB support. And I guess the developers of the SQL standard also agree with me, since they wrote up the BLOB specs.
All of the reasons to put images and such in the DBMS boil down to one fact: the filesystem is also a DBMS (technically, a network DBMS) and it sucks.
1. Interfacing with one DBMS is complicated enough. Interfacing with two adds more complexity, more limitations and more ways your application can fail.
2. Keeping two DBMSs in synch, especially when one of them has no built in capabilities for synchronizing with anything, adds more complexity to your application. You have to write code to find "orphans" and your code has to work around the fact that a file might mysteriously disappear.
3. The only thing a file system is good at is copying files. And it's not generally even very good at that. For example, it's easy to use JDBC to send a database request over a proxy without the application even caring. You can probably do that with your filesystem, but at the expense of more code complexity and you're going to have to configure two transports.
4. Filesystems are notoriously bad at locking. Unix, for example, has "advisory" locks. And if you want to integrate file system locking with DBMS locking, you get more code complexity.
5. Journaling is considered an advanced feature on file systems, and generally only applies to metadata.
5a. Speaking of which, the filesystem metadata is almost invariably useless baggage as far as you're concerned. And if you rely on it, for example, last modified dates, you get more code complexity.
6. Filesystems are designed for different parameters than DBMSs. For example, if you format a hard disk with NTFS, you expect that you can plug it in to another computer and it just works. It might have to share its on disk structures with drivers running on a different operating system written by someone else entirely. A DBMS can optimize its structures for one server written by one group running on one operating system using one binary layout.
6a. And let's also note that you can fine tune your DBMS far more than you can fine tune your filesystem. And if you're fine tuning your file system, you're doubling your work again.
7. A DBMS generally has utilities to handle backups. Now that you're using the filesystem, you have to synchronize two backup operations.
8. If you want your database to be stored on a partition, you have to guess how much space to reserve for the database and the file system.
9. Scaling up your application becomes more complicated when you're scaling a DBMS and a file system.
It certainly sounds easier to stash stuff in the filesystem, and for a quick and dirty solution, it often is. I've done it. Many times you really don't care too much if multimedia for a web site is kept in synch properly; you can write a quick script to delete orphans and if a web server doesn't find an image for whatever reason it fails gracefully.
But if you are concerned with the sorts of things people who use DBMSs are concerned with then a filesystem has all the weaknesses of a crappy DBMS.