Slide 1

Slide 1 text

Messaging: The fine line between awesome and awful LAILA BOUGRIA And how to stay on the right side of it…

Slide 2

Slide 2 text

No content

Slide 3

Slide 3 text

When I was young…

Slide 4

Slide 4 text

The monolith

Slide 5

Slide 5 text

Symptoms

Slide 6

Slide 6 text

Let’s use messaging!

Slide 7

Slide 7 text

Messaging benefits Easier decoupling Increased resilience Better performance Granular scalability

Slide 8

Slide 8 text

Challenges Out of order Hard to troubleshoot Duplicates System is slower UI is inconsistent

Slide 9

Slide 9 text

Distributed, big ball of mud

Slide 10

Slide 10 text

Laila Bougria @lailabougria @noctovis @lailabougria @[email protected]

Slide 11

Slide 11 text

System is slower

Slide 12

Slide 12 text

Request-response

Slide 13

Slide 13 text

Even slower… Producer Request queue Response queue Consumer Producer Consumer

Slide 14

Slide 14 text

Sync vs async request-response

Slide 15

Slide 15 text

One-way Request-response Messaging communication patterns Publish-subscribe

Slide 16

Slide 16 text

Decoupling

Slide 17

Slide 17 text

Place order process 1 Store order Charge credit card 2 Package order 3 Ship the order 4 Bill order 5 Adjust stock 6 Verify customer status 8 Order more stock? 7

Slide 18

Slide 18 text

Place order process Store order Charge credit card Package order Ship the order Bill order Adjust stock Verify customer status Order more stock?

Slide 19

Slide 19 text

Finding logical boundaries  Talk this through with the business  Event storming  Uncover false assumptions  By asking many, many questions!  Rinse and repeat to keep untangling things

Slide 20

Slide 20 text

We end up somewhere here… Customer places order Store order Charge order Package order Backorder order items Package order Ship order Bill order Order more stock? Verify customer status In stock? Stock arrived? Refund order Yes No No Yes Sales Payments Packaging Invoicing Shipping Stock Marketing

Slide 21

Slide 21 text

Communicate between boundaries  One way communication  Request-reply  Publish-Subscribe

Slide 22

Slide 22 text

The passive-aggressive publisher  Publish-subscribe is not a good fit when:  You expect something specific to be done  You need a response with data to continue  You need control over who receives the event

Slide 23

Slide 23 text

Recap  Decouple components by finding logical boundaries  Decouple data by understanding which data depends on each other and which data changes together  Choose the right communication pattern to communicate across components

Slide 24

Slide 24 text

UI is inconsistent

Slide 25

Slide 25 text

Glitches

Slide 26

Slide 26 text

Adjust the language

Slide 27

Slide 27 text

 Ensure message delivery  Show action details  Local storage  Used in several social media applications Illusion of progress

Slide 28

Slide 28 text

Defining SLAs

Slide 29

Slide 29 text

Future messages  Delayed delivery  Supported in Azure Service Bus, Rabbit MQ, Amazon SQS  Calculate the SLA expiration, use it as the delivery time  Verify whether the SLA was violated  Take appropriate action

Slide 30

Slide 30 text

Recap  Adjust language in the UI  Create the illusion of progress  Define Service Level Agreements  Enforce Service Level Agreements with delayed messages

Slide 31

Slide 31 text

Things occur out of order

Slide 32

Slide 32 text

Do we need ordering?

Slide 33

Slide 33 text

Order workflow Customer places order Store order Charge order Package order Backorder order items Package order Ship order Bill order Order more stock? Verify customer status In stock? Stock arrived? Refund order Yes No No Yes

Slide 34

Slide 34 text

Send out messages in the right order

Slide 35

Slide 35 text

Causes of ordering issues Latency Processing time Concurrency Load increase Retries Service availability

Slide 36

Slide 36 text

Let’s make it ordered Store order Charge credit card Package order Ship the order Bill order Adjust stock Verify customer status Order more stock? Sales Payments Shipments Invoices Stock Customer status

Slide 37

Slide 37 text

 Central component drives the business process  Knows and stores the state of the process  Decides which step is next and when  Recreates order Orchestration

Slide 38

Slide 38 text

Orchestration Order Orchestrator Message broker Sales Payments Shipping Invoicing Stock Customer status Packaging

Slide 39

Slide 39 text

Orchestration Order Orchestrator Message broker Sales Payments Shipping Invoicing Stock Customer status Packaging Stock Orchestrator

Slide 40

Slide 40 text

Orchestration pros & cons Order Orchestrator Message broker Sales Payments Shipping Invoicing Packaging

Slide 41

Slide 41 text

 Expect out-of-order messages  Test out-of-order cases  Use orchestration to model workflows  Guard the coupling within a single workflow  Choreography is an alternative for orchestration Recap

Slide 42

Slide 42 text

It’s impossible to troubleshoot failures

Slide 43

Slide 43 text

Message processing failed, but what’s the root cause?

Slide 44

Slide 44 text

We did not expect duplicates

Slide 45

Slide 45 text

And then there were more

Slide 46

Slide 46 text

Idempotency

Slide 47

Slide 47 text

Message deduplication  Detect whether a message was processed before  If so, discard the message  Deterministic Message ID  Deduplication windows

Slide 48

Slide 48 text

 No distributed transactions  Different types of infrastructure within a single system  Transactional guarantees are not cross-infrastructure  Outbox pattern: consistency across database and broker Atomicity problem

Slide 49

Slide 49 text

 Failure management pattern  Ensure data consistency, step-by-step  Sequence of local transactions  Roll back / compensate if one of the operations fail Saga distributed transactions pattern

Slide 50

Slide 50 text

Saga distributed transaction pattern Saga Service A Service B

Slide 51

Slide 51 text

 Make the change idempotent  Use the saga pattern for distributed transactions  Prefer communication over queues instead of REST APIs  Ensure REST APIs are idempotent  Investigate compensating requests Recap

Slide 52

Slide 52 text

 Messaging buys you options to solve scalability, reliability, coupling and performance problems  Commit to decoupling your logic and data  Think how out-of-order processing affects your workflows  Invest in observability  Make idempotency a key pattern in your design Conclusion

Slide 53

Slide 53 text

@lailabougria @noctovis @lailabougria @[email protected]