You are on page 1of 51

How to Handle the Complexity

of Migrate to Microservices from Monolithic Ten year


Part I - Second Edition: The Journey

Alberto Salazar,
CTO Advance Latam,
Auth0 Ambassador

24th April 2018


asalazar@advlatam.com

@betoSalazar
Alberto Salazar

● Speaker, Java Developer, #Community

● Auth0 Ambassador

● Java User Group Leader, JCP Member

● Working 17 years with monolithic

● Founder and CTO: AdvanceLatam &

Cloudbanco
www.advlatam.com www.cloudbanco.com www.ecuadorjug.org

@betoSalazar
@EcuadorJUG
@Auth0Ambassador
Legacy: Is our monolithic

Source: 97 Things Every Software Architect Should Know

@betoSalazar
Legacy: How it looks after 10 years of code

@betoSalazar
The journey

● The evolution of 10 years of code on Enterprise App

● Why to move from Monolith to Microservices

● The fact - 10 years of code

● The path - Tips, tricks, pros & cons of Microservices

● Conclusions

@betoSalazar
The evolution of more than 10 years of code
The vision behind the scenes

J2EE , JEE SOA Evolution Split the monster Microservices Devops


Industry approach Frontend: Microservices
App Server ESB Html 5 Css3 the beginning
Rest End points Docker
Vert.x | Spring boot |
or BPM Mobile Micro-profile | Kubernetes
BAM
Apache Felix OSGI (-) external influence
JEE -> Jakarta EE Istio
NodeJS, Angular,
Apache Karaf React, Native, Serverless
VueJS………………
……………………….

@betoSalazar
The motivation to migrate
from Monolith to Microservices

asalazar@advlatam.com

@betoSalazar
Microservices

@betoSalazar
Microservices ?
The buzz word

Microservices is the architectural approach that everybody talks about and everybody wants it,
but be prepare to manage a distributed system….
@betoSalazar
The Goal

T Y M E T
O CI I
T RK E
L A
VE M
TO
The goal that organizations need is to increasing velocity & agility;

Get into production as soon as posible;

Deploy new features as soon as posible.


@betoSalazar
The journey

@betoSalazar
The reasons of this talk

The plan of move forward (Microservices -> cloud -> serverless ?)

Everybody are talking about the result (microservices architectural style)


but just a few are showing the path
pain

@betoSalazar
The fact - 10 years of code
The Monolithic

asalazar@advlatam.com

@betoSalazar
Legacy: Is our monolithic

@betoSalazar
The Monolith

How it looks

http://microservices.io/patterns/monolithic.html

@betoSalazar
The Monolith

Characteristics

! Attachment to the environment(language, platform & OS)

! Single logical executable, deploy everything at once or nothing at all

! Bottlenecks and Failure of part == failure of whole

! Take months even years getting into production

! Centralized authority slows the delivery process (DBA, OPS, QA)

! Coordinated releases are hard, because brings many changes


together from different teams

@betoSalazar
How start this legacy
1 Year of code
Always the goal was to keep the modularization

@betoSalazar
Team work on the legacy
5 Years of code
Modularization ?

@betoSalazar
Really ?
10 Years of code
Modular WTF

@betoSalazar
10 Years of code

OMG

@betoSalazar
Migrate several years of code, It will be Easy ?

The challenge
! > 2MM lines of highly coupled code

! Build one microservice is easy, but what

about a complete microservice architecture

based on 2MM lines of code

! Time to delivery features are between: 6 to

12 months & project overhead $$

! Working on production environment for

several years
@betoSalazar
The path - Tips, tricks, pros , cons
Microservices

asalazar@advlatam.com

@betoSalazar
The Monolith to Microservices

How it looks

http://microservices.io/patterns/monolithic.html http://microservices.io/patterns/microservices.html

@betoSalazar
Microservices

Characteristics
! Deployable, executable & scaled independently

! Smaller code modules are easier to understand

! High cohesion, low coupling

! Failure is isolated (Fail one part of the system)

