Download as pdf or txt
Download as pdf or txt
You are on page 1of 17

CTO Tuesdays #47

Compensation
“Undoing work when things go wrong”

Dr. Michael Rowley, Chief Technology Officer

Clive Bearman, Director of Product Marketing

1
Some GoToWebinar Tips

„ Click the maximize button for the best resolution


– The panel will minimize itself after a few seconds
– Click the arrows to make it reappear

„ You can enter your Q&A in the questions area….


– We will answer questions at the end of the talk
– Attendee audio is muted

2
Welcome to CTO Tuesdays

„ What is CTO Tuesdays?


– A weekly series hosted by Active Endpoints’ CTO Dr. Michael Rowley
– Tuesdays at 12pm ET, 9am PT 17:00 UTC

„ Who is CTO Tuesdays for?


– Enterprise and application architects
– Project managers
– Developers
– Evaluators of BPM technologies

„ CTO Tuesday Webinars


– Register for upcoming webinars: http://www.activevos.com/ctot
– Replays and feed: http://www.ctotuesdays.com

„ Agenda
– Presentation of the topic
– Panel Q&A

3
Today’s Topic

Compensation
Dr. Michael Rowley, CTO, Active Endpoints

4
Long-running Transactions

„ A transaction is a set of activities that should either:


– All execute successfully
– Not be executed at all if any one of them can’t complete

„ Transactions are critical to the business


– Business logic requires that consistency constraints be maintained
z Constraints may include data from separate systems
– Transactions move the system from one valid global state to another
valid global state
z If a transaction is only partially complete, the system will violate the constraints

„ Partial work must be undone using compensation


– Each activity in the flow has a corresponding activity that says how to
undo its effects
– ACID transaction managers aren’t appropriate

5
ACID Transactions

„ ACID stands for:


– Atomicity – All or none updates
– Consistency – Consistency constraints are maintained
– Isolation – Preventing visibility of incomplete updates
– Durability – Data change survival after system failure

„ Transaction managers
– Uses locks to provide the desired level of isolation
– Uses 2-phase commit to achieve atomicity, consistency and durability
z Phase 1: provisionally store the change for each resource
z Phase 2: officially accept the change for each resource

„ But ACID Transactions DON’T work for business processes

6
ACID Transactions and Business Processes

„ Business transactions
– Last too long to use locks and so
transaction managers don’t help
– Don’t require isolation
z Allow
temporary visibility for incomplete
updates
– Constraints must only be met when
the transaction completes

7
Compensation in Business Processes

„ Business transactions in processes are divided into separate scopes

„ Each activity or sub-process (sub-scope) in the business transaction


defines compensation handlers

„ Compensation handlers specify the activities needed to undo the


work of their activity
– With BPMN the best way to define
compensation for an activity is to use
compensation boundary events.

„ When a fault occurs in a business transaction, all completed


activities and sub-scopes are compensated

8
BPEL Scopes

„ Encapsulate a recoverable, unit of work


– Well suited to business transactions

„ Provides processing context for


– Organization and documentation Process
– Variables Scope A
– Fault handlers Scope B
– Compensation handlers
– Event handlers Scope C

9
Faults Overview

„ A fault is an event that disrupts the normal flow of a business process


– Business-centric faults
z Invoking Web services may result in a WSDL fault
z BPEL process may explicitly throw a fault
– System-centric faults
z Faults may be raised automatically via internal or external error conditions
z Includes the built-in standard BPEL faults

„ When a fault occurs, normal processing halts


– Control is transferred to the appropriate fault handler

10
Compensation using Boundary Events

11
Compensation in Event Subprocesses

12
Compensation Handling

Process 4. Compensate
previous work
Scope
5. Propagate Compensation Fault
compensation Handler Handler

3. Fault triggers
process-level
Compensation Compensation
6. Undo work fault handler
Handler Handler
(in reverse order)

1. Do some work (successfully invoke two services) 2. Invoke another service (throws fault)

13
Default Compensation Handling Scenario

No matching fault handler found,


invoke enclosing scopes Scope A
compensation handlers

Scope B

No matching compensation Scope C


handler found, invoke enclosing
scopes compensation handlers

Compensation
Compensation handler found, Handler
perform compensation

14
Data Seen During Compensation

„ Current data in incomplete enclosing scopes

„ Final data from the scope the handler is defined on


– Includes final data from any enclosing scope that completed
– Called a scope snapshot
– The handler is optional continuation of the scope

„ Snapshots are created for every loop iteration

„ Compensation handlers
– Use data from the snapshot to invoke external services that will undo the
work
– Update data from parent scopes that are still running

15
Transaction Best Practices

„ Create scopes whenever a set of changes should be atomic

„ Create compensation handlers for each activity other than the last
activity in the scope

„ Use locally scoped variables if the scope may be repeated

„ Use data from the locally scoped variables to construct service calls
that will undo the work for that iteration

16
More Information and Contact Details

„ Register for upcoming webinars


– http://www.activevos.com/ctot

„ Download replays and slides


– Blog: http://www.ctotuesdays.com
– RSS feed: http://www.ctotuesdays.com/feed

„ Apply what you learned today


– Download and try ActiveVOS for free
– http://www.activevos.com

„ Contact us with comments or feedback


– Clive Bearman: clive.bearman@activevos.com
– Michael Rowley: michael.rowley@activevos.com
– General: ctot@activevos.com

17

You might also like