SlideShare a Scribd company logo
Microservices with Spring
Carlos Cavero Barca
Monolithic is not the evil
Esta foto de Autor desconocido está bajo licencia CC BY-NC
Microservices versus Monolithic
Microservices
 Loosely couple services
 Distributed architecture and multiple
failure points
 DevOps and Agile cultures easing the
use of the hype technologies
 Easy and quick deployment of new
versions
 More implementation to integrate
the services
 Async and sync communication
 More configuration and automation
Monolithic
 One big service
 Multiple functionalities
 Unique failure point
 Hard to apply novel technologies due
to restrictions
 Hard and slow deployment of new
versions
 Simple implementation because of
simple integration
 Less configuration
(*) https://articles.microservices.com/monolithic-vs-microservices-architecture-5c4848858f59
Monolithic is not the evil…
it is just another alternative architecture to start with
Esta foto de Autor desconocido está bajo licencia CC BY-NC
Microservices patterns and antipatterns
Patterns
 Discovery
 Load Balancing
 Circuit Breaker
 Database per service
 Observability (health, metrics…)
 Multiple service per host
 Externalized configuration
 API Gateway
 Access Token
 Service Decomposition
Antipatterns
 Avoid making microservice the goal
 Why not start with a monolit?
 Inefficient processes and practices - waterfall
process, manual testing, manual deployment
 Silo’d organization - e.g. development hands
off code to QA for testing.
 Poor software quality - the application is a
big ball of mud, the code is anything but
clean, etc
(*) https://microservices.io/patterns/microservices.html
(*) https://chrisrichardson.net/post/antipatterns/2019/01/14/antipattern-microservices-are-the-goal.html
Spring Boot Actuator
Benefits
 Provide multiple endpoints with
metrics and health information about
the Spring service
 Monitor the status of the application
 Always add the dependency to your
Project (using spring initalizr for
instance)
 Mandatory for service Discovery,
traceback, load balancing and circuit
breaker
 Dependency spring-boot-starter-
actuator
Endpoints
Service
/health
/info
/metrics
/trace
/beans
/configprops
/env
/refresh
Service Discovery
Benefits
 Solve the ephemeral condition of the
microservices
 Dinamyc configuration of the services
 Discovering instead of static configuration
 Discover the host and port by using names
instead of Ips or DNS
 Register when launching the application,
the name, host name and available port
 Consult the /health endpoint of the
service (from the dependency actuator)
Service Discovery
Service1
Service
Discovery
Service2
register
register
/health /health
Service Discovery with Eureka
Benefits
 Client-side Discovery
 @EnableEurekaServer annotation
 Cluster configuration recommended
 En caso de caída se elige uno nuevo y este
cambio es transparente para las aplicaciones
cliente (si tienen su propio agente Consul cliente
configurado correctamente). Eureka, en cambio,
si un servidor se cae, son las aplicaciones cliente
las que activamente comunican con el siguiente
servidor Eureka configurado en ellas.
 Además, ofrece interfaz DNS para comunicarse,
algo que Eureka no por lo que no estamos atados
a comunicación REST y además incluye
almacenamiento KV, lo que permite centralizar
la configuración en el mismo sistema.
Netflix Eureka
Service Discovery with Consul
Benefits
 Client-side Discovery
 Fault tolerance and load balancing at server
side
 Simple key/value storage for configuration
and feature flagging
 @EnableDiscoveryClient and the dependency
spring-cloud-starter-consul-all
 It can substitute Eureka and Cloud Config
 Start Consul Agent in local workstation at
http://localhost:8500
 Download the binary
consul agent -server -bootstrap-expect=1 -data-
dir=consul-data -ui -bind=<your IP>
Consul
Service1
Service
Discovery
Service2
register
register
/health /health
API Gateway and intelligent routing with
Zuul
Benefits
 Proxy that centralizes all the
requests and routes them to the
proper microservice
 Authentication and authorization
