Communicate Between Processes Using Correlation

Correlations enable business processes to communicate with each other based on the state of an instance.

When you define a correlation for a business process, you can identify an instance in another process based on the instance state and then send a message to that specific instance.

For example, you can use correlations to communicate between a sales process with the corresponding shipping and mailing processes. When the customer confirms an order, the sales process sends a message to the shipping and mailing processes using a correlation that defines that it uses the order ID to locate the instances in both processes.

How does correlation work?

Let's explore how correlation works with a simple use case.

Suppose we have a main process (Order) for ordering items. This process calls another process (Vendor) to check and confirm if the items requested in the order are available. Both these processes run asynchronously. While the Vendor process runs and checks for the availability of the item requested, the Order process continues to progress to next activities in the process flow – for example, it moves to an activity to get first level approval from the manager, then it moves to the next activity to get approval from finance. The Order process will continue to run until it reaches the activity in which it has to wait for the response message from the Vendor process. Once the response message is received from the Vendor process, the Order process continues to the subsequent activities and completes.

However, in real life scenario many orders may get initiated simultaneously and wait for response from the vendor for the availability of particular items. So there may be a lot of instances of the Order and Vendor processes running simultaneously. How does the engine determine and correctly match the response of a Vendor process instance to the corresponding request of the main Order process instance? For example: 50 instances of the Order and Vendor processes may have been started simultaneously. How does the engine match the response of the Vendor process instance 25 with the request of the Order process instance 25? This is done by using correlation. Using correlation we can match the incoming response message with the appropriate instance. The main component of correlation is the correlation key.

What are correlation keys?

Correlation keys are set of correlation properties used to associate an incoming message to a particular instance of a process. For example, in the use case of the Order and Vendor processes, the correlation key property may be the Order Id. When you define a correlation key, you provide a unique name to the key so as to identify the properties used in the correlation. The scope of the correlation key is the process, which means that after you define a correlation key you can use it for the correlation definition of an activity in that process.

Where do I define correlation keys?

You can define correlation keys either in the activity level (Receive activity) or process level.
  • Define and create correlation key from the properties pane of a receive activity.
  • Define and create correlation key in the process level by clicking the Correlation keys Correlation key icon from the sidebar menu of the process editor. The Correlation keys pane opens where you can define correlation keys for your process. Once defined you can use it in a receive activity in that process.

What are the main steps of implementing correlation?

  1. Define: Define a correlation key to use. When you define a correlation key you provide a name to identify it. You create the key with one or more properties. For example, order id + item number. Properties are abstractions for representative attributes in the process, like the order ID, the customer name, or the social security number.
  2. Initialize: Assign a value to the correlation key using literal values or expressions and initialize it from an activity. You can use the arguments and predefined variables of the activity. After you initialize a correlation, you can’t change its value because the service engine uses this value to locate the instance.
  3. Correlate: Specify the input arguments that should match the correlation key. The input arguments are those that you receive in the response message sent by the called process