O
O
Onatskyi2018-05-20 23:33:40
MySQL
Onatskyi, 2018-05-20 23:33:40

Storage of avatars in the database, what do you say?

Hello!
There was an idea to store user avatars not as files, but in the database, in base64. I want to reduce the number of requests to the server in this way, and the total number of files (since the hosting has a limit on the number of files). And in principle, fooling around with architecture is not a hunt. At the same time, avatars have a size of about 10-20 kb in size (in base64). So from interestingly, what are the pitfalls with this approach ?? Will the load on the base increase significantly, and is it worth it? And the second question, if you store avki in the database, then in a separate table, or you can immediately add a column to the table with users.
Thank you in advance!

Answer the question

In order to leave comments, you need to log in

4 answer(s)
L
landergate, 2018-05-21
@Onatskyi

I want to reduce the number of requests to the server in this way

This will not reduce the number of client requests to the web server. The number of requests will remain the same, just the source of data for issuance will not be a disk, but a DBMS.
In most cases, disk access is cheaper than DBMS access.
To reduce the number of client requests to the web server, you can:
  • Move images to external CDN/cloud storage: Amazon S3 or Openstack Swift from most cloud providers.
  • Transfer images to another web host, using it solely for posting images.

D
D3lphi, 2018-05-20
@D3lphi

Never do that. Files need to be stored in the file system, it copes with this better, as it is designed for this. The files are not stored in the database. Add the path to the file to the base, but not the file itself. It will be much more efficient.

T
ThunderCat, 2018-05-21
@ThunderCat

1) Overhead when stored in the database64 about 30%. that is, + 30% to traffic, and given item 2 - even more.
2) Browser cache doesn't work with base64 images (and works great with images in files).
3) Store files in files.
4) Click on the number of files and place - gravatar.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question