Why Micro Services ?

Why Micro Services ?

Micro Services are the next big thing in the modern software architecture and development. The distributed applications in the recent past changed the world of software outlook. Now the applications are developed, used, work and built differently. This caused the logical evolution of Micro Services. Some best examples of game changers in the software world are Git ( Distributed source control), Cloud computing (AWS, Azure, …), BitCoin (Distributed virtual currency).

Let’s begin our journey with understanding, What are Micro Services?

The Philosophy

The whole idea of Micro Service architecture is that they are small, focused and should be scaled.  

The Definition

The MicroService architectural style is an approach to developing a single application as a suite of small services, each running in its own process and communicating with lightweight mechanisms, often an HTTP resource API. These services are built around business capabilities and independently deployable by fully automated deployment machinery. There is a bare minimum centralized management of these services, which may be written in different programming languages and use different data storage technologies.” – Fowler & Lewis, 2014.

This idea looks very similar to SOA. When I first heard about Micro Services, I thought they are just web Services and got many questions related to them. Some of them are as below
Why these services are called Micro Services?
What is the difference between these micro services and web Services ?
How different this world is different from SOA world?

Characteristics of Micro Service:

Do One thing well : Services should hide, how they work and do a single thing and do it well. The encapsulation is based on the business function of the service that it encapsulates the functional requirements.

Business Domain Centric : Each Service should align to the context with in the domain model for this to make sense in the domain and in the service architecture.

Decentralization : Every service should be decentralized and autonomous, so that each service can operate on its own schedule and priorities. Each service can be updated and deployed as fit.

Smart Endpoints and dumb pipes: This characteristic has come based on SOA, in SOA we have many products / ESB where we can define lot of logic in routing and transforming etc. Where as in Micro services the focus on login inside the service and the communication should happen very dumb like a REST / HTTP resource call to get to the service.   

Fail-Safe : Enterprise systems need to be smart, in that they fail in a way that doesn’t break things in unpredictable ways. Anticipate failure in everything, among with  validation of input and validation of data we send downstream.

Automation : Services should use automation which keeps management and operational support efficient. Employing large number of small services can become a mess if you do not embrace automation.

Principles of Micro Services – Encapsulation, Automation, Business Domain Centric, Isolation, Fail-safe and Observable.

Micro Service Vs Web Service:

The regular Web services are definitely different from Micro services. The regular web services support is based on protocols like HTTP / SOAP. These services are invented to solve the integration problems between application when we have polyglot technologies with different vendors/ applications. So, the aim of web services is to integrate or build a channel to communicate between these applications. Where as Micro services aim is NOT to integrate applications, perhaps to reduce the complexity of a monolithic application to micro services. This would give us re-use, maintainability, test-ability, scalability etc in the application.

Micro Services Vs SOA:

SOA started with very similar characteristics mentioned above, but the idea got converted when many vendors started introducing new features to SOA. Then we have a vendor lock-in problem now. We have lot of logic built in around the services NOT inside the services. So, Micro services are the out come of learning of SOA. Still, micro services are evolving. We might end up with very similar problems of SOA, if we are not cautious. Hope we would be able to use micro services the way they are explained.

Technology Support:

Here are the technology

Building Micro services with Spring Boot

Building Micro services with Drop Wizard


Fowler & Lewis on MicroServices

Videos on MicroService Architecture

How to create a Quartz Job?

How to create a Quartz Job?

The Quartz Jobs can be created with a very simple program by just adding the required libraries to the class path of your project. Here I will try to explain two different ways to configure a Quartz job. This complete post is divided into 3 sections.

Section 1: Common steps for both the approaches

Section 2: Simple Job with out any XML/Properties file involved

Section 3: With XML files and properties files to manage the Jobs.

So, lets put our hands in dirt.

Tools you need before you start this example: Eclipse Juno/Kepler.

Section 1: Common steps to create a Quartz Job/Scheduler

Step 1: Download the Jars for Quartz either from Maven or manual download.

Step 2: Create a Java project  {I am going with older approach}.

Step 3: Refer your downloaded jars in your class path (by Right Click on Project -> Build path -> Add External Archives ) See screen shot below, You could even use jta-1.1.jar instead of jboss-transaction-spi. But don’t miss this jar as this is a mandatory dependency for Quartz 2.2.1.


