Welcome!

Microservices Expo Authors: Zakia Bouachraoui, Elizabeth White, Pat Romanski, Liz McMillan, Yeshim Deniz

Related Topics: Microservices Expo

Microservices Expo: Article

Introducing WS-Transaction Part 1

Introducing WS-Transaction Part 1

In July 2002, BEA, IBM, and Microsoft released a trio of specifications designed to support business transactions over Web services. These specifications, BPEL4WS, WS-Transaction, and WS-Coordination, together form the bedrock for reliably choreographing Web services-based applications, providing business process management, transactional integrity, and generic coordination facilities respectively.

In our previous article (WSJ, Volume 3, issue 5), we introduced WS-Coordination, a generic coordination framework for Web services, and showed how the WS-Coordination protocol can be augmented to support coordination in arbitrary application domains. This article introduces the first publicly available WS-Coordination-based protocol - Web Services Transaction - and shows how WS-Transaction provides atomic transactional coordination for Web services.

Transactions
Distributed systems pose reliability problems that are not frequently encountered in centralized systems. A distributed system consisting of a number of computers connected by a network can be subject to independent failure of any of its components, such as the computers themselves, network links, operating systems, or individual applications. Decentralization allows parts of the system to fail while other parts remain functioning, which leads to the possibility of abnormal behavior of executing applications.

