Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Migrating Monoliths to Microservices -- M3

Asir Vedamuthu Selvasingh
September 09, 2020
86

Migrating Monoliths to Microservices -- M3

Have a legacy software portfolio? Stepping into unfamiliar code, especially legacy code, can be very scary. Code uses local file system or unusual directory layout or homegrown shim for interacting with databases, cache or user directories, secrets lying bare etc.

You can confront monoliths and transform them. So, where do you start when considering an app migration? What apps need to continue running for the next six years and at a lower cost?

Let's look at what and why for monolith & n-tier ==> microservice architecture transformation. What are the popular microservice frameworks for Java customers? How to decompose monolith to microservices? Why Spring cloud and what are its key components? As you walk away, you will be ready to dive deeper and go hands-on with Spring Cloud microservices.

Asir Vedamuthu Selvasingh

September 09, 2020
Tweet

Transcript

  1. ©Microsoft Corporation Azure Asir Selvasingh Principal PM Architect Java on

    Microsoft Azure On-point for everything developers need to build, migrate and scale Java applications on Azure. Started software engineering career in the early days of Java, in 1995, and built enterprise products, applications and open source projects.
  2. What is microservices architecture? suite of small services its own

    process lightweight independently deployable different programming languages different data storage technologies
  3. Microservices are analogous to honeycomb aligning start small different materials

    Repetitive independent integrated grows organically solid abstracted reconstruct
  4. Microservice principles – 12 factor app (2 of 2) •

    • • • • • • • • • • •
  5. Spring Cloud LoadBalancer (client-side) • Moves beyond a single hard-coded

    server URL to a load-balanced solution • Provides client-side load balancing in calls to another microservice • Distributed systems demand an advanced set of routing and load balancing behaviors for microservice to microservice communications One microservice wants to call another microservice, looks up the service registry, returns all the instances of the calling microservice, caller service headache for which instance it calls
  6. Spring Cloud Gateway Cannot duplicate or scatter cross cutting measures

    across microservices – securing, routing, rate limiting, caching, monitoring, hiding services, etc.
  7. Example - Spring Cloud Gateway and LoadBalancer combined • Two

    instances of callme-service • Single instance of caller-service, which uses Spring Cloud Balancer to find the list of available instances of callme- service • callme-service ports are generated dynamically • Spring Cloud Gateway is hiding the complexity of our system from external client. It is open on 8080 and is forwarding requests to the downstream based on request context path.
  8. Example – Spring Cloud Circuit Breaker and Resilience4j @Bean public

    Customizer<ReactiveResilience4JCircuitBreakerFactory> defaultCustomizer() { return factory -> factory.configureDefault(id -> new Resilience4JConfigBuilder(id) .circuitBreakerConfig(CircuitBreakerConfig.custom() .slidingWindowSize(5) .permittedNumberOfCallsInHalfOpenState(5) .failureRateThreshold(50.0F) .waitDurationInOpenState(Duration.ofMillis(30)) .build()) .timeLimiterConfig(TimeLimiterConfig.custom().timeoutDuration(Duration.ofMillis(200)).build()).build()); } • slidingWindowSize is equal to 5 • If 3 timeouts during last 5 calls, circuit is switched to OPEN state • waitDurationInOpenState is set to 30 milliseconds • after 30 milliseconds the circuit is switched to HALF_OPEN state • permittedNumberOfCallsInHalfOpenState is set to 5 • In this five attempts we get <= 2 timeouts, circuit is switched to CLOSE state
  9. Spring Cloud Sleuth and Zipkin – Distributed Tracing Debugging distributed

    apps can be complex and take long time • Spring Cloud Sleuth can instrument apps in a predictable and repeatable way • Zipkin can zero in on latency problems • Together, they trace requests through microservices • Adds trace and span ids to logs • appname: name of the app that logged the span • traceId: ID assigned to a single request, job, or action • spanId: ID of a specific operation that took place • exportable: should the log be exported to Zipkin?
  10. Capstone (2 of 3) – Spring Cloud Components Spring Cloud

    Apps Spring Cloud Components Spring Cloud Components Cloud Services App Consumers Breaker dashboard Service registry Distributed tracing Config dashboard IoT Mobile Browser API Gateway Microservices Microservices Microservices Message brokers Databases Build distributed systems by - • Versioning, distributing, and refreshing configuration via config server and management bus • Dynamically discovering remote dependencies • Decentralizing load balancing decisions • Preventing cascading failures through circuit breakers and bulkheads • Integrating on the behalf of specific clients via gateway • Instrumenting apps for distributed tracing
  11. Capstone (3 of 3) – Migrate Monolith to Microservices -

    M3 Decompose monolithic applications using three principles
  12. Pattern – Backends for Frontends (BFF) Different user experiences want

    to make similar types of calls https://samnewman.io/patterns/architectural/bff/ Single BFF for each different type of client
  13. Mikado Methodology – Breaking up a Monolith The Mikado Method

    by Ola Ellnestam and Daniel Brolund Published by Manning Publications, 2014
  14. Mikado Methodology – Breaking up a Monolith Existing monolith -

    one entry point to the server, from which all the calls are then dispatched using an action parameter. There are three actions that can be performed: •Apply •Fetch •Approve The Mikado Method by Ola Ellnestam and Daniel Brolund Published by Manning Publications, 2014
  15. Securing service-to- service communications and sharing user context between microservices

    (with the same JWT) Siriwardena, P., & Dias, N. (2020). Microservices security in action. New York: Manning Publications.
  16. Modernizing Batch Jobs Batch processing has been around for a

    long time. Since the dawn of automated computing, gathering data, running a process over it, and generating output from it have been a fundamental piece of it. As enterprises transition to the cloud, it is just natural that batch processing also migrates there. Running batch applications on a modern cloud platform is not only possible, but provides real benefits – leverage distributed batch
  17. Upgrade older variants of Spring Microservice apps Old Stack New

    Stack Spring Cloud Eureka Spring Cloud Service Registry Spring Cloud Netflix Zuul Spring Cloud Gateway Spring Cloud Netflix Archaius Spring Cloud Config Server Spring Cloud Netflix Ribbon Spring Cloud Load Balancer (client-side load balancer) Spring Cloud Hystrix Spring Cloud Circuit Breaker + Resilience4J Spring Cloud Netflix Turbine Micrometer + Prometheus
  18. Prep Apps for Azure Spring Cloud Spring Boot Version Spring

    Cloud Version Azure Spring Cloud Version 2.1 Greenwich.RELEASE 2.1.2 2.2 Hoxton.SR8 Not needed 2.3 Hoxton.SR8 Not needed
  19. Deploy Spring Microservice Apps to Azure Spring Cloud $ az

    spring-cloud create –n my-spring-cloud \ -g my-resource-group –l westus2 $ az spring-cloud config-server set \ --config-file application.yml $ az spring-cloud app create -n account-service \ --instance-count 1 --is-public true $ az spring-cloud app deploy -n account-service \ --jar-path target\account-service.jar $ az spring-cloud app logs -f -n account-service
  20. Need Microsoft Help to Build or Migrate Your Java Apps

    to Azure Spring Cloud? (1 of 2) We can a) Guide your design and plan – thru architecture design session / workshop b) Help build representative proof of concepts or pilot • By customer and engineers in Java on Azure team c) Migrate your Java apps to Azure Spring Cloud • By Microsoft Consulting Services (MCS) Nominate yourself …
  21. Need Microsoft Help to Build or Migrate Your Java Apps

    to Azure Spring Cloud? (2 of 2) http://aka.ms/pilot-my-spring-cloud-apps
  22. Session takeaways Learning Objective – be able to Takeaways Explain

    microservices Covered what and why for Monolith & N-tier to Microservice architecture transformation Confront monoliths Shared recipes for transforming monoliths and several migration routes Dive deeper and go hands-on with Spring Cloud Covered base Spring Cloud components that are backbone for microservices
  23. Session resources 1 – Spring Cloud Spring Cloud Config Server

    Spring Cloud Service Registry Spring Cloud Gateway Spring Cloud Load Balancer Spring Cloud Circuit Breaker Spring Cloud Sleuth and Zipkin
  24. Q&A