! Independent Teams (decide their own

architecture)

! Polyglot “Plus”
https://martinfowler.com/articles/microservices.html
https://martinfowler.com/bliki/MicroservicePrerequisites.html

@betoSalazar
The path

Microservices

! Split the frontend from the backend & keep

the centralized data

! Secure your API

! Containers, logs, monitoring

! Split the data

! Don’t forget the frontend

@betoSalazar
The path -> Split the frontend from the backend
JEE application server
The Monolith (0/5)

MODULE1.war

MODULE1-JS.jar

MODULE2.war

MODULE3.war

css.war

MODULE4.war

theApp.ear

JEE application server Database

businesslogic.jar
businesslogic.jar
businesslogic.jar
businesslogic.jar
@betoSalazar
The path -> Split the frontend from the backend

Split the frontend from the backend (1/5)

JSF Controller Code

Call the Facade

@betoSalazar
The path -> Split the frontend from the backend

Split the frontend from the backend (1/5)

Facade Code

Call the Business


Logic

@betoSalazar
The path -> Split the frontend from the backend

The communication

JEE application server

MODULE1.war JEE application server


MODULE1-JS.jar

consumer.jar
businesslogi
MODULE2.war
Message businesslogi
MODULE3.war
Queue businesslogi
businesslogic.jar
css.war

producer.jar
MODULE4.war
Apache ActiveMQ
theApp.ear
RabbitMQ theApp-backend.ear

Apache Kafka……
http://activemq.apache.org
https://www.rabbitmq.com Database
https://kafka.apache.org

http://camel.apache.org/mdc-logging.html

@betoSalazar
The consumer

Split the frontend from the backend

Use Camel Routes


Request - reply

Call the Processor

@betoSalazar
The consumer

Split the frontend from the backend

Camel Processor Code

Call the Facade

@betoSalazar
The path -> Split the frontend from the backend
JEE application server

Split the backend consumer.jar

businesslogic.jar

JEE application server


theApp-backend.ear
JEE application server consumer.jar

businesslogic.jar
MODULE1.war

MODULE1-JS.jar JEE application server

theApp-backend.ear
consumer.jar
MODULE2.war
Message
MODULE3.war
Queue businesslogic.jar

css.war

producer.jar JEE application server


MODULE4.war theApp-backend.ear

theApp.ear consumer.jar

businesslogic.jar

JEE application server

Database
theApp-backend.ear

consumer.jar

businesslogic.jar

theApp-backend.ear

@betoSalazar
The path -> Split the frontend from the backend

Split the backend


Osgi container
consumer.jar
Service
some api
engine-orchestrator.jar
businesslogic.jar
Spring boot
Osgi container
consumer.jar
Service
dynamic-camel-routes.jar
some api businesslogic.jar

fat jar
consumer.jar
Service
batch.jar
some api businesslogic.jar

fat jar
consumer.jar
Service
services.jar
some api businesslogic.jar

fat jar
consumer.jar
Service

install just
business-module1.jar
some api businesslogic.jar

fat jar consumer.jar


what you need
Service
some api
businesslogic.jar
business-module-n.jar in a Docker
Container
https://projects.spring.io/spring-boot/
https://microprofile.io/
https://vertx.io/
https://www.docker.com/
https://github.com/fabric8io/docker-maven-plugin @betoSalazar
https://github.com/spotify/docker-maven-plugin
The path -> Split the frontend from the backend

Logging, trace & Monitoring


Osgi container
1) Use Mapped Diagnostic Context (MDC)
consumer.jar
Service
engine-orchestrator.jar
businesslogic.jar
Enrich log files
some api

Osgi container

Service
consumer.jar
2) Introduce a correlationId
3) Collect the logs
dynamic-camel-routes.jar
some api businesslogic.jar

fat jar
consumer.jar 4) Search by rest API or use Kibana
Service
batch.jar
some api businesslogic.jar

fat jar
consumer.jar
Service
services.jar
some api businesslogic.jar

fat jar
consumer.jar
Service

