Images Belong in the Database

Posted by Sam

Logical Reasons

The more web programming and system administration I do the more I'm convinced that images and other forms of uploaded content belong in the database. I've pretty strongly suspected this for many a years but it's becoming more and more clear that this is just how things need to be. There are many reasons. Some are technical and some are logical, but all signs point to loading images in the database. Below are just a couple.

I'll start with the logical reason first and then get to the technical reasons. Logically all other forms of dynamic content will reside in the database yet programmer after programmer insists on putting images and other uploaded content on the filesystem. Now you've got some content in the database and it's tied to content on the filesystem. Suddenly the nice clean line is broken. You've blurred the lines on who does what and where it goes. What usually happens is programmers forget to clean up after themselves so files references are deleted in the database but still exist on the file system. You know why this happens? Because you shouldn't have put it there in the first place. Repeat after me - dynamic content in the database and application files in the filesystem. Got it?

Technical Reasons

So know that we've got the logical reasons behind us what are some of the technical reasons? For starters your database(s) will always be in sync. That's what they are meant to do. That's what they have to do. Your database(s) have to be synchronized. Your site depends on it. It doesn't matter if it's a simple site with a single database server or a huge site with a dozen database servers. You have to keep your database servers in sync. And databases are good at it. It's much much easier to scale out database servers than file servers. Having all your dynamic content in the database keeps everything in sync.

Some people will wrongly argue that having files in the database will cause slowdowns. To that I say....um maybe, but only if you're doing it wrong. Databases are very fast and have excellent caching but it's highly likely that multiple web servers can server images straight from disk faster than a database. Well that's great, but images still belong in the database. And in this case you can have your cake and eat it too. Check out this article about caching images on the file system with Rails. Hrm, one extra line of code lets you cache your image on the file system. Doesn't seem to bad to me. Elegant, simple and lightning fast.

The Reason for the Rant

Time after time I'm responsible for deploying other people's crappy software. They invariably come up with some stupid solution that lets them click the checkbox that says their product will work on a load balancer, but they neglect to tell you upfront what ridiculous hoops you have to jump through to get it work. The most recent product is called Ektron. I can't say what it's like to work with from a programming stand point but from an admin stand point it's a nightmare. Instead of loading the images in the database like they should they instead force you to share out files and do this dumb little virtual directory linking to the other servers. It's just annoying and not even close to elegant, but then I have yet to see a CMS system that is so I wasn't surprised. Thankfully the Ruby on Rails team understands what it takes to scale apps and they provide you with a nice foundation. If only the rest of the world would catch up.

Tags: rubyonrails web rant

Bad Christmas Gifts

Posted by Sam

In my last post (Annoying Flash Issues) I referred to the Barkley Holiday site that I was working on. I couldn't really talk about what it was at the time, but we unveiled it last week so I think I can safely publish the site URL on my blog. The site is called the Bad Gift Emporium and it's really bad. On purpose. The idea is you can upload your bad gifts for all the world to see. If you are willing to part with your bad gift you can even trade or sell it on the site. Let me know what you think.

Bad Gift Emporium - Barkley

Tags: web humor

Very impressive snowflake

Posted by Sam

Perhaps the most visible part of my job is keeping dozens of web sites up and running. Some of them are very high profile sites and some of them are very obscure. One of the most surprising sites is a site that my company (Barkley) did several years ago. It's called Make-a-Flake. Year after year it continues to get millions of hits with no marketing of any kind.

The basic idea behind the site is that it tries to replicate the paper snowflakes we all made as kids in grade school. If you've used the site you know how difficult it can be to make a very coo flake and even more difficult if you are trying to recreate a particular design or image. And that brings us to a flake I came across today. The flake is below and if you've ever watched South Park you know exactly what the creator of the flake was making. I count no less than five distinct images carved into this snowflake and the main image is that of Kyle from South Park. Go try and make a snowflake and you will really being to appreciate how difficult this snowflake truly is. Have other great snowflakes? Leave them in the comments.

Kyle Broflovski snowflake

Tags: web