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

2019-07-11.aws-summit-cape-town.map002.application-integration-patterns-for-microservices.pdf

 2019-07-11.aws-summit-cape-town.map002.application-integration-patterns-for-microservices.pdf

One of the implications of applying the microservices architectural style is that a lot of communication between components is done over the network. In order to achieve the promises of microservices, this communication needs to happen in a loosely coupled manner.

One option that many architects have in mind here is that all services expose an API following the REST architectural style. However, there is another option that provides even looser coupling: asynchronous messaging. In discussions with customers we saw that this option is not always on the radar of architects.

In this talk, we want to discuss some fundamental application integration patterns mostly based on messaging and connect them to real-world use cases in a micro services scenario. In doing so, we will also point out some benefits that asynchronous messaging can have over REST APIs for the communication between microservices.

Dirk Fröhner

July 11, 2019
Tweet

More Decks by Dirk Fröhner

Other Decks in Technology

Transcript

  1. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Application Integration Patterns for Microservices Dirk Fröhner Solutions Architect Amazon Web Services [email protected] @dirk_f5r M A P 0 0 2
  2. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Application Integration Patterns (not only) for Microservices M A P 0 0 2 Dirk Fröhner Solutions Architect Amazon Web Services [email protected] @dirk_f5r
  3. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Agenda Introduction Application integration patterns Concrete use cases
  4. S U M M I T © 2019, Amazon Web

    Services, Inc. or its affiliates. All rights reserved.
  5. S U M M I T © 2019, Amazon Web

    Services, Inc. or its affiliates. All rights reserved. “If your application is cloud-native, or large-scale, or distributed, and doesn’t include a messaging component, that’s probably a bug.” Tim Bray Senior Principal Engineer, AWS Messaging, Eventing & Orchestration
  6. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Potential drawbacks of synchronous systems Synchronous systems are tightly coupled. A problem in a synchronous downstream dependency has immediate impact on the upstream callers. Retries from upstream callers can all-too easily fan-out and amplify problems. Photo by Clem Onojeghuo on Unsplash
  7. S U M M I T © 2019, Amazon Web

    Services, Inc. or its affiliates. All rights reserved.
  8. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Message exchange One-way Request-response Message channel Receiver No response expected Synchronous vs. fire-and-forget Response expected Return address Correlation ID Sender Message channel Responder Requester Message channel
  9. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Message channels Point-to-point (queue) Publish-subscribe (topic) Consumed by one receiver Easy to scale Flatten peak loads Consumed by all subscribers Durable subscriber Receivers Sender Queue Subscribers Publisher Topic
  10. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Message channels Point-to-point (queue) Publish-subscribe (topic) AWS service for queue functionality (serverless): Amazon Simple Queue Services (SQS) AWS service for topic functionality (serverless): Amazon Simple Notification Service (SNS) Receivers Sender Subscribers Publisher Amazon SQS Amazon SNS
  11. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Message channels Point-to-point (queue) Publish-subscribe (topic) AWS service for queue functionality (non-serverless): Amazon MQ (managed Apache Active MQ) AWS service for topic functionality (non-serverless): Amazon MQ (managed Apache Active MQ) Receivers Sender Subscribers Publisher Amazon MQ Amazon MQ
  12. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Message channels Topic-queue-chaining Allows fan-out and receiver scale-out at the same time Publisher Topic Queue Queue Receivers Application 1 Application 2
  13. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Message channels Dead letter queue (DLQ) Transient failure mitigation Poison-pill handling Sender Queue DLQ Receivers X
  14. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Message channels FIFO queue Message groups Guaranteed ordering Messages grouped by discriminator attribute Example: Amazon SQS with sender provided message group IDs – no further consumption as long as messages with particular message group ID are invisible Queue Receiver Sender Receivers Sender Queue Order!
  15. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Message channels Message delivery QoS At least once At most once Exactly once Queue Receiver Sender Exactly once? Well! Tunable / configurable messaging systems: Choose between at least once or at most once Deduplication capabilities to detect and eliminate messages which are sent more than once to or by the messaging system But how to deal with a situation where the message was consumed but never acknowledged? → Your systems still have to be able to handle duplicate messages → Messages should be processed in an idempotent manner
  16. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Message channels Visibility timeout, inflight messages Time visibility timeout receive message receive message receive message receive message Time receive message receive message delete / acknowledge message visibility timeout
  17. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Message routing Message filter Recipient list Receive only a relevant subset of messages Controlled by subscriber Publisher remains completely unaware Send only a relevant subset of messages to a subscriber Controlled by publisher or separate component Potentially adds coupling Subscribers Publisher Subscribers Publisher Topic color = blue color = red Recipient List
  18. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Message routing Scatter-gather Request sent out to interested entities who can submit their individual response Responses aggregated for processing Requester Topic Responders Queue Aggregator Processor
  19. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Message routing Pipes and filters Event triggers chain of processing steps (“filters”) Knowledge of destination for next step(s) is wired into each filter Similar patterns: chain of responsibility, processing pipeline, saga choreography Event source Pipe Filter Filter Pipe Pipe Result target … Filter Step 1 Step 2 Step n
  20. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Message routing Saga orchestration Event triggers orchestrated workflow Knowledge of workflow is externalized into orchestrator component, as well as for potential rollback Workflow participants remain as loosely coupled as possible Processor Processor Processor Processor Event source Orchestrator Result target … Step 1 Step 2 Step n-1 Step n
  21. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Message routing Saga orchestration AWS service for saga orchestration (serverless): AWS Step Functions Processor Processor Processor Processor Event source Orchestrator Result target … Step 1 Step 2 Step n-1 Step n
  22. S U M M I T © 2019, Amazon Web

    Services, Inc. or its affiliates. All rights reserved.
  23. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Context: Wild Rydes Inc.
  24. S U M M I T © 2019, Amazon Web

    Services, Inc. or its affiliates. All rights reserved.
  25. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 1: Submit a ride completion Unicorn Unicorn Management App
  26. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 1: Submit a ride completion Unicorn Unicorn Management App https://... submit-ride-completion { "from": "...", "to": "...", "duration": "...", "distance": "...", "customer": "...", "fare": "..." }
  27. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 1: Submit a ride completion Unicorn Unicorn Management App https://... submit-ride-completion AWS Cloud Unicorn Management Service { "from": "...", "to": "...", "duration": "...", "distance": "...", "customer": "...", "fare": "..." }
  28. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 1: Submit a ride completion Unicorn Unicorn Management App https://... submit-ride-completion AWS Cloud Unicorn Management Service Customer Notification Service Customer Accounting Service Customer Loyalty Service Datalake Ingestion Service Extraordinary Rides Service { "from": "...", "to": "...", "duration": "...", "distance": "...", "customer": "...", "fare": "..." }
  29. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 1: Submit a ride completion Unicorn Unicorn Management App https://... submit-ride-completion AWS Cloud Unicorn Management Service Customer Notification Service Customer Accounting Service Customer Loyalty Service Datalake Ingestion Service Extraordinary Rides Service { "from": "...", "to": "...", "duration": "...", "distance": "...", "customer": "...", "fare": "..." } Only interested in rides with: fare >= x distance >= y
  30. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 1: Submit a ride completion Unicorn Unicorn Management App https://... submit-ride-completion AWS Cloud Unicorn Management Service Customer Notification Service Customer Accounting Service Customer Loyalty Service Datalake Ingestion Service Extraordinary Rides Service { "from": "...", "to": "...", "duration": "...", "distance": "...", "customer": "...", "fare": "..." } Only interested in rides with: fare >= x distance >= y Integration via database?
  31. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 1: Submit a ride completion Unicorn Unicorn Management App https://... submit-ride-completion AWS Cloud Unicorn Management Service Customer Notification Service Customer Accounting Service Customer Loyalty Service Datalake Ingestion Service Extraordinary Rides Service { "from": "...", "to": "...", "duration": "...", "distance": "...", "customer": "...", "fare": "..." } Only interested in rides with: fare >= x distance >= y Integration via database? Oh my!
  32. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 1: Submit a ride completion Unicorn Unicorn Management App https://... submit-ride-completion AWS Cloud Unicorn Management Service Customer Notification Service Customer Accounting Service Customer Loyalty Service Datalake Ingestion Service Extraordinary Rides Service { "from": "...", "to": "...", "duration": "...", "distance": "...", "customer": "...", "fare": "..." } Only interested in rides with: fare >= x distance >= y Integration via REST APIs?
  33. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 1: Submit a ride completion Unicorn Unicorn Management App https://... submit-ride-completion AWS Cloud Unicorn Management Service Customer Notification Service Customer Accounting Service Customer Loyalty Service Datalake Ingestion Service Extraordinary Rides Service { "from": "...", "to": "...", "duration": "...", "distance": "...", "customer": "...", "fare": "..." } Only interested in rides with: fare >= x distance >= y Integration via REST APIs? Absolutely, but…
  34. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 1: Submit a ride completion Unicorn Unicorn Management App https://... submit-ride-completion AWS Cloud Unicorn Management Service Customer Notification Service Customer Accounting Service Customer Loyalty Service Datalake Ingestion Service Extraordinary Rides Service { "from": "...", "to": "...", "duration": "...", "distance": "...", "customer": "...", "fare": "..." } https://... https://... https://... https://... https://... Recipient list
  35. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 1: Submit a ride completion Unicorn Unicorn Management App https://... submit-ride-completion AWS Cloud Unicorn Management Service Customer Notification Service Customer Accounting Service Customer Loyalty Service Datalake Ingestion Service Extraordinary Rides Service { "from": "...", "to": "...", "duration": "...", "distance": "...", "customer": "...", "fare": "..." } Request Distribution Service https://... https://... https://... https://... https://... https://... Recipient list service
  36. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 1: Submit a ride completion Unicorn Unicorn Management App https://... submit-ride-completion AWS Cloud Unicorn Management Service Customer Notification Service Customer Accounting Service Customer Loyalty Service Datalake Ingestion Service Extraordinary Rides Service { "from": "...", "to": "...", "duration": "...", "distance": "...", "customer": "...", "fare": "..." } Request Distribution Service Only interested in rides with: fare >= x distance >= y https://... https://... https://... https://... https://... https://... Self-managed filtering
  37. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 1: Submit a ride completion Unicorn Unicorn Management App https://... submit-ride-completion AWS Cloud Unicorn Management Service Customer Notification Service Customer Accounting Service Customer Loyalty Service Datalake Ingestion Service Extraordinary Rides Service { "from": "...", "to": "...", "duration": "...", "distance": "...", "customer": "...", "fare": "..." } Request Distribution Service Only interested in rides with: fare >= x distance >= y https://... https://... https://... https://... https://... https://... Self-managed filtering Integration via messaging? Absolutely!
  38. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 1: Submit a ride completion Unicorn Unicorn Management App https://... submit-ride-completion AWS Cloud Unicorn Management Service Customer Notification Service Customer Accounting Service Customer Loyalty Service Datalake Ingestion Service Extraordinary Rides Service { "from": "...", "to": "...", "duration": "...", "distance": "...", "customer": "...", "fare": "..." } Ride Completion Topic Publish-subscribe (topic)
  39. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 1: Submit a ride completion Unicorn Unicorn Management App https://... submit-ride-completion AWS Cloud Unicorn Management Service Customer Notification Service Customer Accounting Service Customer Loyalty Service Datalake Ingestion Service Extraordinary Rides Service { "from": "...", "to": "...", "duration": "...", "distance": "...", "customer": "...", "fare": "..." } Ride Completion Topic Amazon SNS message filter: fare >= x distance >= y Message filter
  40. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 1: Submit a ride completion Unicorn Unicorn Management App https://... submit-ride-completion AWS Cloud Unicorn Management Service Customer Notification Service Customer Accounting Service Customer Loyalty Service Datalake Ingestion Service Extraordinary Rides Service Amazon SNS message filter: fare >= x distance >= y { "from": "...", "to": "...", "duration": "...", "distance": "...", "customer": "...", "fare": "..." } Ride Completion Topic Topic-queue-chaining
  41. S U M M I T © 2019, Amazon Web

    Services, Inc. or its affiliates. All rights reserved.
  42. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 2: Prebooking campaigns Wild Rydes Customer Wild Rydes Customer App https://... submit-ride-prebooking AWS Cloud Ride Booking Service / Prebooking Submission Resource Datalake Ingestion Service Ride Booking Service / Prebooking Processing Resource { "from": "...", "to": "...", "when": "...", "customer": "..." } Prebooking Notification Topic Further decoupling Prebooking Notification Buffer Queue Prebooking Processing Buffer Queue
  43. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 2: Prebooking campaigns Wild Rydes Customer Wild Rydes Customer App https://... submit-ride-prebooking AWS Cloud Ride Booking Service / Prebooking Submission Resource Datalake Ingestion Service Ride Booking Service / Prebooking Processing Resource { "from": "...", "to": "...", "when": "...", "customer": "..." } Prebooking Notification Topic Even further decoupling Prebooking Notification Buffer Queue Prebooking Processing Buffer Queue Prebooking Submission Buffer Queue
  44. S U M M I T © 2019, Amazon Web

    Services, Inc. or its affiliates. All rights reserved.
  45. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Unicorn Management Service Use case 3: Instant ride RFQ Wild Rydes Customer Wild Rydes Customer App https://... submit-instant-ride-rfq AWS Cloud Ride Booking Service Unicorn Management Resource Unicorn Management Resource Unicorn Management Resource { "from": "...", "to": "...", "customer": "..." } Request For Quotes Topic Scatter-gather { "from": "...", "to": "...", ”quotes": "..." } RFQ Response Queue …
  46. S U M M I T © 2019, Amazon Web

    Services, Inc. or its affiliates. All rights reserved.
  47. © 2019, Amazon Web Services, Inc. or its affiliates. All

    rights reserved. S U M M I T Use case 4: Fare collection Saga orchestration AWS Step Functions state machine orchestrates involved services State machine includes rollback scenarios for distributed transactions Customer accounting service Customer payment service Fare collection service …
  48. Thank you! S U M M I T © 2019,

    Amazon Web Services, Inc. or its affiliates. All rights reserved. Dirk Fröhner Solutions Architect Amazon Web Services [email protected] @dirk_f5r
  49. S U M M I T © 2019, Amazon Web

    Services, Inc. or its affiliates. All rights reserved.