Slide 1

Slide 1 text

Getting Started With Microservices Pranav Kumar

Slide 2

Slide 2 text

Agenda ● Why Microservice ? ● What is Microservice ? ● What do we( Developer,Architect, Business..etc) need ? ● Technology Comparison ● Microservice Features ● Spring Boot Features ● Microservice Communication ● Testing ● Demo

Slide 3

Slide 3 text

Why ?

Slide 4

Slide 4 text

Problem with Monolithic Architecture ➔ Tightly Coupled ➔ Language dependency ➔ Scalability ➔ Root Cause Analysis ➔ Monitoring ➔ Auditing ➔ Performance Management Integration Layer (Business Logic) Catalog Query Parts Pricing & Availabilit y Quotatio n Order Order Track ORM Database Pricing

Slide 5

Slide 5 text

What ? ➔ Software Architecture Style ➔ Loosely coupled ➔ Language Agnostic ➔ Highly Scalable Catalog ORM Database

Slide 6

Slide 6 text

What ? “Microservices is a way of breaking large software projects into smaller, independent, and loosely coupled modules. Individual modules are responsible for highly defined and discrete tasks and communicate with other modules through simple, universally accessible APIs.”

Slide 7

Slide 7 text

What do we need ?

Slide 8

Slide 8 text

Software/Service ● Loosely coupled ● Rest Support ● Transaction Management ● Log Management ● Auditing ● Scalable ● Secure ● Statistics We need..

Slide 9

Slide 9 text

Technologies.. Comparison Rest Support Embedded Container Statistics Support Log Management Transaction Management Security DropWizard ✓ ✓ ✓ ✓ ✕ ✓ Spring Boot ✓ ✓ ✓ ✓ ✓ ✓ Apache Karaf ✓ ✓ ✕ ✕ ✓ ✓ Jersey ✓ ✓ ✓ ✓ ✕ ✓ Apache CXF ✓ ✓ ✓ ✓ ✓ ✓

Slide 10

Slide 10 text

Microservice Features

Slide 11

Slide 11 text

Coupling Microservices definitions says that “Microservices is a way of breaking large software projects into smaller, independent, and loosely coupled modules” So, this issue is straightaway solved. Catalog ORM Database Query Parts ORM Database

Slide 12

Slide 12 text

Language Independent Each service can be developed using different programming language Allows you to take advantage of emerging and latest technologies (framework, programming language , programming practice, etc.). Catalog( Spring Boot ) Spring Data NoSql Query Parts( Apache Karaf ) Hibernate RDBMS

Slide 13

Slide 13 text

Scalability Since microservices are very small part of the complete software ecosystem, It is very easy to scale the same. Unlike, the monolithic web application, where if we have to do a scaling, first we have to setup the environment ( apache, tomcat ) and then deploy the war/ear files in that.

Slide 14

Slide 14 text

Scalability with monolithic ... Integration Layer (Business Logic) Catalog Query Parts Pricing & Availabi lity Quotat ion Order Order Track ORM Database Pricing Integration Layer (Business Logic) Catalog Query Parts Pricing & Availabi lity Quotat ion Order Order Track ORM Database

Slide 15

Slide 15 text

Scalability with Microservice Catalog ORM Database Query Parts ORM Database Catalog ORM Database

Slide 16

Slide 16 text

Root Cause Analysis It is always difficult to find the root cause in a Single Large Monolithic system. In microservice, fault isolation would be improved and we can easily identify which service is consuming more memory or cpu and we can scale that service easily and fix the issue ( if any ) later.

Slide 17

Slide 17 text

Spring Boot

Slide 18

Slide 18 text

Logging Strategy Spring Boot provides us the various way to achieve logging ➔ Using Aspect ➔ Using logback ➔ Annotation based logging ( When an exception occurs )

Slide 19

Slide 19 text

@Before("execution(* com.wtc.samplems.controller.*.*(..))") public void logServicebefore(JoinPoint joinPoint) { logger.debug("Completed: " + joinPoint); System.out.println( "Completed: " + joinPoint ); } Annotation ( Handling Exception and log ): @ExceptionHandler(Exception.class) @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR) public @ResponseBody JSONObject handleException(Exception e, HttpServletRequest request) { JSONObject jSONObject = new JSONObject(); jSONObject.put(ConstantsUtility.STATUS, ConstantsUtility.FAILED); UtilityLogger.error("Request Processing Failed in Navigation Serv "+e.getMessage()); return jSONObject; } AspectJ:

Slide 20

Slide 20 text

UTF-8 ./logs/servive.log %d ${logger.type} %p %m%n 10 ./logs/navigationservices.log.%i 1MB %d ${logger.type} %p %m%n utf8 Logback:

Slide 21

Slide 21 text

Monitoring Spring boot comes with it’s own monitoring tool called “Spring Admin Console” We can monitor various aspects like: ➔ Application health ➔ Memory ➔ JVM ➔ Garbage Collection ➔ Metrics etc.. We can also changelog level without restarting of the application. This would help us in debugging any prod issue Sample UI : https://github.com/codecentric/spring-boot-admin

Slide 22

Slide 22 text

Dashboard with Desktop Notifications

Slide 23

Slide 23 text

View Application Health, Information & Details

Slide 24

Slide 24 text

View Metric Counters

Slide 25

Slide 25 text

Manage Logback logger levels

Slide 26

Slide 26 text

Auditing Auditing would be achieved using AspectJ We can have the information like ➔ Who accessed the URL and from where ➔ How many requests have been successfully served to whom and how many got failed ➔ Which services - How many times - By Whom

Slide 27

Slide 27 text

Performance Management Until now, We are using several tools to perform this task ● Jconsole ● JvisualVM ● Java Mission Control ( Comes with Java 8 ) ● Logicmonitor (Paid)

Slide 28

Slide 28 text

Performance Management Every time a new developer/user comes to the environment, we have to educate them to understand each of the tool. Spring Boot gives us a single tool ( Spring Admin Console) to do the performance management as well

Slide 29

Slide 29 text

Transaction Management Spring gives us various ways to manage the transactions, In which two of them are very popular : ➔ Using Aspects ➔ Annotation Based

Slide 30

Slide 30 text

Using Aspect

Slide 31

Slide 31 text

@Transactional public class DefaultFooService implements FooService { Foo getFoo(String fooName); Foo getFoo(String fooName, String barName); . . } Annotation

Slide 32

Slide 32 text

Communication External : Using REST Internal : Using REST

Slide 33

Slide 33 text

Testing - Unit testing - Junit - Integration Testing - Rest Client - Postman

Slide 34

Slide 34 text

Demo

Slide 35

Slide 35 text

?

Slide 36

Slide 36 text

Thank You! Follow us on www.walkingtree.tech