S
S
SET12020-06-12 22:14:32
MySQL
SET1, 2020-06-12 22:14:32

How to shard such a database?

Let's say there is a site where users register and write articles for their blog. Each article can be rate like and write a comment. One MySQL instance stores all the articles, likes, and comments on the articles of 50,000 users. I was overtaken by the idea that if some very famous person starts a blog, and she writes 500 articles, each of which will collect 500,000 likes, then there will be 250,000,000 entries in the table. And if he continues to write articles, then sooner or later the moment X will come when the server will not be able to cope. Can you suggest a solution to this problem? It is necessary to somehow make it so that you can simply connect additional instances and the application automatically knows where to look for the necessary information. I perfectly understand that the solution to this problem cannot be quickly painted on this project, but I spent about a week looking for a solution to this problem, but I never came up with anything. I would be grateful for any hints.

Answer the question

In order to leave comments, you need to log in

5 answer(s)
F
FanatPHP, 2020-06-13
@FanatPHP

We need to make a tag, "wet erotic fantasies."
We don't have a website yet.
There is no database.
There are no articles.
There is no famous person.
No official likes.
But on the other hand, pants full of anxiety, AND SUDDENLY THE BASE IS NOT RIGHT!!!
in a constructive way.
Buy yourself a couple of good books, but rather go to normal courses, which are from Avito, I don’t remember what they are called. Then go to work in a normal office, where you can figure out in practice what a database is and from which end they approach it. Not in the sense of load, but so that thoughts do not arise about the type of tables likes_for_userid_847192 .
And after 5 years, you can start thinking about the question, "what will happen if there are 1,000,000,000,0000 00000 000000!!!111adinadin records in the database."

D
Dimonchik, 2020-06-12
@dimonchik2013

5ee3e55fbb7e2976333625.jpeg
here and what you haven't asked yet

R
Roman Mirilaczvili, 2020-06-13
@2ord

There is hardly any miracle solution in system scalability. From rather banal advice: correctly design the database for heavy loads by adding the necessary indexes. But all the same, there will come a moment when the load will be too large and then the available connections to the DBMS will be exhausted, there will be some kind of locks, timeouts, crashes and other joys. That even dev ops won't save you from "the server is temporarily unavailable".
In the clouds, you can automatically scale computing resources to some extent, but you can suddenly go bankrupt due to the attack of some bot.

R
rPman, 2020-06-13
@rPman

First, what makes you think that the server will not cope?
Secondly, sharding provides only linear load optimization, i.e. allows you to distribute the load on multiple servers.
Most likely you are just writing code that does meaningless calculations for each sneeze, instead of storing the result. For example, instead of counting likes using count for each page impression, count likes by increasing and decreasing the value of the post field.
Perform complex analytics offline using third-party tools, because sql databases are not suitable for this.

K
Konstantin Tsvetkov, 2020-06-13
@tsklab

Or partitioning , or a cluster .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question