Camunda Team Blog

Advanced Asynchronous Continuations in camunda BPM

Written by Daniel Meyer on , under Execution category.
Asynchronous continuations are a a very powerful process engine feature. Up until now you could use asynchronous continuations in two ways:
  1. Before an activity. 
  2. Asynchronous process instantiation using the async start event. (Added in 7.0).
With camunda BPM 7.2.0-alpha3, Asynchronous continuations become even more powerful:
  1. You can now place an asynchronous continuation AFTER an activity. (HOT!)
  2. Asynchronous continuations are now supported on more BPMN 2.0 constructs, such as the Parallel Gateway.

Why Asynchronous Continuations?

Asynchronous continuations are break-points in the process execution. They are used as transaction boundaries and allow another thread than the currently active thread to continue execution.

From a use case perspective
  • Async is used for placing a safe-point before an activity such that the execution state is committed. If the activity then fails to execute, the transaction is rolled back only up to the safe point.
  • Async also comes in handy if you have longer-running computations and do not want to block the calling thread (eg. HTTP Thread) but instead want to delegate the heavy lifting to a background thread.
  • Finally, due to the fact that asynchronous continuations are executed by the job executor, the retry mechanism can be used in order to retry a failed activity execution.

NEW: Asynchronous Continuations After an Activity

Asynchronous Continuations BEFORE and AFTER an activity. Details.

Asynchronous continuations after an activity come in handy when you want to place a safe point after an activity:

Asynchronous continuations after an activity are useful if you want to make sure that the state changes performed by the activity are saved before the process engine continues process execution.
  • Usually this is a lot more intuitive than placing the asynchronous continuation before the next activity.
  • An activity may have multiple outgoing sequence flows. Without the capability to place an asynchronous continuation after the activity, you would have to place it before all of the next activities.
  • Not every activity may have a "next activity". In BPMN 2.0 it is perfectly valid that an activity does not have any outgoing flows. Or, the activity may be a compensation handler which is not allowed to have an outgoing sequence flow.
  • If the activity is followed by a synchronizing construct (like a parallel gateway) it is useful to place a safe point after the activity in order to make sure a potential failure & retry caused by optimistic locking does not affect the activity. (You could also place an asynchronous continuation BEFORE the parallel gateway, of course).

I think that currently camunda BPM is the most advanced open source process engine in this area. If you know another open source process engine with has more flexible asynchronous continuation capabilities, let us know, I am always good for a challenge :)

As a side-note: the concept which makes asynchronous continuations possible is the "Atomic Operation". When the process engine executes a process, it will progress though the graph as a sequence of Atomic Operations. It then becomes possible to break execution between two atomic operations being executed. We are implementing CMMN (The new standard for adaptive case management, ACM) with the same programming model. As a result, it will also be possible to implement Async for CMMN as well :)