Note: Once these steps are over either you can choose Section 2 or Section 3. [I recommend Section 3]

Section 2:  Simple Job using Java Code

Step 1: Create a class which implements org.quartz.Job interface.

Step 2: Implement execute() method of this interface.

Step 3: Write your business logic inside this execute method i.e. what has to be done when your job gets executed.

See below code as example

package com.ravi.schedulers;

import org.quartz.Job;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;

public class ExampleQuartzJob implements Job{

    public void execute(JobExecutionContext arg0) throws JobExecutionException    {
       // TODO Auto-generated method stub
       System.out.println("Logic Goes here........");

Create another class.

package com.ravi.schedulers.test;

import org.quartz.JobBuilder;
import org.quartz.JobDetail;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.SimpleScheduleBuilder;
import org.quartz.Trigger;
import org.quartz.TriggerBuilder;
import org.quartz.impl.StdSchedulerFactory;

public class TestBJob {

    public static void main(String[] args) {
        try {
            // Create Job details 
            JobDetail job = JobBuilder.newJob(TestJob.class)
           // Create the trigger with running interval of the job
           Trigger trigger = TriggerBuilder.newTrigger()
          //This is how you start the job
          SchedulerFactory schFactory = new StdSchedulerFactory();
          Scheduler scheduler = schFactory.getScheduler();
          // tricky step, if you don't start the scheduler, it won't run.
          // This is the thing which will run your Job at the triggered time/interval.
          scheduler.scheduleJob(job, trigger);
          //Use it to stop the scheduler. 
      } catch (SchedulerException e) {

Here are the next steps ….

You might get some warning as below as I missed the dependency of slf4j –

SLF4J: Failed to load class “org.slf4j.impl.StaticLoggerBinder”.
SLF4J: Defaulting to no-operation (NOP) logger implementation

But the program will run as it is not a mandatory dependency. If you want to avoid warning please add this jar as well in your references.

Lets move on to other section.

Section 3: Scheduler Jobs with XML, Properties files.

Step1: Create a XML file with name quartz-config.xml (You can even use another name :), just for identification I am using this name.)

<?xml version="1.0" encoding="UTF-8"?>



<description>This is Test Job</description>
<!-- It will run every 2 seconds -->
<cron-expression>0/2 * * * * ?</cron-expression>

Step2: Create a properties file with name quartz.properties, in the same folder.

org.quartz.scheduler.instanceName = ExampleQuartzJob
org.quartz.threadPool.threadCount = 3
org.quartz.jobStore.class = org.quartz.simpl.RAMJobStore
org.quartz.plugin.jobInitializer.class =org.quartz.plugins.xml.XMLSchedulingDataProcessorPlugin
org.quartz.plugin.jobInitializer.fileNames = com/ravi/schedulers/quartz-config.xml
org.quartz.plugin.jobInitializer.failOnFileNotFound = true

Once you are done with these two changes, you have to create a main method class to test this job.

package com.ravi.schedulers;

import javax.naming.NamingException;
import org.quartz.Scheduler;
import org.quartz.SchedulerException;
import org.quartz.SchedulerFactory;
import org.quartz.impl.StdSchedulerFactory;

public class QuartzRunner {
     public static void main(String[] args) throws SchedulerException, NamingException {
         // Creating scheduler factory and scheduler
         SchedulerFactory factory = new StdSchedulerFactory(
         Scheduler scheduler = factory.getScheduler();
         // Start scheduler

This is how you can create a scheduler job using Quartz API. Hope this was helpful and useful for your work.

If you are using Spring-Boot, your scheduling job become dam easy….

Here is how you need to configure your scheduling in Spring boot.

Use @EnableScheduling annotation at your application class/ Main program of Spring boot.

Then simply put @Scheduled(fixedDelay=150000) on your method which need to be scheduled.

For Example, I want to update my Log data into DB every 15 seconds. Here is the code for it,


public void updateDBLogs() {

// Read log file

// apply business logic

// insert into DB


There are many options than fixed delay for scheduling … you can even try Cron job like this.

@Scheduled(cron = “0 0 0/1 * * ?”)

Happy Scheduling 🙂