Service-Orientation with .NET : Service Composition and Orchestration Basics - Orchestration (part 2)
State Repository and Compensating Service Transaction
Whereas regular task services tend to encapsulate parent business process logic that can be executed within reasonable timeframes as part of single, runtime service activities, orchestrations offer the ability to create and manage long-running service activities.
The execution time of a given orchestration can span from a few seconds to hours or even days, especially if it involves human interaction. This is why orchestration platforms naturally provide a central state database and an alternative transaction mechanism that does not allow for the rollback of changes. These two characteristics correspond to the State Repository and Compensating Service Transaction patterns respectively.
State Repository with .NET
During times of inactivity, long-running processes can be stored in a central state database through a technique called dehydration. When processing needs to resume, the process logic is rehydrated and loaded back into memory. This is the primary reason State Repository is applied within orchestration platforms.
Managing this type of state previously with traditional .NET component technologies, such as .NET Enterprise Services or COM+, was often challenging. .NET orchestration tools, on the other hand, are built specifically to accommodate the state management requirements of long-running processes. For example, if you think of a process as an object of type orchestration, then capturing the state of a running process instance is equivalent to taking a snapshot of all the properties of that object and saving it to persistent storage. Rehydration is then just a matter of deserializing the data from the persistent storage to recreate the orchestration object graph.
Figure 5 shows how only active process instances reside in the orchestration engine. Idle process instances, such as those waiting to receive messages, are dehydrated and stored in persistent storage (usually SQL Server).
Figure 5. The orchestration engine dehydrates idle process instances to a database to conserve server resources.
Compensating Service Transaction
The parent business process logic encapsulated by an orchestrated task service can be extended with routines designed to respond to various exceptions that may occur at runtime in relation to an overarching transaction. These routines are commonly employed as an alternative to ACID-style transactions when it makes sense not to preserve the state of the process prior to the transaction. As a result, a rollback of all changes that occurred prior to the exception is not required. The Compensating Service Transaction pattern allows for a failed transaction to be handled via this pre-defined exception logic, referred to as compensation logic (as shown in Figure 6).
Figure 6. Compensation logic is pre-defined as part of the overall business process logic encapsulated by the orchestrated task service controlling a transaction as part of a service composition.
Both WF and BizTalk Server provide different features for defining compensations. Because compensation logic is part of the overall workflow or process definition, the same tools are generally used.
Other Patterns
The extended patterns hierarchy for the Orchestration compound pattern includes the additional Atomic Service Transaction , Data Model Transformation, and Rules Centralization patterns (Figure 7). When applied in conjunction with the core patterns, these optional patterns provide further features and capabilities that can enhance and extend orchestration platforms. Both WF and BizTalk Server provide support for these patterns (as shown in the upcoming Table 1).
Figure 7. The extended patterns hierarchy for the Orchestration compound pattern.
| Orchestration Patterns | WF | BizTalk Server |
|---|---|---|
| Process Abstraction | 2 | 1 |
| Process Centralization (tools) | 2 | 1 |
| State Repository | 2 | 1 |
| Compensating Service Transaction | 2 | 1 |
| Rules Centralization | 2 | 1 |
| Atomic Service Transaction | 2 | 1 |
| Data Model Transformation | 2 | 1 |
Microsoft Orchestration Platforms: WF and BizTalk Server
Table 1 highlights the differences in the respective platforms in how they provide support for the attainment of the feature-sets associated with the patterns.
Each platform has distinct strengths and weaknesses with regard to feature-set, flexibility, cost, and the effort necessary to build, run, and maintain orchestrated solutions. Table 2 provides further insight into some key areas of comparison.
| Characteristic | WF | BizTalk Server |
|---|---|---|
| APIs | .NET, WF object model | XML, .NET orchestration library, BizTalk object model |
| architecture foundation | .NET | XML and .NET |
| autonomy | orchestrations are autonomous or embedded in other applications | orchestrations are fully autonomous |
| composability | composition of Web services and custom WF activities, and orchestrations are composable as services or directly | composition of Web services and legacy applications, and orchestrations are composable as services or directly |
| cost | free of charge as part of the .NET framework | licensed by processor |
| discovery | services are discoverable via published WSDL definitions or inside the developer tool | services are discoverable via published WSDL definitions |
| extensibility | high extensibility for customized execution, state persistence and support for other protocols and transports via custom activities | extensibility to support additional transports, protocols, and message processing |
| formal contracts | light support for service contracts in the form of .NET interfaces | strong support for XML Schema and WSDL-based contracts |
| industry standards | support for SOAP, WSDL. WS-* | strong support for XML, SOAP, WSDL, and WS-* with WCF integration and limited support for WS-BPEL |
| messaging | general support for asynchronous messaging, resource management, and XML-based message exchanges | |
| reusability | reusable via Web services and directly inside the orchestration engine (other forms of reuse possible with custom development) | reusable via Web services, queue endpoints, file drop, and directly inside the orchestration engine |
| rules engine | rules based on facts in .NET objects | complex rules based on facts in XML documents, .NET objects, and database records |
| scalability | medium scalability through custom extensions for persistence and activity scheduling | high scalability through clustering and distributable functionality |
| state management | process state is stored in memory, SQL Server, or custom data store | process state is stored in SQL Server |
| tools | re-hostable orchestration design, Web service publishing | orchestration design, data mapping, Web service publishing, runtime monitoring and deployment |