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?
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.