ASP.NET MVC – Storing Images vs Virtual Resizing and Returning Byte Arrays

asp.netasp.net-mvcdesignimage manipulationweb services

I need to create a REST web service to manage user submitted images and displaying them all in a website. There are multiple websites that are going to use this service to manage and display images. The requirements are to have 5 pre-defined image sizes available.

The 2 options I see are the following:

  1. The web service will create the 5 images, store them in the file system and and store the URL's in the database when the user submits the image. When the image is requested, the web service will return an array of URLs.

    I see this option to be a little hard on the hard drive. The estimates are 10,000 users per site, and lets say, 100 sites. The heavy processing will be done when the user submits the image and each image is going to be pulled from the File System.

  2. The web service will store just the image that the user submits in the file system and it's URL in the database. When the user request images, the web service will get the info from the DB, load the image on memory, create its 5 instances and return an object with 5 image arrays (I will probably cache the arrays).

    This option is harder on the processor and memory. The heavy processing will be done when the images get requested.

    A plus I see for option 2 is that it will give me the option to rewrite the URL of the image and make them site dependent (prettier) than having a image repository for all websites. But this is not a big deal.

What do you think of these options? Do you have any other suggestions?

Best Answer

Definitely use a file store, whether that's a classic CDN, a cloudy one, or a roll-your-own. I also wouldn't bother storing all 5 image sizes. Create the scaled images on the fly, at first access (i.e. if the DB query for a particular image and size returns NULL for the URL, scale the larger image down, and return the newly created URL, then store it for future references).

Don't bother too much about hard drives. There's already a very effective file cache in every relevant OS, and you're going to be hard-pressed to beat that. Furthermore, you'd planning to service a million users. You can quote storage at a reasonable $1.00 per user and have plenty of money to play with.

Don't worry about the URL pretty-ness. Our filestore is known as download.<OurCompanyName>.com, even though it's actually hosted by a well-known CDN company.

Related Topic