logstash
business-module1.jar
some api businesslogic.jar

fat jar consumer.jar


Service
businesslogic.jar
business-module-n.jar
some api

http://www.baeldung.com/mdc-in-log4j-2-logback
https://www.elastic.co/products/elasticsearch
https://www.elastic.co/products/logstash
https://www.elastic.co/products/kibana

@betoSalazar
The path -> Split the frontend from the backend
JEE application server

Rest API consumer.jar


Rest-api-layer

businesslogic.jar

JEE application server


theApp-backend.ear
JEE application server consumer.jar
Rest-api-layer

businesslogic.jar
MODULE1.war

MODULE1-JS.jar JEE application server

theApp-backend.ear
MODULE2.war
Message Rest-api-layer
consumer.jar

MODULE3.war
Queue businesslogic.jar

css.war
rest-client.jar
producer.jar JEE application server
MODULE4.war theApp-backend.ear

theApp.ear consumer.jar
Rest-api-layer

businesslogic.jar

JEE application server

Database
theApp-backend.ear

consumer.jar
Rest-api-layer

businesslogic.jar

theApp-backend.ear

@betoSalazar
The path -> Split the frontend from the backend

Rest API
Osgi container
Rest-api-layer
Service
engine-orchestrator.jar
businesslogic.jar
some api

Osgi container
Spring MVC
Rest-api-layer
Service
dynamic-camel-routes.jar
some api businesslogic.jar

fat jar
Rest-api-layer
Service
batch.jar
some api businesslogic.jar

fat jar
Rest-api-layer
Service
services.jar
some api businesslogic.jar

fat jar
Rest-api-layer
Service
business-module1.jar
some api businesslogic.jar

fat jar Rest-api-layer


Service
businesslogic.jar
business-module-n.jar
some api

https://docs.spring.io/spring/docs/current/spring-framework-
reference/web.html#mvc-introduction

@betoSalazar
The path -> Split the frontend from the backend

Rest API Spring Webflux

https://docs.spring.io/spring/docs/current/spring-framework-reference/web-reactive.html#spring-webflux
@betoSalazar
The path -> Split the frontend from the backend

Rest API Vert.x

https://vertx.io/docs/vertx-core/java/
@betoSalazar
The path -> Split the frontend from the backend

Rest API JAX-RS JEE 8

https://javaee.github.io/tutorial/jaxrs003.html
@betoSalazar
The path

Secure your API


Osgi container

JWT Service
some api
engine-orchestrator.jar

JSON WEB TOKEN Osgi container

&
Service
React nodejs some api
dynamic-camel-routes.jar

Login

React nodejs
Authorization Server fat jar

Service
batch.jar
some api
Engine Transaction
fat jar
React nodejs POST bank.com/api/v1/accouts
Service
services.jar
Module n some api

Osgi container
fat jar
Services Service
api-gateway.jar business-module1.jar
api rest some api

fat jar
POST bank.com/api/v1/accouts
Service
some api
business-module-n.jar Database
https://jwt.io/
https://auth0.com
logstash

@betoSalazar
@EcuadorJUG @betoSalazar
The path
Osgi container Rest-api-layer

Service
Rest endpoints & API Gateway some api
businesslogic.jar
engine-orchestrator.jar

Osgi container
Rest-api-layer
Service
businesslogic.jar
dynamic-camel-routes.jar
some api

Hazelcast fat jar


Rest-api-layer
Service
POST bank.com/api/v1/accouts businesslogic.jar
batch.jar
some api

fat jar fat jar


Rest-api-layer

Services Service
api-gateway.jar businesslogic.jar
services.jar
some api
api rest

fat jar
Rest-api-layer
Service
business-module1.jar
businesslogic.jar
some api

Discovery Services via IMDG


fat jar
backbone of your Microservices architecture Rest-api-layer

Service businesslogic.jar
business-module-n.jar
some api

https://hazelcast.org/
Discovery services to inspect or rely on the contents of any named IMap

