Example CBT

2PC - Two phase commit

2PC - Request Commit

Coordinator

Flights
service

Hotels
service

Cars
service

Request
& Lock

2PC - Verdict - NO

Coordinator

Flights
service

Hotels
service

Cars
service

NO

YES

UNLOCK

2PC - Verdict - YES

Coordinator

Flights
service

Hotels
service

Cars
service

YES

COMMIT & UNLOCK

2PC Summary

  • Easy to understand
  • Centralized distributed transaction management
  • "Immediate" result for end-user 
  • Requires extra code
  • Based on sync protocol (HTTP)
  • Slow - depends on nodes response time
  • Blocking resources

Event Choreography

Event choreography

API

Flights
service

Hotels
service

Cars
service

(C) Book flight

(E) Flight booked

(E) Hotel booked

(E) Car rental rejected

Event Choreogrpahy Summary

  • Easy to understand
  • Almost no extra code required
  • Fits into Event-driven architecture
  • Based on async protocol
  • No centralized distributed transaction management
  • May cause spaghetti dependecies -> hard to follow
  • Not so easy to test

"Saga" pattern

Process manager

Saga pattern

  • No state machine
  • No persisted data
  • Designed for failure compensating
  • State machine
  • Persisted data
  • Designed for managing processes

Saga pattern

API

Flights
service

Hotels
service

Cars
service

(C) Book flight

(E) Flight booked

(E) Hotel booked

(E) Car rental rejected

Saga

(C) Book hotel

(C) Rent car

Compensate

Chronicle

Process manager/saga pattern framework for .NET Core

Saga pattern (sort of) Summary

  • Easy to understand
  • Centralized distributed transaction management
  • Fits into Event-driven architecture
  • Based on async protocol
  • Required some extra work

Which approach is the best?

AVOIDING distributed transactions

BEST:

Event Choreography

SIMPLE TRACKING:

Process manager/Saga

IF NECESSARY:

Bunch of links

  • Demos - bit.ly/2ORQmhg
  • DShop - bit.ly/2Q3HLIg
  • Chronicle - bit.ly/2Qab387
  • NserviceBus Saga - bit.ly/1fZFQSk
  • Devmentors.io

Thanks!

@d_pawlukiewicz

foreverframe.net

Copy of O złożonych procesach biznesowych w rozproszonym świecie mikrousług

By goorion

Copy of O złożonych procesach biznesowych w rozproszonym świecie mikrousług

  • 44