Friday, February 24, 2017

Monolithic vs Microservice

Monolithic application is the traditional application which you normally create (i.e., a single big system) which consists of different components as a single deployable unit.

Example of a monolithic application could be an application that has a front-end, back end system that performs several services.

In this the application is normally deployed as a single unit.

Problems with Monolithic approach:
  • A single code base which contains the entire application is difficult for the developers to understand particularly people who are new to the team. The application can be difficult to modify.
  • The application takes a lot of time to startup, not to mention the deployment.
  • The build of the application takes more time, the larger the code base, the slower will be the IDE, the build sometimes has to build components that are not related to the developer currently working on.
  •  Code base maintainence: Maintaining the single code base for all the developer could be a nightmare particularly when a developer committed a wrong code at the end of the day.
  • Scalability: You might have only certain parts of the application that need to be scaled, but you might have to scale the entire application.
  • Deployment dependency: If you have multiple components and developers in a single code base, you may not be able to deploy or wait for a particular interval to get your code deployed to some environments even though you completed your change faster.
  • Every developer need to know the technical stack used in the entire application. Only developers of certain skillset will be able to contribute. Use of a limited technical stack for the entire development team

A lot of problems which are mentioned above can be resolved in the microservice architecture.

A microservice is a relatively small service that can be deployed independently and scaled. This is normally done by a small group of developers who can choose their preferred technical stack to solve a problem.

A big application can comprise of multiple microservices developed by different teams of different skillset. This eliminates any long term commitment to a technology stack.


The code base is relatively small, and hence the build and deployment time is also less. 

Thursday, February 23, 2017

Live reload using Spring boot - Dev tools


Spring boot – Dev tools – Live reload

Spring boot dev tools provides some interesting features, this page explains how to use the live reload option.

What is live reload ?
Normally whenever you make any change in the view, you have to do the following changes.
  • Make the change in the view.
  • Restart / redeploy the application in the server.
  • Go to the browser and refresh the page.

Also the above approach works only for the web content, if it is java, you might need to rerun the build, which takes lot of time just to see a simple change.

How to implement live reload in Spring
1.       Include sprint starter for dev tools.
              <dependency>
                     <groupId>org.springframework.boot</groupId>
                     <artifactId>spring-boot-devtools</artifactId>
              </dependency>

2.       Create a simple controller method:

       @RequestMapping("/testlivereload")
       public String  testlivereload() {
              return "Deivee";
      
       }

3.       Install browser extensions for Live reload

4.       Enable live reload


5.       This will be connected to the server

 
6.       Now change the code and save, do not redeploy or start the server.

       @RequestMapping("/testlivereload")
       public String  testlivereload() {
              return "Spring boot - Dev tools - Live reload";
       }


The code will be autodeployed and the browser will be refreshed with the content.



If you are doing frequent changes and you dont wnat the reload to happen every now and then you change the files, you may also have a trigger file which will enable to reload only when the trigger file changes.

You can also set properties to ingnore certain folders in the project, these folders whenver modified will not trigger the reload.


You can also set the following property to disable the livereload
spring.devtools.livereload.enabled = false