The best way to store messages and chat files

I would like to know what you think about storing chat messages in a database?

I need to be able to bind other things to them (like files or contacts), and using a database is the best way I see now.

The same question applies to files, because they can be attached to chat messages, I also have to store them in a database.

With thousands of messages and files, I wonder about performance degradation and database size.

What do you think, considering that I'm using PHP with MySQL / Doctrine?

+4
source share
2 answers

I think it would be nice to store any text information in the database (names, message history, etc.) if you structure your database correctly. I worked on large websites (many kilometers of visits per day) and telecommunications companies that store information about their users (including traffic statistics) in databases that have grown to hundreds of gigabytes, and the applications work fine.

But with regard to binary information, such as images and files, it would be better to store them in file systems and store only their paths in the database, because it would be cheaper to read them from disks in order to associate the database process with reading a file with several megabytes.

As I said, it is important that you do a few things:

  • Build your information correctly - it is very important to design your database correctly, correctly divide it into tables and tables into fields with your performance goals, as this will become the basis for your application and queries. Get it wrong and your requests will be slow.

  • Make the right decisions for the table engines corresponding to each table. This is an important step, as it will greatly affect the performance of your queries. For example, MyISAM blocks read access to a table while it is being updated. This will be a problem for a web application, such as a social network or news site, because in many situations, your users will basically have to wait for the information to be updated before they see the generated page.

  • Create the right indexes - very important for performance, especially for applications with rapidly growing large databases.

  • Measuring the performance of your queries as the data grows and looking for ways to improve them - you will always find bottlenecks that need to be removed, this is a continuous continuous process. Every popular web application should do this.

+3
source

I think a NoSQL database such as CouchDB or MongtoDB is an option. You can also store files separately and link them through a known file name, but it depends on your system architecture.

+1
source

Source: https://habr.com/ru/post/1444085/


All Articles