research if the scheduling logic should be placed in the database or in application backend #740

Closed
opened 2026-05-05 09:36:31 +00:00 by a22erigr · 8 comments
Collaborator

Description

When implementing #727 the developer noted that a design decision needed to be made. Where should the "scheduling" logic be placed. This needs to be researched.

What needs to be done

Research where the "scheduling" logic should be placed. Leave process and cones and a conclusion/recommendation.

## Description When implementing #727 the developer noted that a design decision needed to be made. Where should the "scheduling" logic be placed. This needs to be researched. ## What needs to be done Research where the "scheduling" logic should be placed. Leave process and cones and a conclusion/recommendation.
Collaborator

We have two different choices regarding where scheduling logic for database tasks should be placed: in the postgres database or in the backend as a new service.

Database

If we decide to add it directly to the postgres database we would have to use an extension, and my recommendation is pg_cron. pg_cron, as far as I can gather, seems to be a standard extension for handling scheduling of tasks within databases (referenced in AWS postgres manual). With this option the scheduled database tasks would always run regardless of connection to our application services. It would however require us to revamp the postgres image/setup we are currently using, since the base postgres image does not have the pg_cron extension. This solution will require more time (i.e. sub-issues) but should not result in us having to change any existing communication with the DB.

Service/backend

The second option is having scheduling logic as a sub-service to our main service (like tempSensors). We would be able to use ASP.NET built-in scheduling, requiring no additional dependencies. This approach is more in line with how our project is structured and would allow our scheduling logic to be more understandable and more easily documented. It would also allow us to more easily integrate user/role-specific tasks which need to be scheduled. The main flaw would be, as is stated above, that it would require two components to run (service and database), meaning additional points of failure.

Conclusion

The main factors to take into consideration when making the choice between the two alternatives is if the scheduled tasks will require external information and the complexity of them. In the case of issue #727, where the logic is basic and requires zero external information, I would choose option 1. It is also important to note that these two aren't mutually exclusive, meaning future, more complex tasks requiring external data could use option 2.

We have two different choices regarding where scheduling logic for database tasks should be placed: in the postgres database or in the backend as a new service. ### Database If we decide to add it directly to the postgres database we would have to use an extension, and my recommendation is pg_cron. pg_cron, as far as I can gather, seems to be a standard extension for handling scheduling of tasks within databases (referenced in [AWS postgres manual](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/PostgreSQL_pg_cron.html)). With this option the scheduled database tasks would always run regardless of connection to our application services. It would however require us to revamp the postgres image/setup we are currently using, since the base postgres image does not have the pg_cron extension. This solution will require more time (i.e. sub-issues) but should not result in us having to change any existing communication with the DB. ### Service/backend The second option is having scheduling logic as a sub-service to our main service (like tempSensors). We would be able to use ASP.NET built-in scheduling, requiring no additional dependencies. This approach is more in line with how our project is structured and would allow our scheduling logic to be more understandable and more easily documented. It would also allow us to more easily integrate user/role-specific tasks which need to be scheduled. The main flaw would be, as is stated above, that it would require two components to run (service and database), meaning additional points of failure. ### Conclusion The main factors to take into consideration when making the choice between the two alternatives is if the scheduled tasks will require external information and the complexity of them. In the case of issue #727, where the logic is basic and requires zero external information, I would choose option 1. It is also important to note that these two aren't mutually exclusive, meaning future, more complex tasks requiring external data could use option 2.
Collaborator

A third, secret option would be to run the tasks through shell commands and schedule them using OS-level cron/other scheduler. This would allow us to group multiple scheduled tasks together, disregarding of which database/service they are connected to. I do not recommend this option since it seems overly complicated, but wanted you to be aware of its existence.

A third, secret option would be to run the tasks through shell commands and schedule them using OS-level cron/other scheduler. This would allow us to group multiple scheduled tasks together, disregarding of which database/service they are connected to. I do not recommend this option since it seems overly complicated, but wanted you to be aware of its existence.
Collaborator

Good work, we will have this as one of the talkpoints with the " customer" to see if they have any preferences in the implementation.

Good work, we will have this as one of the talkpoints with the " customer" to see if they have any preferences in the implementation.
Collaborator

Did we get an answer to this at the customer meeting?

Did we get an answer to this at the customer meeting?
Author
Collaborator

The customer meting is tomorrow 13:00

The customer meting is tomorrow 13:00
Collaborator

Aha!

Aha!
Author
Collaborator

@a24vinla The customer things the logic should be placed in the database

@a24vinla The customer things the logic should be placed in the database
Author
Collaborator

After discussion with teacher ,customer and group leaders we will be using pg_cron

After discussion with teacher ,customer and group leaders we will be using **pg_cron**
Sign in to join this conversation.
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Andras/BoundlessFlowCampus2K#740
No description provided.