Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top