Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Webinar "Communication Between Loosely Coupled Microservices"

Slides from the Camunda webinar "Communication Between Loosely Coupled Microservices" in February 2021. Recording can be found online: https://page.camunda.com/wb-communication-between-microservices

  • Be the first to comment

Webinar "Communication Between Loosely Coupled Microservices"

  1. 1. Microservices Webinar Series – Part 1 of 4 Communication Between Loosely Coupled Microservices @berndruecker
  2. 2. bernd.ruecker@camunda.com @berndruecker http://berndruecker.io/ Bernd Ruecker Co-founder and Chief Technologist of Camunda
  3. 3. Service A Microservices @berndruecker Monolith Service B Service C C B A D
  4. 4. Service A Autonomous Microservices @berndruecker Service B Service C
  5. 5. Photo by born1945, available under Creative Commons BY 2.0 license.
  6. 6. Service A Business capabilities require services to interact @berndruecker Service B Service C
  7. 7. Microservices Webinar Series What When Communication Between Microservices Today Benefits of Long-Running Microservices Q2/2021 Business Transactions And Consistency Q3/2021 Accelerate Via Cloud-Native Q4/2021
  8. 8. Let‘s talk about food
  9. 9. How does ordering Pizza works? Pizza Place You Phone Call Synchronous blocking communication Feedback loop (ack, confirmation or rejection) Temporal coupling (e.g. busy, not answering) Pizza Place You Email Asynchronous non-blocking communication No temporal coupling Pizza Place You A feedback loop might make sense (ack, confirmation or rejection) Email Confirmation Email
  10. 10. Feedback loop != result Pizza Place You Email Confirmation Email Pizza Delivery Feedback (ACK, confirmation, rejection) Result
  11. 11. Synchronous blocking behavior for the result? Bad user experience Does not scale well
  12. 12. Scalable Coffee Making https://www.enterpriseintegrationpatterns.com/ramblings/18_starbucks.html Photo by John Ingle @berndruecker
  13. 13. Scalable Pizza baking La Pizza Cresci Cannes https://www.maison-cresci.com/ from http://www.travellingsnail.com/content/la-pizza-cresci-cannes
  14. 14. PUT/order Synchronous results? Pizza Place You Pizza Delivery HTTP 200 The task of Pizza making is long running
  15. 15. Only the first communication step is synchronous Pizza Place You PUT/order HTTP 200 Pizza Delivery The task of Pizza making is long running
  16. 16. Only the first communication step is synchronous Pizza Place You PUT/order HTTP 200 Pizza Delivery The task of Pizza making is long running
  17. 17. Command vs. event-based communication Pizza Place You I order this pizza OK – got it Command = Intent Cannot be ignored Independant of communication channel Pizza Place You „Hey – I am hungry!“ Event = Fact Sender can't control what happens
  18. 18. Events vs. Commands „Pizza Salmon is ready!“ I baked this for my friend Andrea. Please package it immediately and deliver it over while it‘s hot!
  19. 19. Definitions Event = Something happened in the past. It is a fact. Sender does not know who picks up the event. Command = Sender wants s.th. to happen. It has an intent. Recipient does not know who issued the command.
  20. 20. Does this scale? Hey – somebody ordered Hey – Pizza is ready
  21. 21. Orchestrator Command
  22. 22. Definition Orchestration = command-driven communication Choreography = event-driven communication
  23. 23. Let‘s switch examples: Order fulfillment Checkout Payment Inventory Shipment Order placed Payment received Goods shipped Goods fetched @berndruecker
  24. 24. Event chains Checkout Payment Inventory Shipment Order placed Payment received Goods shipped Goods fetched @berndruecker
  25. 25. Phil Calcado at QCon NYC 2019
  26. 26. Order Fulfillment Orchestration and Choreography Checkout Payment Inventory Shipment Payment received Order placed Retrieve payment @berndruecker This is choreography This is orchestration
  27. 27. Order Fulfillment Collaboration style is independant of communication style Checkout Payment Inventory Shipment Payment received Order placed Retrieve payment @berndruecker Choreography Orchestration Asynchronous non-blocking Asynchronous non-blocking Synchronous blocking
  28. 28. Want to learn more about choreography vs. orchestration? https://learning.oreilly.com/library/view/practical-process-automation/9781492061441/ 30 days trial: https://learning.oreilly.com/get-learning/?code=PPAER20 Recording from QCon: https://drive.google.com/file/d/1IRWoQCX-gTPs7RVP5VrXaF1JozYWVbJv/view?usp=sharing Slides: https://www.slideshare.net/BerndRuecker/gotopia-2020-balancing-choreography-and-orchestration
  29. 29. Communication Options – Quick Summary Communication Style Synchronous Blocking Asynchronous Non-Blocking Collaboration Style Command-Driven Event-Driven Example REST Messaging (Queues) Messaging (Topics) Feedback Loop HTTP Response Response Message - Pizza Ordering via Phone Call E-Mail Twitter This is not the same!
  30. 30. Coupling
  31. 31. Types of Coupling Type of coupling Description Example Recommendation Implementation Coupling Service knows internals of other services Joined database Avoid
  32. 32. Types of Coupling Type of coupling Description Example Recommendation Implementation Coupling Service knows internals of other services Joined database Avoid
  33. 33. Types of Coupling Type of coupling Description Example Recommendation Implementation Coupling Service knows internals of other services Joined database Avoid Temporal Coupling Service depends on availability of other services Synchronous blocking communication Reduce or manage
  34. 34. Types of Coupling Type of coupling Description Example Recommendation Implementation Coupling Service knows internals of other services Joined database Avoid Temporal Coupling Service depends on availability of other services Synchronous blocking communication Reduce or manage
  35. 35. Types of Coupling Type of coupling Description Example Recommendation Implementation Coupling Service knows internals of other services Joined database Avoid Temporal Coupling Service depends on availability of other services Synchronous blocking communication Reduce or manage Deployment Coupling Multiple services can only be deployed together Release train Typically avoid, but depends
  36. 36. Types of Coupling Type of coupling Description Example Recommendation Implementation Coupling Service knows internals of other services Joined database Avoid Temporal Coupling Service depends on availability of other services Synchronous blocking communication Reduce or manage Deployment Coupling Multiple services can only be deployed together Release train Typically avoid, but depends
  37. 37. Types of Coupling Type of coupling Description Example Recommendation Implementation Coupling Service knows internals of other services Joined database Avoid Temporal Coupling Service depends on availability of other services Synchronous blocking communication Reduce or manage Deployment Coupling Multiple services can only be deployed together Release train Typically avoid, but depends Domain Coupling Business capabilities require multiple services Order fulfillment requires payment, inventory and shipping Unavoidable unless you change business requirements or service boundaries
  38. 38. Types of Coupling Type of coupling Description Example Recommendation Implementation Coupling Service knows internals of other services Joined database Avoid Temporal Coupling Service depends on availability of other services Synchronous blocking communication Reduce or manage Deployment Coupling Multiple services can only be deployed together Release train Typically avoid, but depends Domain Coupling Business capabilities require multiple services Order fulfillment requires payment, inventory and shipping Unavoidable unless you change business requirements or service boundaries This is influenced with the communication or collaboration style
  39. 39. Remote Communication
  40. 40. Patterns To Survive Remote Communication Service Consumer Pattern/Concept Use With Service Provider X Service Discovery Sync (X) X Circuit Breaker Sync X Bulkhead Sync (X) Load Balancing Sync X X Retry Sync / Async X Idempotency Sync / Async X De-duplication Async X (X) Back Pressure & Rate Limiting Sync / (Async) X X Await feedback Async X Sagas Sync / Async (X) …
  41. 41. Patterns To Survive Remote Communication Service Consumer Pattern/Concept Use With Service Provider X Service Discovery Sync (X) X Circuit Breaker Sync X Bulkhead Sync (X) Load Balancing Sync X X Retry Sync / Async X Idempotency Sync / Async X De-duplication Async X (X) Back Pressure & Rate Limiting Sync / (Async) X X Await feedback Async X Sagas Sync / Async (X) …
  42. 42. Circuit Breaker Photo by CITYEDV, available under Creative Commons CC0 1.0 license.
  43. 43. Circuit Breaker Webshop You PUT/order Address Check Payment from https://martinfowler.com/bliki/CircuitBreaker.html
  44. 44. Circuit Breaker Webshop You PUT/order Address Check Payment @CircuitBreaker(name = BACKEND, fallbackMethod = "fallback") public boolean addressValid(Address a) { return httpEndpoint.GET(...); } private boolean fallback(Address a) { return true; } e.g. Resilience4J: resilience4j.circuitbreaker: instances: BACKEND: registerHealthIndicator: true slidingWindowSize: 100 permittedNumberOfCallsInHalfOpenState: 3 minimumNumberOfCalls: 20 waitDurationInOpenState: 50s failureRateThreshold: 50
  45. 45. Circuit Breaker Webshop You PUT/order Address Check Payment @CircuitBreaker(name = BACKEND) public void retrievePayment(...) { return httpEndpoint.PUT(...); } e.g. Resilience4J:
  46. 46. Bulkhead Webshop You PUT/order Address Check Payment „Only 10 threads are allowed to wait for payment handling“
  47. 47. Retry Webshop You PUT/order Address Check Payment e.g. Resilience4J: @Retry(name = BACKEND, fallbackMethod = "fallback") public boolean addressValid(Address a) { return httpEndpoint.GET(...); } private boolean fallback(Address a) { return true; } RetryConfig config = RetryConfig.custom() .maxAttempts(5) .waitDuration(Duration.ofMillis(500)) .retryOnResult(r -> r.getStatus() == 500) .retryOnException(e -> e instanceof WebServiceException .retryExceptions(IOException.class, TimeoutException.cl .ignoreExceptions(BusinessException.class) .build();
  48. 48. Stateful retry Webshop You PUT/order Address Check Payment We wait at least 15 minutes for the payment service to become available. Bank transfer can take 7 days.
  49. 49. Stateful retry Webshop You PUT/order Address Check Payment We wait at least 15 minutes for the payment service to become available. Bank transfer can take 7 days.
  50. 50. Photo by pixabay, available under Creative Commons CC0 1.0 license.
  51. 51. Requirement: Idempotency of services! Photo by pixabay, available under Creative Commons CC0 1.0 license.
  52. 52. Requirement: Idempotency of services! Photo by Chr.Späth, available under Public Domain.
  53. 53. Make every service idempotent! Credit Card Payment Charge Credit Card cardNumber amount Charge Credit Card cardNumber amount transactionId Not idempotent Idempotent charge Generally: create Ids as soon as possible
  54. 54. Awaiting feedback from RabbitMQ manual
  55. 55. Awaiting feedback from RabbitMQ manual We wait at least 15 minutes for the payment service to become available. Bank transfer can take 7 days.
  56. 56. Did you just say „long running“?
  57. 57. Patterns To Survive Remote Communication Service Consumer Pattern/Concept Service Provider X Service Discovery (X) X Circuit Breaker Bulkhead (X) Load Balancing X X Retry X Idempotency X De-duplication X (X) Back Pressure & Rate Limiting X X Await feedback X Sagas (X)
  58. 58. Patterns For Remote Communication Service Consumer Pattern/Concept Service Provider X Service Discovery (X) X Circuit Breaker Bulkhead (X) Load Balancing X X Retry X Idempotency X De-duplication X (X) Back Pressure & Rate Limiting X X Await feedback X Sagas (X)
  59. 59. A hard decision
  60. 60. Take Away • Know • communication styles (sync/async) • collaboration styles (command/event) • Patterns to survive • You can get rid of temporal coupling with asynchronous communication • Make sure you or your team can handle it • You will need long running capabilities (you might need it anyway) • Domain coupling does not go away!
  61. 61. Want to know more? https://page.camunda.com/wp-ultimate- guide-to-process-automation-and- microservices
  62. 62. Thank you! @berndruecker
  63. 63. mail@berndruecker.io @berndruecker https://berndruecker.io https://medium.com/berndruecker https://github.com/berndruecker Contact: Slides: Blog: Code: https://learning.oreilly.com/library /view/practical-process- automation/9781492061441/ 30 days trial: https://learning.oreilly.com/get- learning/?code=PPAER20

×