3

We have a microservice written using Spring boot which has its own NoSQL datastore. We are working on functionality whereby we want to delete some old data (in magnitude of 0.5 million documents) and want to do it on a regular basis(once a day) based on presence of records of particular type in data store.

Is having a scheduler which runs once everyday and does the deletion, a correct approach for it ? Also since its a microservice and several instances of it will be running, how do we control that this scheduler runs on only 1 instance ?

user762421
  • 503
  • 1
  • 12
  • 24
  • Also since its a microservice and several instances of it will be running, how do we control that this scheduler runs on only 1 instance ? what do you mean by instance over here ?Each microservice will be running as separate application with its own database . – Pradeep Oct 30 '17 at 14:46
  • Go though this link http://microservices.io/patterns/deployment/multiple-services-per-host.html – Pradeep Oct 30 '17 at 14:46
  • Instances over here means different JVMs of same application/microservice and in each JVM the application connects to the same database instance. – user762421 Oct 30 '17 at 15:25

1 Answers1

5

There are multiple options I can think of now:

  1. If there is a single instance of micro-service deployed, you can use something like quartz to time the job.
  2. Create a RESTful API for cleanup, invoke it using a script, please refer to https://stackoverflow.com/a/15090893/2817980 for example. This will make sure that only one instance of the service works on cleanup.
  3. If there is a master-slave replica, ask the master to allocate to only 1 instance
  4. Create a scheduled job using something like quartz and then check if the job already taken up by some other scheduler in zookeeper/redis/db or any other storage.

I can discuss more on this.

Shashank
  • 133
  • 2
  • 13
  • Yes Please.. you can provide the all alternatives a part from the above mention options – Lova Chittumuri Feb 27 '18 at 10:24
  • @LovaChittumuri the alternatives I'd suggested can be applied base on the scenario/requirement. I can probably suggest another thing when we run through the requirements. To me, with the information provided so far, looks like Option#4 would be more suitable. – Shashank Feb 27 '18 at 17:50