How to run multiple replicas in docker swarm with db sync

I have scheduler application which works as follow with mongo db

  1. Fectchs config collection- To get the next available time window (start and end time) to fetch raw data from collection.
  2. Fetch raw data
  3. Processes raw data and save into db.
  4. updates config collection for next time window.

Now i am starting this as service in docker swarm with multiple instances, How i can ensure service will works in sync to get and update config collection and processed raw data.

Source: Docker Questions