Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scheduling tasks within a cluster of identical peers

Given a simple web application running on AWS Elastic Beanstalk (i.e. 1..n identical instances behind a load balancer), how can I have a scheduled background operation that runs on one instance only?

I do have a cron-like scheduling mechanism within the web application, and could use e.g. AWS Simple Queue Service to queue tasks (and ensure that each task is executed just once). But how do I ensure that only one instance creates the tasks (to avoid duplicates)?

Obviously, I could have a dedicated instance that is in charge of creating tasks, but I'm looking for a more dynamic mechanism that lets one of the normal instances take on that role automatically. Any ideas?

like image 452
ejain Avatar asked Nov 15 '25 13:11

ejain


2 Answers

Looks like this could be accomplished using Hazelcast: Only the oldest node in the cluster (can be determined through the API) creates and queues tasks.

like image 169
ejain Avatar answered Nov 17 '25 03:11

ejain


Quartz Scheduler works very well for us. Nodes come and go in our beanstalk, and Quartz manages to run the job on a node that happens to be up when the scheduler indicates that it needs to run. Supports cron-style scheduling as well as a couple of other formats. It is fault tolerant, and can run jobs that were missed because no instances were available when the task should have executed, or if a node failed to complete the execution.

Assumes that you're using RDS or some other relational DB that Quartz can use as a persistent store.

like image 41
Jason Avatar answered Nov 17 '25 03:11

Jason



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!