Should I compress files to save to the database?

4
  

I do not want to take into account whether saving files in the database is good practice.

Since many systems save the files (images, pdf's, doc's, etc) in the database, I'd like to know if it's a good practice to compress these files by zipping them, for example.

The size of the bank can have great influence on the system, whether due to limitations, memory bottlenecks, etc. Does this make it worthwhile to reduce the size of the files because you will have a job to compress every time you save the file and unzip it whenever you want to show the same file to the user?

    
asked by anonymous 26.02.2016 / 21:16

2 answers

2
  

Since many systems save the files (images, pdf's, doc's, etc) in the database, I'd like to know if it's a good practice to compress these files by zipping them, for example.

Yes, and quite common, by the way. One of the most famous for this, incidentally, is ZLib .

  

Is it worth reducing the size of files because you will have a job to compress every time you save the file and unzip it every time it shows the same file to the user?

Unless your system is mission-critical, and thousands of requests are made to download gigantic files (I say hundreds of megabytes here), it's worth it.

According to the author of ZLib (see also question), there are still ways to speed up compression and decompression using methods, but with a lower compression quality. It's worthwhile to run tests on the various compression libraries and their options to determine what suits your needs best.

    
26.02.2016 / 21:25
2

Depends on the frequency with which you will want to access these files. If they're going to stay there mocking most of the time, and assuming you do not have or can not clean up more disk space, it might be worth it. Now if you will be accessing them constantly is not very smart to have to decompress each access, will end up degrading its performance in exchange for saving physical memory.

An exact answer will depend a lot on your situation, but overall I would not recommend it, Spending on disk space is in most cases much less relevant than spending on processor / ram.

    
26.02.2016 / 21:38