When can I store derived data in a database?

I currently have a GAME table with two fields

user_id, win

win = 1 for victory, 0 for loss

Suppose I want to display the percentage of winnings. This is pretty trivial with a count operation. However, suppose I want to display thousands of users on one page with a winning percentage for each. I have some scalability issues regarding this scenario. This is too big a problem to create a separate cache table with the following fields.

user_id, win_percentage

This will be updated every time a new game is published. Now the winning percentage can be determined very quickly, instead of using thousands of counting operations. What is the best way to deal with this problem?

+3
source share
2 answers

Data warehouse people say that it is always necessary to store derived data in a database. Until it is updated.

The question is one of the updates.

Firstly. Your scalability issues are not many. “Suppose I want to display thousands of users on one page with a winning percentage for each,” doesn't really matter. It can be calculated very, very fast.

This will be updated every time a new game is published.

This is a problem with storing the received data. The cost of updating may outweigh the cost of computing. You do not know without actual usage statistics.

In this way.

, ( ), .

+3

( ), ( , - memcached) , .

( ), , - .

, , , ?

:

- !

.

user_id, wins, loses, percentage

, , , .

+2

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


All Articles