Microservices – Cron Job Implementation

apicronmicroservicesrest

I'm implementing an application that's made of bunch of microservices. Each of them is fairly simple, focusing on its own task. Let's call two of them Service A and Service B. They are both implemented in NodeJs and expose a Rest API. Now I need to run couple of cron jobs (some at 1m interval, others at 5m, 1h and so on) and I need to pass data from one service to another. For example I need data from Service A, call an external API, process the data and POST it to Service B.

enter image description here

I thought of using another microservice called Task Master in this example, that would do this cron job and all the others (for all the services in the application), therefore being master of all the cron jobs.

  1. Is this a bad idea ? One microservice just for cron jobs ? And all the cron jobs ?
  2. What would be the best way to implement this ? Could it be another NodeJs app ?

Best Answer

This is a fairly common pattern. Common enough that there is existing software to accomplish a lot of what you've described. Look at kubernetes cronjobs, or celery periodic tasks, for example. Most serverless frameworks also support periodic scheduling. I would do a thorough review of existing implementations before trying to make your own.

Related Topic