interceptors
 Implement Circuit Breaker (Hystrix)
 Zuul provides Load Balancing in the
server side (with Ribbon) and not in
the client side like Ribbon
 Canary testing
API Gateway and Routing
Zuul
Service1
Service
Discovery
Service2
Client
Cloud Config Server
Benefits
 Configuration is independent of the artefact
 Configuration parameters are externalized
and it is possible to get the latest version
easily
 Different environments (test, staging and
production) can be separated
 It is language agnostic because it publishes
an API REST
 Refresh automatically the configuration with
http://localhost:8090/monitor
 Encrypt the configuration values at the
server side and decrypt at client side with
/encrypt and /decrypt endpoints
 @EnableConfigServer
Cloud Config Server
Cloud Config
Zuul
Service1
Service
Discovery
Service2
Client
Circuit Breaker with Hystrix
Benefits
 Break the circuit in case of failure or latency
(like an electric one) providing valid
alternatives instead
 If the number of errors is above the threshold
the circuit is open and no more requests can
be done
 Automatic checking of the /health endpoint
until the service is available again
 Provides resilience and fault tolerance
avoiding the propagation of failures,
unlimited time-response and isolation of
point of access
 Two possible solutions to return a default
value: no availability or failure and timeout
 @HystrixCommand with a valid fallback
Hystrix
Service1
Service
Discovery
Service2
register
discover
/health /health
Hystrix fallback
Client-side Load Balancing with Ribbon
Benefits
 Load Balancing at client level
 Multiple instances of the same
service
 Distribution of workloads
 Get the information from the
Discovery service and select the right
instance
 If a instance is not available and
Eureka is no updated then some
Fallback could be sent. To solve this
you can use a proxy (Zuul)
 Choose and round-robin
Ribbon
Client
Service
Discovery
Service2
register
discover
/health
Replica1
Replica2
round-robin
Pub/Sub with RabbitMQ
Benefits
 Message Broker
 Producers send to the queues
 Consumers read from the queues
 Async communication
 Distributed (micro)services
 AMQP protocol
Message Broker – Spring Cloud Bus
Event Producer
Consumer1 Consumer2 Consumer3
Client
resource.updated
resource.created
(*) https://reflectoring.io/event-messaging-with-spring-boot-and-rabbitmq/
(*) http://cloud.spring.io/spring-cloud-static/spring-cloud-bus/2.0.0.RELEASE/single/spring-cloud-bus.html#_quick_start
(*) http://cloud.spring.io/spring-cloud-static/spring-cloud-config/2.0.1.RELEASE/single/spring-cloud-
config.html#_push_notifications_and_spring_cloud_bus
OpenFeign
Benefits
 Reduce the complexity of binding
API HTTP REST calls
 Takes care of Load Balancing and
