There was a small dispute with a colleague. The essence of the problem: there is a product, it has different pictures, it is necessary to return these pictures to the client. The pictures were decided to be returned by one response in the form of a Jason object with an array of these pictures in base64. In general, the question is: what is better in speed: select these pictures from the database with one query or read from disk? Whether indicators can change at heavy loading?
3 answers
It depends on the size and frequency of the image request. If there are few of them, and there is enough memory on the SQL server, then they will be in the cache of the SQL Server, in fact, in the RAM, and be given quickly enough. If there is not enough memory, then working continuously with large data will have a bad effect on SQL Server performance — you won’t win the speed of working with pictures, and lose the performance of other queries. In this case, you can use FileStream - the files are in the file system, but they are accessed as SQL objects.
FileStream is even more useful than you can play around - first put the pictures in the database, look at the performance, then upload to the file system and redo the column into FileStream - and look again. At the same time, the methods of working with objects will not change - all this can be done without rewriting the code.
In my opinion, it is better to keep pictures on the disk separately, and only keep references to them in the database.
Choose these pictures from the database with one query (yes if not enough) or read from disk (yes if there is a lot)? Indicators may change in a big way. I would send one request for one product.