23
votes

I am writing a new application at the moment and certain entities in the application have images (just used for display purposes on the website).

I want to host my application on azure later and I am trying to figure out whether it would be better to use Azure Blob storage to store all images or just store them in the DB?

What is better performance wise when loading the images on the website?

  • SQL: Controller -> DB -> VIEW
  • Azure Blob: Controller -> Webcall to Azure DB -> VIEW

Could someone please explain benefits of either solution to me so that I can make up my mind?

2
I don't know too much about Azure for hosting, Images in databases can be interesting topic. Maintaining Referential Integrity storing them in DB is nice but bloating DB size with them isn't great either. A thought, Are you going to use azure db too? If so my assumption would be that storage would be cheaper hosting them in Azure Blob storage rather than paying for larger DB resources but that is purely an assumption....Matt
Thanks Matt, good points. Yes will be using Azure DB as well - and the blob is def cheaper... :)Nik
well then I guess it comes down to if performance is acceptable and I apologize but I cannot weigh in on that as I don't use azure. cheersMatt

2 Answers

30
votes

How you design your database storage scheme is subjective, but there are objective things to consider in your scenario. I'll address those, and leave the "which should I choose" to you...

Azure Storage blobs are designed for bulk "block" data (such as documents, images, etc). Something like SQL Database is designed for metadata (stuff you search/index/query).

Everything can be done via SQL Database, and you would only need to worry about SQL queries (and it sounds like that's something you're already familiar with). SQL Server (and SQL Database) have always had the ability to store binary content via its BLOB type.

While you can store your images in SQL Database, you will find that your database size increases considerably, vs just storing queryable metadata. And while SQL Database service allows you to scale your storage, you'll find larger scale in blob storage (up to 500TB) at a lower cost than SQL Database service. If you run SQL Server in a VM, then you'll still have storage cost (attached disks) equivalent to blobs, along with VM costs.

Storage blobs, by themselves, don't provide a query language - you will need to know the container and/or blob name. So, for optimum searching, you'll want a queryable database with your metadata (e.g. SQL Database).

If you store your images in blobs, and reference them via URI in your database, you will be able to query against your database, find the image's URI, and then read from blob storage appropriately.

Also note: With blobs, you'll be able to provide direct image URI access to, say, a browser or an app (even if the blob is marked as private), which allows you to then bypass your app tier when delivering binary (image) content to the end-user. Blobs may also be cached in the CDN, which you cannot do with SQL Database.

Which you choose is ultimately up to you; I simply provided the objective reasons to use each.

14
votes

Much cheaper in BLOB.

You are also probably going the get faster transfer as BLOB. Now the initial lookup may be a little faster with SQL but for a large image I think BLOB would win. SQL is just plain not optimized for big stuff and BLOB is.

And you keep SQL free to serve up short stuff.