Trendyol Scheduler Service

Bahadir Tasdemir
Trendyol Tech
Published in
3 min readAug 10, 2019

In Trendyol Marketplace team, we needed a centralized job executor service. In detail, the need is to trigger the desired asynchronous events across microservices. In this post, you are going to read the details about the Trendyol Scheduler Service.

You can access the Github repo via this link.

Technology

Scheduler Service is a Spring Boot app with version 2.1.0.RELEASE. To begin with, for the database it uses PostgreSQL version 9.6.12. For cache and concurrency purposes, Couchbase 6.0.0 is set. Also, to be able to create job descriptions asynchronously, it provides a queueing mechanism via RabbitMQ 3.7.8.

Basic Principle of the Service

At the present time, this service simply triggers the needed tasks in the REST APIs. To provide this, when a job is needed to be created, basically a record is saved into the database with needed information, it’s that simple. Then, when the job is activated, it makes a simple REST call to honor the royal process.

In detail, the scheduled jobs are set with Spring’s Task Scheduler. When the application starts up, it fetches all the job definitions from the database and sets up them.

Scheduler Service — Init Jobs

There are two main types of jobs:

Cron Scheduled Jobs

Cron Scheduled Jobs provide running a task in definite time intervals (or other combinations that the Cron notation can supply). In summary, there are two types of scheduled Jobs. They are REST Scheduled Jobs and Bean Scheduled Jobs.

Rest Scheduled Jobs
Rest Scheduled Jobs

Rest Scheduled Jobs: When you set a rest scheduled job, it activates the related job via a REST call to the destination API. For example, think that you have a Customer Service API. If this API has an endpoint like “/customers/report” then this job will simply make a request to that endpoint to trigger the job process.

Bean Scheduled Jobs
Bean Scheduled Jobs

Bean Scheduled Jobs: Bean scheduled jobs process the task with a bean’s method (this is appropriate for Spring Boot services). When the job is triggered, the Scheduler Service will make a rest call to the destination API. Then, it will run the desired bean and its method. While making the request, it sets the needed data to the payload like bean name and the method name.

Future Tasks

When you need to run a process for once in a definite time, this job type accomplishes it. Simply, you set the application URL, endpoint and payload (future tasks run only via REST calls).

Sample

Given the points, it is so simple to set up any kind of job. For example, to create a Rest Scheduled Job, you simply enter the below changeset:

Define Scheduled Job

In this case, this changeset will create a Bean Scheduled Job. In addition, this job will be triggered per five minutes and the method ‘invoke’ will be triggered by the bean ‘sampleJobService’ in the application ‘http://localhost:6060’.

For another example, if you need a Future Task then your solution is below:

Define Future Task

As you can see, the future task is set at five minutes later from now. It will expire in ten minutes. Also, the job will be triggered at the application ‘http://localhost:6060’ with the endpoint ‘/future-job/invoke’.

You can find all the samples in the code repository.

Conclusion

To sum up, Trendyol Scheduler Service is a solution for our microservice environment job executions. Additionally, feel free to contribute to the open-source repository. If you have questions please feel free to ask. Also, don’t forget to read the other blog post about ‘How Do We Use Couchbase in Trendyol Marketplace’.

--

--