Answer the question
In order to leave comments, you need to log in
How to design a database for distribution?
I will try to describe everything with an example:
There are 10-100-... users.
Each user can create a schedule for a specific activity on the site.
(Send an email about the status of the account to E-mail every hour)
In other words, set up a newsletter to your email as he pleases.
At least every minute. (Hardly)
Let's take for example:
10 users who want to receive emails every 10 minutes.
Namely:
00:00
00:10
00:20
00:30...
Answer the question
In order to leave comments, you need to log in
I would do this
user_id, weekDays, date, startTime, interval, endTime, nextTime
SELECT * FROM `table`
WHERE `nextTime` < `endTime`
AND ((`weekDays` & (1 << WEEKDAY(NOW())) OR `date` = CURDATE())
AND `nextTime` < {$currentTime};
UPDATE `table`
SET `nextTime` = ADDTIME(`nextTime`, `interval`)
WHERE `nextTime` < `endTime`
AND `nextTime` < {$currentTime};
$currentTime is needed in order not to miss events between SELECT and UPDATE queries. UPDATE `table`
SET `nextTime` = `startTime`
Theoretically, the user can create 7 schedules for each day of the week.
This means:
7(days) * 24(hours) * 60(minutes) = 10080 records per user.
This is maximum.
Let's say a person still creates for 7 days. and for 24 hours.
But it is unlikely that he will need letters more often than 1 time in 5-10 minutes.
So there will be not 60, but 6-12 letters. Let's take 10.
So 7*24*10 = 1680.
Again, let's assume that there are 1000 users.
1000 * 1680 = 1.68M records consisting of 3-4 integer fields.
This is given that each of the 1000 users made a personal schedule for each day of the week, which is unlikely.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question