Consider the case of a distributed system where the individual computers provide a selection of useful services that can be utilized by an application. It is natural that an application that uses a collection of these services requires that they behave consistently, even in the presence of failures. A very simple consistency requirement is that of failure atomicity: the application either terminates normally, producing the intended results, or is aborted, producing no results at all. This failure atomicity property is supported by atomic transactions, which have the following familiar ACID properties:

  • Atomicity: The transaction completes successfully (commits) or if it fails (aborts) all of its effects are undone (rolled back);
  • Consistency: Transactions produce consistent results and preserve application specific invariants;
  • Isolation: Intermediate states produced while a transaction is executing are not visible to other transactions. Furthermore, transactions appear to execute serially, even if they are actually executed concurrently. This is typically achieved by locking resources for the duration of the transaction so that they cannot be acquired in a conflicting manner by another transaction;
  • Durability: The effects of a committed transaction are never lost (except by a catastrophic failure).

    A transaction can be terminated in two ways: committed or aborted (rolled back). When a transaction is committed, all changes made within it are made durable (forced onto stable storage such as disk). When a transaction is aborted, all changes made during the lifetime of the transaction are undone. In addition, it is possible to nest atomic transactions, where the effects of a nested action are provisional upon the commit/abort of the outermost (top-level) atomic transaction.

    Why ACID Transactions May Be Too Strong
    Traditional transaction processing systems are sufficient to meet requirements if an application function can be represented as a single top-level transaction. However, this is frequently not the case. Top-level transactions are most suitably viewed as short-lived entities, performing stable state changes to the system; they are less well suited for structuring long-lived application functions that run for minutes, hours, days, or longer. Long-lived, top-level transactions may reduce the concurrency in the system to an unacceptable level by holding on to resources (usually by locking) for a long time. Furthermore, if such a transaction aborts, much valuable work already performed will be undone.

    Given that the industry is moving toward a loosely coupled, coarse-grained, B2B interaction model supported by Web services, it has become clear that the semantics of traditional ACID transactions are unsuitable for Web-scale deployment. Web services-based transactions differ from traditional transactions in that they execute over long periods, they require commitments to the transaction to be negotiated at runtime, and isolation levels have to be relaxed.

    WS-Transaction
    In the past, making traditional transaction systems talk to one another was a rarely achieved holy grail. With the advent of Web services, we have an opportunity to leverage an unparalleled interoperability technology to splice together existing transaction-processing systems that already form the backbone of enterprise-level applications.

    WS-Coordination Foundations
    An important aspect of WS-Transaction that differentiates it from traditional transaction protocols is that a synchronous request/response model is not assumed. This model derives from the fact that WS-Transaction (see Figure 1) is layered upon the WS-Coordination protocol whose own communication patterns are asynchronous by default.

     

    In our last article, we looked at how WS-Coordination provides a generic framework for specific coordination protocols, like WS-Transaction, to be plugged in. Remember that WS-Coordination provides only context management - it allows contexts to be created and activities to be registered with those contexts. WS-Transaction leverages the context management framework provided by WS-Coordination in two ways. First, it extends the WS-Coordination context to create a transaction context. Second, it augments the activation and registration services with a number of additional services (Completion, Completion WithAck, PhaseZero, 2PC, Outcome Notification, BusinessAgreement, and BusinessAgreementWithComplete) and two protocol message sets (one for each of the transaction models supported in WS-Transaction) to build a full-fledged transaction coordinator on top the WS-Coordination protocol infrastructure.

    WS-Transaction Architecture
    In common with other transaction protocols (like OTS and BTP), WS-Transaction supports the notion of the service and participant as distinct roles, making the distinction between a transaction-aware service and the participants that act on behalf of the service during a transaction: transactional services deal with business-level protocols, while the participants handle the underlying WS-Transaction protocols, as shown in Figure 2.

     

    A transaction-aware service encapsulates the business logic or work that is required to be conducted within the scope of a transaction. This work cannot be confirmed by the application unless the transaction also commits and so control is ultimately removed from the application and placed into the transaction's domain.

    The participant is the entity that, under the dictates of the transaction coordinator, controls the outcome of the work performed by the transaction-aware Web service. In Figure 2 each service is shown with one associated participant that manages the transaction protocol messages on behalf of its service, while in Figure 3, we see a close-up view of a single service, and a client application with their associated participants.

     

    The transaction-aware Web service and its participant both serve a shared transactional resource, and there is a control relationship between them through some API - which on the Java platform is JAXTX. In the example in Figure 3, we assume that the database is accessed through a transactional JDBC database driver, where SQL statements are sent to the database for processing via that driver, but where those statements will be tentative and only commit if the transaction does. In order to do this, the driver/database will associate a participant with the transaction which will inform the database of the transaction outcome. Since all transactional invocations on the Web service carry a transaction context, the participant working with the database is able to identify the work that the transactional service did within the scope of a specific transaction and either commit or roll back the work.

    At the client end, things are less complex. Through its API, the client application registers a participant with the transaction through which it controls transaction termination.

    WS-Transaction Models
    Given that we've already seen that traditional transaction models are not appropriate for Web services, we must pose the question, "What type of model or protocol is appropriate?" The answer to that question is that that no one specific protocol is likely to be sufficient, given the wide range of situations that Web service transactions are likely to be deployed within. Hence the WS-Transaction specification proposes two distinct models, each supporting the semantics of a particular kind of B2B interaction. In the following sections we'll discuss these two models, but for the sake of brevity we ignore possible failure cases.

    Note: as with WS-Coordination, the two WS-Transaction models are extensible, allowing implementations to tailor the protocols as they see fit (e.g., to suit their deployment environments). For clarity, we'll discuss only the "vanilla" protocols and leave proprietary extensions out of the picture.

    Atomic Transactions (AT)
    An atomic transaction, or AT, is similar to traditional ACID transactions and intended to support short-duration interactions where ACID semantics are appropriate.

    Within the scope of an AT, services typically enroll transaction-aware resources, such as databases and message queues, indirectly as participants under the control of the transaction. When the transaction terminates, the outcome decision of the AT is then propagated to each enlisted resource via the participant, and the appropriate commit or rollback actions are taken.

    This protocol is similar to those employed by traditional transaction systems that already form the backbone of an enterprise. It is assumed that all services (and associated participants) provide ACID semantics and that any use of atomic transactions occurs in environments and situations where this is appropriate: in a trusted domain, over short durations.

    To begin an atomic transaction, the client application first locates a WS-Coordination coordinator Web service that supports WS-Transaction. Once found, the client sends a WS-Coordination CreateCoordinationContext message to the activation service specifying http://schemas.xmlsoap.org/ws/2002/08/wstx as its coordination type and will get back an appropriate WS-Transaction context from the activation service. The response to the CreateCoordinationContext message, the transaction context, has its CoordinationType element set to the WS-Transaction at namespace, http://schemas.xmlsoap.org/ws/2002/08/wstx, and also contains a reference to the atomic transaction coordinator endpoint (the WS-Coordination registration service) where participants can be enlisted, as shown in Listing 1 (the code for this article can be found online at www.sys-con.com/webservices/sourcec.cfm.

    After obtaining a transaction context from the coordinator, the client application then proceeds to interact with Web services to accomplish its business-level work. With each invocation on a business Web service, the client inserts the transaction context into a SOAP header block, such that the each invocation is implicitly scoped by the transaction - the toolkits that support WS-Transaction-aware Web services provide facilities to correlate contexts found in SOAP header blocks with back-end operations.

    Once all the necessary application-level work has been completed, the client can terminate the transaction, with the intent of making any changes to the service state permanent. To do this, the client application first registers its own participant for the Completion or CompletionWithAck protocol. Once registered, the participant can instruct the coordinator either to try to commit or roll back the transaction. When the commit or rollback operation has completed, a status is returned to the participant to indicate the outcome of the transaction. The CompletionWithAck protocol goes one step further and insists that the coordinator must remember the outcome until it has received acknowledgment of the notification from the participant.

    While the completion protocols are straightforward, they hide the fact that in order to resolve to an outcome several other protocols need to be executed.

    The first of these protocols is the optional PhaseZero. The PhaseZero protocol is typically executed where a Web service needs to flush volatile (cached) state, which may be in use to improve performance of an application to a database prior to the transaction committing. Once flushed, the data will then be controlled by a two-phase aware participant.

    All PhaseZero participants are told that the transaction is about to complete (via the PhaseZero message) and they can respond with either the PhaseZeroCompleted or Error message; any failures at this stage will cause the transaction to roll back. The corresponding interfaces through which the participant and transaction coordinator exchange PhaseZero messages are shown in Listing 2.

    After PhaseZero, the next protocol to execute in WS-Transaction is 2PC. The 2PC (two-phase commit) protocol is at the heart of WS-Transaction atomic transactions and is used to bring about the consensus between participants in a transaction such that the transaction can be terminated safely.

    The 2PC protocol is used to ensure atomicity between participants, and is based on the classic two-phase commit with presumed abort technique. During the first phase, when the coordinator sends the prepare message, a participant must make durable any state changes that occurred during the scope of the transaction, such that these changes can either be rolled back or committed later. That is, any original state must not be lost at this point as the atomic transaction could still roll back. If the participant cannot prepare then it must inform the coordinator (via the aborted message) and the transaction will ultimately roll back. If the participant is responsible for a service that did not do any work during the course of the transaction, or at least did not do any work that modified any state, it can return the read-only message and it will be omitted from the second phase of the commit protocol. Otherwise, the prepared message is sent by the participant.

    Assuming no failures occurred during the first phase, in the second phase the coordinator sends the commit message to participants, who will make permanent the tentative work done by their associated services.

    If a transaction involves only a single participant, WS-Transaction supports a one-phase commit optimization. Since there is only one participant, its decisions implicitly reach consensus, and the coordinator need not drive the transaction through both phases. In the optimized case, the participant will simply be told to commit and the transaction coordinator need not record information about the decision since the outcome of the transaction is solely for that single participant.

    To place the 2PC protocol concepts into a Web services context, the interfaces of the transaction coordinator and corresponding 2PC participant are defined by the WSDL shown in Listing 3. The two WSDL portType declarations are complementary; for instance, where the 2PCParticipantPortType exposes the prepare operation to allow a coordinator to put it into the prepared state; the 2PCCoordinatorPortType has the prepared operation to allow participants to inform the coordinator that they have indeed moved to the prepared state. Figure 4 (redrawn from the WS-Transaction specification http://msdn.microsoft.com/library/ default.asp?url=/library/en-us/dnglobspec/ html/ws-transaction.asp) shows the state transitions of a WS-Transaction atomic transaction and the message exchanges between coordinator and participant; the coordinator generated messages are shown in the solid line, whereas the participant messages are shown by dashed lines.

     

    Once the 2PC protocol has finished, the Completion or CompletionWithAck protocol that originally began the termination of the transaction can complete, and inform the client application whether the transaction was committed or rolled back. In addition, some services may have registered an interest in the completion of a transaction, and they will be informed via the OutcomeNotificatonProtocol.

    Like the PhaseZero protocol, the OutcomeNotificatonProtocol is an optional protocol that some services will register for so that they can be informed when the transaction has completed, typically so that they can release resources (e.g., put a database connection back into the pool of connections).

    Any registered OutcomeNotification participants are invoked after the transaction has terminated and are told the state in which the transaction completed (the coordinator sends either the Committed or Aborted message). Since the transaction has terminated, any failures of participants at this stage are ignored - OutcomeNotification is essentially a courtesy and has no bearing on the outcome of the transaction.

    Finally, after having gone through each of the stages in an AT, we can now see the intricate interweaving of individual protocols that goes to make up the AT as a whole in Figure 5.

     

    Coordinating Atomic Transactions on the Web
    Transactions come to the fore when computational work with real-world financial implications must be executed. That being said, what better place to demonstrate the use of WS-Transaction than in online retail, where organizations live and die based on the quality of their customer service?

    Take the situation where a customer needs to purchase a new set of formalwear items, including a suit, tie, and shoes. Obviously it wouldn't be advisable for the customer to go into a formal situation without any of these, so the purchase of all three is a prerequisite for the completion of a business transaction.

    In the first instance, let's consider the situation where a single retailer can offer a choice of all three items (see Figure 6).

     

    In Figure 6 the retailer's Web service acts as a gateway to some back-end services that it also hosts. In this case, since the trust domain is entirely within one organization it's safe to use an Atomic Transaction to scope the purchases that the client application makes into a single logical unit of work.

    A typical use case for the architecture shown in Figure 6 is:
    1.   The client application begins its interaction with the online store, which creates an AT at the back end.
    2.   The client purchases items, which are then locked and other transactions cannot see them.
    3.   When the client application decides to buy the items, the AT is committed and its tentative work is made permanent, unless there are faults, in which case the work is rolled back.
    4.   The termination status of the transaction is reported back to the customer as a purchase successful/unsuccessful message.

    Aside from the fact that we are using Web services to host application logic, this is a textbook transactions example, which goes to strengthen the view that ATs are meant to be used within the kinds of close trust domains that traditional transaction processing infrastructure operates within. The Web services aspects of the protocol simply mean that proprietary transaction processing systems can interoperate, but this does not change their fundamental trust characteristics - which must be borne in mind by developers lest they expose lockable resources to the Web!

    Summary
    In this article we've seen how WS-Coordination has been used to provide the basis of the WS-Transaction protocol. We have also discussed the first transaction model that WS-Transaction supports: Atomic Transaction. This protocol is suitable for supporting short-lived transactions between trusted Web services where the possibility for malicious locking of resources is low.

    In our next article, we'll introduce the Business Activity protocol and show how it can provide the basis for higher-level business process management and workflow technology.

  • More Stories By Mark Little

    Mark Little was Chief Architect, Transactions for Arjuna Technologies Ltd, a UK-based company specialising in the development of reliable middleware that was recently acquired by JBoss, Inc. Before Arjuna, Mark was a Distinguished Engineer/Architect within HP Arjuna Labs in Newcastle upon Tyne, England, where he led the HP-TS and HP-WST teams, developing J2EE and Web services transactions products respectively. He is one of the primary authors of the OMG Activity Service specification and is on the expert group for the same work in J2EE (JSR 95). He is also the specification lead for JSR 156: Java API for XML Transactions. He's on the OTS Revision Task Force and the OASIS Business Transactions Protocol specification. Before joining HP he was for over 10 years a member of the Arjuna team within the University of Newcastle upon Tyne (where he continues to have a Visiting Fellowship). His research within the Arjuna team included replication and transactions support, which include the construction of an OTS/JTS compliant transaction processing system. Mark has published extensively in the Web Services Journal, Java Developer's Journal and other journals and magazines. He is also the co-author of several books including “Java and Transactions for Systems Professionals” and “The J2EE 1.4 Bible.”

    More Stories By Jim Webber

    Dr. Jim Webber is a senior researcher from the University of Newcastle
    upon Tyne, currently working in the convergence of Web Services and Grid
    technologies at the University of Sydney, Australia. Jim was previously
    Web Services architect with Arjuna Technologies where he worked on Web
    Services transactioning technology, including being one of the original
    authors of the WS-CAF specification. Prior to Arjuna, Jim was the lead
    developer with Hewlett-Packard on the industry's first Web Services
    Transaction solution. Co-author of "Developing Enterprise Web Services -
    An Architect's Guide," Jim is an active speaker and author in the Web
    Services space. Jim's home on the web is http://jim.webber.name

    Comments (1)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


    Microservices Articles
    When building large, cloud-based applications that operate at a high scale, it’s important to maintain a high availability and resilience to failures. In order to do that, you must be tolerant of failures, even in light of failures in other areas of your application. “Fly two mistakes high” is an old adage in the radio control airplane hobby. It means, fly high enough so that if you make a mistake, you can continue flying with room to still make mistakes. In his session at 18th Cloud Expo, Lee A...
    In his general session at 19th Cloud Expo, Manish Dixit, VP of Product and Engineering at Dice, discussed how Dice leverages data insights and tools to help both tech professionals and recruiters better understand how skills relate to each other and which skills are in high demand using interactive visualizations and salary indicator tools to maximize earning potential. Manish Dixit is VP of Product and Engineering at Dice. As the leader of the Product, Engineering and Data Sciences team at D...
    Lori MacVittie is a subject matter expert on emerging technology responsible for outbound evangelism across F5's entire product suite. MacVittie has extensive development and technical architecture experience in both high-tech and enterprise organizations, in addition to network and systems administration expertise. Prior to joining F5, MacVittie was an award-winning technology editor at Network Computing Magazine where she evaluated and tested application-focused technologies including app secu...
    Containers and Kubernetes allow for code portability across on-premise VMs, bare metal, or multiple cloud provider environments. Yet, despite this portability promise, developers may include configuration and application definitions that constrain or even eliminate application portability. In this session we'll describe best practices for "configuration as code" in a Kubernetes environment. We will demonstrate how a properly constructed containerized app can be deployed to both Amazon and Azure ...
    Modern software design has fundamentally changed how we manage applications, causing many to turn to containers as the new virtual machine for resource management. As container adoption grows beyond stateless applications to stateful workloads, the need for persistent storage is foundational - something customers routinely cite as a top pain point. In his session at @DevOpsSummit at 21st Cloud Expo, Bill Borsari, Head of Systems Engineering at Datera, explored how organizations can reap the bene...
    Using new techniques of information modeling, indexing, and processing, new cloud-based systems can support cloud-based workloads previously not possible for high-throughput insurance, banking, and case-based applications. In his session at 18th Cloud Expo, John Newton, CTO, Founder and Chairman of Alfresco, described how to scale cloud-based content management repositories to store, manage, and retrieve billions of documents and related information with fast and linear scalability. He addresse...
    The now mainstream platform changes stemming from the first Internet boom brought many changes but didn’t really change the basic relationship between servers and the applications running on them. In fact, that was sort of the point. In his session at 18th Cloud Expo, Gordon Haff, senior cloud strategy marketing and evangelism manager at Red Hat, will discuss how today’s workloads require a new model and a new platform for development and execution. The platform must handle a wide range of rec...
    SYS-CON Events announced today that DatacenterDynamics has been named “Media Sponsor” of SYS-CON's 18th International Cloud Expo, which will take place on June 7–9, 2016, at the Javits Center in New York City, NY. DatacenterDynamics is a brand of DCD Group, a global B2B media and publishing company that develops products to help senior professionals in the world's most ICT dependent organizations make risk-based infrastructure and capacity decisions.
    Discussions of cloud computing have evolved in recent years from a focus on specific types of cloud, to a world of hybrid cloud, and to a world dominated by the APIs that make today's multi-cloud environments and hybrid clouds possible. In this Power Panel at 17th Cloud Expo, moderated by Conference Chair Roger Strukhoff, panelists addressed the importance of customers being able to use the specific technologies they need, through environments and ecosystems that expose their APIs to make true ...
    In his keynote at 19th Cloud Expo, Sheng Liang, co-founder and CEO of Rancher Labs, discussed the technological advances and new business opportunities created by the rapid adoption of containers. With the success of Amazon Web Services (AWS) and various open source technologies used to build private clouds, cloud computing has become an essential component of IT strategy. However, users continue to face challenges in implementing clouds, as older technologies evolve and newer ones like Docker c...