@betoSalazar
The path
The path
Split de database
Osgi container
Rest-api-layer
Service
engine-orchestrator.jar
businesslogic.jar
- Consistency Models:

some api

JEE application server


Strong vs Eventual consistency
Osgi container
Rest-api-layer
Service
MODULE1.war
- Materalized views
some api
dynamic-camel-routes.jar
businesslogic.jar

MODULE1-JS.jar
- ETL Tools fat jar
MODULE2.war Rest-api-layer
Service
batch.jar
MODULE3.war
some api businesslogic.jar
css.war POST bank.com/api/v1/accouts
fat jar
MODULE4.war Rest-api-layer
theApp.ear fat jar Service
services.jar
some api businesslogic.jar

Services
api-gateway.jar fat jar
api rest Rest-api-layer
Service
business-module1.jar
some api businesslogic.jar

POST bank.com/api/v1/accouts
Automate your database
migration https://flywaydb.org/ fat jar Rest-api-layer
Service
https://developers.redhat.com/promotions/migrating- some api
businesslogic.jar
business-module-n.jar

to-microservice-databases/

logstash

@betoSalazar
The path

Don’t forget the frontend & the agility


Osgi container
Rest-api-layer
Service
engine-orchestrator.jar
businesslogic.jar
some api

Osgi container
React nodejs Rest-api-layer
Service
Login JWT some api
dynamic-camel-routes.jar
businesslogic.jar

React nodejs JSON WEB TOKEN fat jar


Rest-api-layer
Engine Transaction Service
batch.jar
some api businesslogic.jar

React nodejs POST bank.com/api/v1/accouts


fat jar
Rest-api-layer
Module n
fat jar Service
services.jar
some api businesslogic.jar

Services
api-gateway.jar fat jar
api rest Rest-api-layer
Service
business-module1.jar
some api businesslogic.jar

POST bank.com/api/v1/accouts
fat jar Rest-api-layer
Service
businesslogic.jar
business-module-n.jar
https://jwt.io/ some api

https://nodejs.org/es/
https://facebook.github.io/react/
https://angular.io/
https://facebook.github.io/react-native/ logstash

@betoSalazar
Microservices Architecture

@betoSalazar
Containers - Orchestrators - Cloud Istio: Service Mesh

Containers (Docker) ->

Manage the same code + environment in diferente stages

Orchestrators (Kubernetes, Docker Swarm, Mesos) ->

We need to orchestrated our containers

Cloud (eg. Oracle Cloud, Google Cloud, AWS, Azure, Bluemix)

@betoSalazar
Summary &
Code blueprints repositories

asalazar@advlatam.com

@betoSalazar
The conclusion

Microservices Architecture Losses

! Transactions
! Single data repository
! Better problems solver needed (Developers /
architects)
! the system and services have to deal with
network communications, failures, rebalances,
splits.

@betoSalazar
The conclusion

Recommendations

Design your application modular (either monolith, OSGi or microservices)

Continuously refactor your modules or microservices to achieve optimal boundaries

Monolithic apps only look simple from the outside, but you just open the box

Care about logs, monitoring and always use a CORRELATIONID and MDC (Mapped Diagnostic Context)

We need to deal with service load balance, monitoring, security

@betoSalazar
The conclusion

Recommendations

Use Docker + Kubernates + Istio

Automate the deployment and delivery process -> CI & CD -> DEVOPS Culture

Secure your APIs - JWT json web token, Json Web Signature, Json Web Encryption

Use lightweight frameworks or java containers (Karaf, Vert.x, Spring boot, Microprofile
(Payara, WildFly Swarm, OpenLiberty, TomEE))

Design for failover, Service load balancing and automatic scaling, data Separation,
Integrity, Performance

@betoSalazar
code blueprints:
https://github.com/lasalazarr/fastdev

https://github.com/lasalazarr/guide-monolithic-to-
microservices
asalazar@advlatam.com

@betoSalazar
THANK YOU
Auth0 Ambassadors.
Helping the developer community make the
internet safer.
asalazar@advlatam.com

@betoSalazar

You might also like