So I'm struggling with a database concept a new project.
I need a database for events which can have relations between them and they have to be executed at a specific time.
Example:
id: 1, user_from: 1, user_to: 2, when: 08:00
id: 2, user_from: 2, user_to: 1, when 07:30
id: 3, user_from: 3, user_to: 2, when: 07:00
If user with id 1 is logging in at 08:01, every single event with relations to the user with id 1 has to be executed.
The problem in these example:
With this example, all three events should have been executed, because 1 has a relation with 2 and 2 has relations with 3. If I would change the event with id 3 to something like this:
id: 3, user_from: 3, user_to: 2, when 09:00
the event with id 3 shouldn't have been executed, because the 'when'-index is just at 08:01.
Another problem:
If user with id 3 is logging in at 09:00 only the event with id 3 should have been executed.
My Question:
With the possibility that there are more then 10k events at the same time, but only one for the user who is logging in, I don't want to calculate the results of all events, I just want the ones with a relation to the user which is logging in. How can I do this to prevent fast loading all the time?
My ideas:
MongoDB with Recursive Query:
Recursive search on a collection in MongoDB
Normal SQL Database with a relation table:
I will calculate all relations when the new event is added to the events table, so I don't need the care about them when the user is logging in.
Thank you for any responses and feel free to ask any questions about the problem. I'm also open for any new title suggestion. It's hard to describe...