Discovery if Ribbon and Eureka are
included as dependency
 @FeignClient(name=“spring-
service-name")
Spring Security OAuth
Benefits
 Provides Oauth 2.0 authentication
 It can also connect with other IdM
tools (such as Keycloak)
Project Lombok
Benefits
 Java library that automatically
plugs into your editor and build
tools with less programming
 Fully integrated with Spring
 Getters, setters or equals methods
automatically embedded in the
data model
 With annotations obtain a fully
featured builder
 Automate your logging variables
How to make it works in
Eclipse IDE
Esta foto de Autor desconocido está bajo licencia CC BY-SA
 When starting a fresh Eclipse
installation Lombok needs to be
configured:
 Go where your jar is, run it:
java –jar lombok-1.18.8.jar
 Click on Install/Update
 Launch Eclipse and update project
configuration
And much more
 Distributed tracing with Zipkin and Sleuth

More Related Content

PDF
The Evolution of Distributed Systems on Kubernetes
PDF
Kafka at the Edge: an IoT scenario with OpenShift Streams for Apache Kafka | ...
PDF
Kubernetes: The evolution of distributed systems | DevNation Tech Talk
PDF
Distributed Enterprise Monitoring and Management of Apache Kafka (William McL...
PDF
How Confluent Completes the Event Streaming Platform (Addison Huddy & Dan Ros...
PDF
How Apache Kafka® Works
PDF
Mainframe Integration, Offloading and Replacement with Apache Kafka | Kai Wae...
PDF
Redis and Kafka - Simplifying Advanced Design Patterns within Microservices A...
The Evolution of Distributed Systems on Kubernetes
Kafka at the Edge: an IoT scenario with OpenShift Streams for Apache Kafka | ...
Kubernetes: The evolution of distributed systems | DevNation Tech Talk
Distributed Enterprise Monitoring and Management of Apache Kafka (William McL...
How Confluent Completes the Event Streaming Platform (Addison Huddy & Dan Ros...
How Apache Kafka® Works
Mainframe Integration, Offloading and Replacement with Apache Kafka | Kai Wae...
Redis and Kafka - Simplifying Advanced Design Patterns within Microservices A...

What's hot (20)

PPTX
A Look into the Mirror: Patterns and Best Practices for MirrorMaker2 | Cliff ...
PDF
Taming a massive fleet of Python-based Kafka apps at Robinhood | Chandra Kuch...
PDF
Dual write strategies for microservices
PDF
Orchestration Patterns for Microservices with Messaging by RabbitMQ
PDF
Making your Life Easier with MongoDB and Kafka (Robert Walters, MongoDB) Kafk...
PDF
Lessons from the field: Catalog of Kafka Deployments | Joseph Niemiec, Cloudera
PPTX
Cloud native Kafka | Sascha Holtbruegge and Margaretha Erber, HiveMQ
PDF
Leveraging Microservices and Apache Kafka to Scale Developer Productivity
PDF
Asynchronous Microservices in nodejs
PDF
Stream Processing with Kafka and KSQL in Jupiter | Namit Mahuvakar, Jupiter
PPTX
Microservices with Node and Docker
PDF
Kafka Excellence at Scale – Cloud, Kubernetes, Infrastructure as Code (Vik Wa...
PDF
The New Way of Configuring Grace Periods for Windowed Operations in Kafka Str...
PDF
Building adaptive user experiences using Contextual Multi-Armed Bandits with...
PDF
KrakenD API Gateway
PDF
Event-driven Applications with Kafka, Micronaut, and AWS Lambda | Dave Klein,...
PDF
Testing Event Driven Architectures: How to Broker the Complexity | Frank Kilc...
PDF
Exposing and Controlling Kafka Event Streaming with Kong Konnect Enterprise |...
PDF
Event-driven Applications with Kafka, Micronaut, and AWS Lambda | Dave Klein,...
PDF
Demystifying Event-Driven Architectures with Apache Kafka | Bogdan Sucaciu, P...
A Look into the Mirror: Patterns and Best Practices for MirrorMaker2 | Cliff ...
Taming a massive fleet of Python-based Kafka apps at Robinhood | Chandra Kuch...
Dual write strategies for microservices
Orchestration Patterns for Microservices with Messaging by RabbitMQ
Making your Life Easier with MongoDB and Kafka (Robert Walters, MongoDB) Kafk...
Lessons from the field: Catalog of Kafka Deployments | Joseph Niemiec, Cloudera
Cloud native Kafka | Sascha Holtbruegge and Margaretha Erber, HiveMQ
Leveraging Microservices and Apache Kafka to Scale Developer Productivity
Asynchronous Microservices in nodejs
Stream Processing with Kafka and KSQL in Jupiter | Namit Mahuvakar, Jupiter
Microservices with Node and Docker
Kafka Excellence at Scale – Cloud, Kubernetes, Infrastructure as Code (Vik Wa...
The New Way of Configuring Grace Periods for Windowed Operations in Kafka Str...
Building adaptive user experiences using Contextual Multi-Armed Bandits with...
KrakenD API Gateway
Event-driven Applications with Kafka, Micronaut, and AWS Lambda | Dave Klein,...
Testing Event Driven Architectures: How to Broker the Complexity | Frank Kilc...
Exposing and Controlling Kafka Event Streaming with Kong Konnect Enterprise |...
Event-driven Applications with Kafka, Micronaut, and AWS Lambda | Dave Klein,...
Demystifying Event-Driven Architectures with Apache Kafka | Bogdan Sucaciu, P...
Ad

Similar to Microservices with Spring (20)

PDF
Микросервисы со Spring Boot & Spring Cloud
PPTX
Microservice creation using spring cloud, zipkin, ribbon, zull, eureka
PPTX
MicroService Architecture
PDF
Monolithic to Microservices Migration Journey of iyzico with Spring Cloud
PDF
Microservices - not just with Java
PDF
Microservices with Java, Spring Boot and Spring Cloud
PDF
Monolithic to microservices migration journey with spring cloud
PPTX
Springboot Microservices
PDF
Cloudify your applications: microservices and beyond
PPT
JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?
PPT
Flying to clouds - can it be easy? Cloud Native Applications
PPTX
Micro Services Architecture
PDF
Spring Cloud: Why? How? What?
PDF
Building ‘Bootiful’ microservices cloud
PPTX
Implementing Micro Services Tasks (service discovery, load balancing etc.) - ...
PDF
Four Times Microservices - REST, Kubernetes, UI Integration, Async
PPTX
Intro to spring cloud &microservices by Eugene Hanikblum
PDF
Microservices with Spring Cloud and Netflix OSS
PDF
Arquitecturas de microservicios - Medianet Software
PPTX
Pros and Cons of a MicroServices Architecture talk at AWS ReInvent
Микросервисы со Spring Boot & Spring Cloud
Microservice creation using spring cloud, zipkin, ribbon, zull, eureka
MicroService Architecture
Monolithic to Microservices Migration Journey of iyzico with Spring Cloud
Microservices - not just with Java
Microservices with Java, Spring Boot and Spring Cloud
Monolithic to microservices migration journey with spring cloud
Springboot Microservices
Cloudify your applications: microservices and beyond
JDD 2016 - Jacek Bukowski - "Flying To Clouds" - Can It Be Easy?
Flying to clouds - can it be easy? Cloud Native Applications
Micro Services Architecture
Spring Cloud: Why? How? What?
Building ‘Bootiful’ microservices cloud
Implementing Micro Services Tasks (service discovery, load balancing etc.) - ...
Four Times Microservices - REST, Kubernetes, UI Integration, Async
Intro to spring cloud &microservices by Eugene Hanikblum
Microservices with Spring Cloud and Netflix OSS
Arquitecturas de microservicios - Medianet Software
Pros and Cons of a MicroServices Architecture talk at AWS ReInvent
Ad

Recently uploaded (20)

PPTX
Operating system designcfffgfgggggggvggggggggg
PPTX
ManageIQ - Sprint 268 Review - Slide Deck
PDF
medical staffing services at VALiNTRY
PDF
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
PPTX
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
PDF
How to Migrate SBCGlobal Email to Yahoo Easily
PDF
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
top salesforce developer skills in 2025.pdf
PPTX
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
PDF
How Creative Agencies Leverage Project Management Software.pdf
PDF
System and Network Administraation Chapter 3
PDF
Nekopoi APK 2025 free lastest update
PDF
PTS Company Brochure 2025 (1).pdf.......
PPTX
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
PDF
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
System and Network Administration Chapter 2
PPTX
Introduction to Artificial Intelligence
Operating system designcfffgfgggggggvggggggggg
ManageIQ - Sprint 268 Review - Slide Deck
medical staffing services at VALiNTRY
Why TechBuilder is the Future of Pickup and Delivery App Development (1).pdf
Internet Downloader Manager (IDM) Crack 6.42 Build 42 Updates Latest 2025
Oracle E-Business Suite: A Comprehensive Guide for Modern Enterprises
How to Migrate SBCGlobal Email to Yahoo Easily
T3DD25 TYPO3 Content Blocks - Deep Dive by André Kraus
Navsoft: AI-Powered Business Solutions & Custom Software Development
top salesforce developer skills in 2025.pdf
Lecture 3: Operating Systems Introduction to Computer Hardware Systems
How Creative Agencies Leverage Project Management Software.pdf
System and Network Administraation Chapter 3
Nekopoi APK 2025 free lastest update
PTS Company Brochure 2025 (1).pdf.......
CHAPTER 12 - CYBER SECURITY AND FUTURE SKILLS (1) (1).pptx
Audit Checklist Design Aligning with ISO, IATF, and Industry Standards — Omne...
Internet Downloader Manager (IDM) Crack 6.42 Build 41
System and Network Administration Chapter 2
Introduction to Artificial Intelligence

Microservices with Spring

  • 2. Monolithic is not the evil Esta foto de Autor desconocido está bajo licencia CC BY-NC
  • 3. Microservices versus Monolithic Microservices  Loosely couple services  Distributed architecture and multiple failure points  DevOps and Agile cultures easing the use of the hype technologies  Easy and quick deployment of new versions  More implementation to integrate the services  Async and sync communication  More configuration and automation Monolithic  One big service  Multiple functionalities  Unique failure point  Hard to apply novel technologies due to restrictions  Hard and slow deployment of new versions  Simple implementation because of simple integration  Less configuration (*) https://articles.microservices.com/monolithic-vs-microservices-architecture-5c4848858f59
  • 4. Monolithic is not the evil… it is just another alternative architecture to start with Esta foto de Autor desconocido está bajo licencia CC BY-NC
  • 5. Microservices patterns and antipatterns Patterns  Discovery  Load Balancing  Circuit Breaker  Database per service  Observability (health, metrics…)  Multiple service per host  Externalized configuration  API Gateway  Access Token  Service Decomposition Antipatterns  Avoid making microservice the goal  Why not start with a monolit?  Inefficient processes and practices - waterfall process, manual testing, manual deployment  Silo’d organization - e.g. development hands off code to QA for testing.  Poor software quality - the application is a big ball of mud, the code is anything but clean, etc (*) https://microservices.io/patterns/microservices.html (*) https://chrisrichardson.net/post/antipatterns/2019/01/14/antipattern-microservices-are-the-goal.html
  • 6. Spring Boot Actuator Benefits  Provide multiple endpoints with metrics and health information about the Spring service  Monitor the status of the application  Always add the dependency to your Project (using spring initalizr for instance)  Mandatory for service Discovery, traceback, load balancing and circuit breaker  Dependency spring-boot-starter- actuator Endpoints Service /health /info /metrics /trace /beans /configprops /env /refresh
  • 7. Service Discovery Benefits  Solve the ephemeral condition of the microservices  Dinamyc configuration of the services  Discovering instead of static configuration  Discover the host and port by using names instead of Ips or DNS  Register when launching the application, the name, host name and available port  Consult the /health endpoint of the service (from the dependency actuator) Service Discovery Service1 Service Discovery Service2 register register /health /health
  • 8. Service Discovery with Eureka Benefits  Client-side Discovery  @EnableEurekaServer annotation  Cluster configuration recommended  En caso de caída se elige uno nuevo y este cambio es transparente para las aplicaciones cliente (si tienen su propio agente Consul cliente configurado correctamente). Eureka, en cambio, si un servidor se cae, son las aplicaciones cliente las que activamente comunican con el siguiente servidor Eureka configurado en ellas.  Además, ofrece interfaz DNS para comunicarse, algo que Eureka no por lo que no estamos atados a comunicación REST y además incluye almacenamiento KV, lo que permite centralizar la configuración en el mismo sistema. Netflix Eureka
  • 9. Service Discovery with Consul Benefits  Client-side Discovery  Fault tolerance and load balancing at server side  Simple key/value storage for configuration and feature flagging  @EnableDiscoveryClient and the dependency spring-cloud-starter-consul-all  It can substitute Eureka and Cloud Config  Start Consul Agent in local workstation at http://localhost:8500  Download the binary consul agent -server -bootstrap-expect=1 -data- dir=consul-data -ui -bind=<your IP> Consul Service1 Service Discovery Service2 register register /health /health
  • 10. API Gateway and intelligent routing with Zuul Benefits  Proxy that centralizes all the requests and routes them to the proper microservice  Authentication and authorization interceptors  Implement Circuit Breaker (Hystrix)  Zuul provides Load Balancing in the server side (with Ribbon) and not in the client side like Ribbon  Canary testing API Gateway and Routing Zuul Service1 Service Discovery Service2 Client
  • 11. Cloud Config Server Benefits  Configuration is independent of the artefact  Configuration parameters are externalized and it is possible to get the latest version easily  Different environments (test, staging and production) can be separated  It is language agnostic because it publishes an API REST  Refresh automatically the configuration with http://localhost:8090/monitor  Encrypt the configuration values at the server side and decrypt at client side with /encrypt and /decrypt endpoints  @EnableConfigServer Cloud Config Server Cloud Config Zuul Service1 Service Discovery Service2 Client
  • 12. Circuit Breaker with Hystrix Benefits  Break the circuit in case of failure or latency (like an electric one) providing valid alternatives instead  If the number of errors is above the threshold the circuit is open and no more requests can be done  Automatic checking of the /health endpoint until the service is available again  Provides resilience and fault tolerance avoiding the propagation of failures, unlimited time-response and isolation of point of access  Two possible solutions to return a default value: no availability or failure and timeout  @HystrixCommand with a valid fallback Hystrix Service1 Service Discovery Service2 register discover /health /health Hystrix fallback
  • 13. Client-side Load Balancing with Ribbon Benefits  Load Balancing at client level  Multiple instances of the same service  Distribution of workloads  Get the information from the Discovery service and select the right instance  If a instance is not available and Eureka is no updated then some Fallback could be sent. To solve this you can use a proxy (Zuul)  Choose and round-robin Ribbon Client Service Discovery Service2 register discover /health Replica1 Replica2 round-robin
  • 14. Pub/Sub with RabbitMQ Benefits  Message Broker  Producers send to the queues  Consumers read from the queues  Async communication  Distributed (micro)services  AMQP protocol Message Broker – Spring Cloud Bus Event Producer Consumer1 Consumer2 Consumer3 Client resource.updated resource.created (*) https://reflectoring.io/event-messaging-with-spring-boot-and-rabbitmq/ (*) http://cloud.spring.io/spring-cloud-static/spring-cloud-bus/2.0.0.RELEASE/single/spring-cloud-bus.html#_quick_start (*) http://cloud.spring.io/spring-cloud-static/spring-cloud-config/2.0.1.RELEASE/single/spring-cloud- config.html#_push_notifications_and_spring_cloud_bus
  • 15. OpenFeign Benefits  Reduce the complexity of binding API HTTP REST calls  Takes care of Load Balancing and Discovery if Ribbon and Eureka are included as dependency  @FeignClient(name=“spring- service-name")
  • 16. Spring Security OAuth Benefits  Provides Oauth 2.0 authentication  It can also connect with other IdM tools (such as Keycloak)
  • 17. Project Lombok Benefits  Java library that automatically plugs into your editor and build tools with less programming  Fully integrated with Spring  Getters, setters or equals methods automatically embedded in the data model  With annotations obtain a fully featured builder  Automate your logging variables How to make it works in Eclipse IDE Esta foto de Autor desconocido está bajo licencia CC BY-SA  When starting a fresh Eclipse installation Lombok needs to be configured:  Go where your jar is, run it: java –jar lombok-1.18.8.jar  Click on Install/Update  Launch Eclipse and update project configuration
  • 18. And much more  Distributed tracing with Zipkin and Sleuth