Managing complex business transactions

Dariusz Pawlukiewicz

19.12.2018, bstoknet #88

in distributed world of micorservices...

Example CBT

CBT in monolith

The issue in DShop

...Mircorservices

  • domain is distributed into several services
  • async protocol for writes (queue). Possible LLT.
  • the whole app was pretty much done. Had to fit into Event-Driven Architecture.   

Why was it an issue?

  • ability to support distributed business transactions
  • ability to inform end-user about DT state

What we wanted to achieve?

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

DEMO

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

DEMO

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

API

Flights
service

(C) Book flight

Operations
service

(C) Book flight

SignalR service

(E) Operation updated

(E) Flight booked

(WS) Operation updated

How to determine operation status?

Saga pattern... wait what?

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

.NET Core Saga frameworks

  • Worfklow-core
  • NServiceBus Saga

Chronicle

Process manager/saga pattern framework for .NET Core

DEMO IN DSHOP

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

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

By goorion

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

  • 40