Can I Please Store Images in the Database Now?
Can I Please Store Images in the Database Now?
Years ago, DBAs frowned upon the use of BLOB data types within a relational database. Consider if this is still the case or if it's finally okay to store images in the database.
Join the DZone community and get the full member experience.Join For Free
Read the 2019 State of Database DevOps Report for the very latest insights
When the relational database wars reached their high point in the 1990s, it seemed like every trade magazine was filled with advertisements where one database provider was comparing their features or performance metrics against the other key players. Back then, it was common to see IBM, Oracle, Microsoft, Informix, and even Sybase take jabs at each other over the course of a given release cycle. I often grew tired of those comparison grids always favoring the vendor who paid for the advertisement, only to find conflicting results in a competitor’s advertisement a few pages away.
One of the features that became popular during that time was the BLOB (binary large object). This data type paved the way for multimedia items (like images, videos, or audio) to be stored within a record in the database. As a programmer, I became excited about this possibility... until the database administrators (DBAs) shot down the idea. In fact, we were told to store the multimedia data in the file system, then store some type of link to the file system location in a VARCHAR field for the record referencing the image.
Since the DBAs knew the database far better than I did, I listened. In fact, I always kept this in mind.
While on a project that utilizes a great deal of multimedia content, I was surprised to notice that the application currently stores the multimedia items within the database. Using BLOB fields in the table, the images that related to a given record were stored directly in the database table. I was reminded back to the legions of DBAs who made it clear that this approach was not appropriate.
So, I thought I better bring this to the attention of my client. After all, I worried about the potential performance issues we could face with all of this multimedia information in the database. I mean, there are tens of thousands of users for the application, each using a lot of BLOB data.
This could be a nightmare in the making.
Doing a Little Research First
Before scheduling time with the development lead, I decided to gather some facts regarding the use of BLOBs. I was certain that the direction given to me years ago would be easy to locate — providing all the necessary information needed to invalidate a design decision that might not hold up to a production load on the application.
Since the client was using Oracle as their database provider, I decided to see what TOM (the Oracle Masters) have to say about this approach. The Ask TOM site was started by former Oracle employee Tom Kyte and was a resource I utilized when working on projects that used Oracle as the database. In fact, Tom Kyte's last 15 years with Oracle were spent answering questions by Oracle database users around the globe. He is now retired.
The following thread basically asked TOM to explain the advantages and disadvantages of storing files within an Oracle database.
Tom Kyte's reply started bluntly...
"I know of no advantages to storing data I want to keep for a long time outside of a database."
He then provided supplemental facts that compliment the concept of storing multimedia content as a BLOB in the database:
Confirm that the information is professionally managed by the database.
Can be backed up and recovered with the associated metadata stored in the same record.
Secured to match the other records on that row.
Scalable, offering the comparison of a file system with 100,000 documents.
Benefits of undelete, locking, and read consistency.
My New View
While I understand that cloud-based file systems provide improvements over the days of using a Windows-based file system to share files, I am amazed at how my view on using BLOBs in the database maintained a dated perspective that was spawned decades earlier. In my own defense, the projects I have worked on since that time rarely have utilized any multimedia data types that offered the opportunity to review the option of using the database to store this information.
However, this learning experience was refreshing and allowed me to see the database at a different level.
What are your thoughts on this topic? Are you using BLOBs in your database design? What lessons have been learned as a result of taking this approach or from avoiding this approach?
Opinions expressed by DZone contributors are their own.