Microservices
Patterns & Practice
Rafael Monteiro
TICNOVA 2018
Maringá – PR
Formado em Ciência
da Computação pela
Universidade
Presbiteriana
Mackenzie
Mestrando em
Inteligência Artificial
Software Engineer /
Data Scientist
Agenda
Introduction to Microservices
Data Patterns
Integration Patterns
Testing Microservices
Operations
Deployment
Introduction to
Microservices
Monolithic
Architecture
Microservices
Architecture
Microservices Architecture
• This solution has a number of benefits:
• Enables the continuous delivery and deployment of large, complex
applications.
• Smaller and faster to test
• Services can be deployed independently
• Each microservice is relatively small
• Easier to understand
• The application starts faster, which makes developers more productive, and
speeds up deployments
Source: https://microservices.io/patterns/
Microservices Architecture
• Improved fault isolation
• Eliminates any long-term commitment to a technology stack.
Source: https://microservices.io/patterns/
Data Patterns
Shared Database
One Database
per service
CQRS
• How to implement queries
in a microservice
architecture?
Event
Sourcing
How to reliably/atomically
publish events whenever state
changes?
Integration
Patterns
Service Discovery
Service
registry
Client-side
service
discovery
Server-side
service
discovery
Client-side service discovery
Server-side service discovery
Eureka
Circuit Breaker
How to prevent a network or service failure from cascading to other services?
Circuit Breaker
• Services handle the failure of the
services that they invoke
• It is challenging to choose timeout
values without creating false
positives or introducing excessive
latency.
Hystrix
API
Gateway
Contract First
API
Gateway
Saga Pattern
• Problem
• Each service has its own
database
• How to maintain data
consistency across
services?
Saga Pattern
Saga Pattern
Saga Pattern
Messaging
•Services communicating
by exchanging messages
over messaging channels.
Data Source
hell...
Much better….
Schema
Registry
Testing your
Microservices
Contract Testing
Contract Testing
Operations
Log aggregation
How to understand the behavior of an application and troubleshoot
problems?
Use a centralized logging service that aggregates logs from each service
instance. The users can search and analyze the logs. They can configure
alerts that are triggered when certain messages appear in the logs.
Log aggregation
Health Check API
•How to detect that a
running service instance
is unable to handle
requests?
Health Check API
This pattern has the following drawbacks:
The health check might not sufficiently comprehensive or the service instance might fail between health
checks and so requests might still be routed to a failed service instance
The health check endpoint enables the health of a service instance to be
periodically tested
Health Check API
• A service has an health check API endpoint
(e.g. HTTP /health) that returns the health
of the service. The API endpoint handler
performs various checks, such as
• the status of the connections to the
infrastructure services used by the
service instance
• the status of the host, e.g. disk space
• application specific logic
Health Check API
Application
metrics
Prometheus , New Relic ,
AppDynamics, Grafana +
InfluxDB.
How to understand the
behavior of an application and
troubleshoot problems?
Distributed tracing
How to understand the
behavior of an application
and troubleshoot problems?
Assigns each external request
a unique external request id
Passes the external request
id to all services that are
involved in handling the
request
Includes the external request
id in all log messages
Records information (e.g.
start time, end time) about
the requests and operations
performed when handling a
external request in a
centralized service
Distributed tracing
Ex: Spring Cloud Sleuth
Deployment
Deployment Patterns
Single Service
Instance per
Host
Multiple service
instances per
host
Service Instance
per VM
Service instance
per container
Service
deployment
platform
Deployment Patterns
References
• Livro Migrating to Microservice
Databases – Edson Yanaga
• https://microservices.io/
• http://www.confluente.io
• https://www.enterpriseintegrationpatt
erns.com/
• https://www.nginx.com/blog/introduct
ion-to-microservices/
• https://en.paradigmadigital.com/dev/s
pring-cloud-microservices-architecture-
12/
• https://dzone.com/articles/distributed-
sagas-for-microservices
E-mail: rafael@monteiro.io
Github:
github.com/rafamonteiro
LinkedIn:
https://bit.ly/2jQQIXj
Obrigado!!!!
Feedback ? Contato ?

Microservices: Patterns & Practices