Answer the question
In order to leave comments, you need to log in
When should you think about creating a database?
When should you think about creating a database, in different applications?
For example, if I know that the application will have, for example, 6 types of data to store (tables), and in each table there will be no more than 500 records. For such purposes, I think it's better to use json and store everything in a file.
Be it mobile/web/winapp.
Answer the question
In order to leave comments, you need to log in
If the application is single-user and no data search is needed, the database is not needed.
If you have a site designed for the simultaneous work of more than one person, then you cannot do without a database. The simplest data change performed on the database with a single atomic command, in the case of files, will require locking the file, which means waiting for other users to release it.
PS
Ok, let's have a blog. Will you be able to comment on posts? Then you need to somehow write down these comments. Putting likes or editing karma is also a data record. Even the simplest view counter is already a data change. Here, using the example of such a counter, they usually explain the need for atomicity and locks. Imagine that two people open a blog post at the same time and the scripts increase the read counters, the old value is 99.
Script 1: read the file "counters"
Script 2: read the file "counters"
Script 1: find the post counter in the file, got 99
Script 2: find in the file post counter, got 99
Script 1: increase the post counter, got 100
Script 2: increase the post counter, got 100
Script 1: write the file "counters"
Script 2: write the file "counters"
That is, instead of the expected 101, the counter has only 100. So, before changing any data, you need to lock the file for writing, read the current data from it, make changes, write the file, unlock it. Well, since this is json, you will have to read and write the entire file each time. If data changes change the relationship with data in other files, then all related files will have to be locked to avoid integrity violations.
Well, search by data, let's say the ten most read posts. In the file version, you will have to read the entire json and sort it, while in the database, with the correct arrangement of indexes, this action is performed in one request with a linear receipt of the first ten records by index.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question