Storing big files in database

My application has feature of uploading pdf files having size 20-25mb. I want to store content of file in Database. Which database will be suitable- sql server or nosql. Which will be faster to retrieve file. Please suggest.

Hello @sethi.pooja, welcome to freeCodeCamp!

There are a few ways you can save large files to an app.

I usually deploy my apps to online cloud providers, and usually leverage their “blob storage option”, which are usually cheap, fast and optimized for these scenarios, rather than filling up my dedicated database option.

If you aren’t able to leverage these cloud options, you could save these files to the file system yourself (assuming you have that ability, and capacity). Then you use your database for the file metadata.

Otherwise serializing and storing it into the database your already using would work in a pinch, assuming you aren’t saving tons and tons of data. It’s also worth noting some database’s have limits on individual record size, there are libraries that can help you though, which chunk and manage this use-case for you. Regardless you’ll be seeing high costs for these files, so again, don’t go this route if your scale is large.

Lastly, it might be worth to consider not storing the file at all, and render it at runtime. If your running reports or something, building the report on the fly from other data (that is stored in a database) might make the most sense, but is the slowest of all options.

So just to summarize:

  1. Use dedicated blob storage on the cloud provider you are using, if your deploying to the cloud
  2. Store to the filesystem if your able to, if the scale isn’t large
  3. Serialize to the database your using for other data, if the scale isn’t large
  4. Store nothing, and build the file on the fly, cheapest, but slowest option

The biggest concern is where your running, and at what scale your running. A solution for a few large files is different than if your running at some Youtube scale.

Good luck!

I want to add one thing:

Never do this without auth and limits. Because this can become expensive very fast (if I automatically upload huge files many times). Services like AWS and Google Cloud don’t have spending limits.