Welcome!

Microservices Expo Authors: Liz McMillan, Todd Matters, Pat Romanski, Elizabeth White, Stefana Muller

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) View Comments

    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.


    Most Recent Comments
    mukhias 09/01/08 09:03:30 AM EDT

    i am sorry.. i can't see the source code for the aritcle..

    @MicroservicesExpo Stories
    New competitors, disruptive technologies, and growing expectations are pushing every business to both adopt and deliver new digital services. This ‘Digital Transformation’ demands rapid delivery and continuous iteration of new competitive services via multiple channels, which in turn demands new service delivery techniques – including DevOps. In this power panel at @DevOpsSummit 20th Cloud Expo, moderated by DevOps Conference Co-Chair Andi Mann, panelists examined how DevOps helps to meet the de...
    For most organizations, the move to hybrid cloud is now a question of when, not if. Fully 82% of enterprises plan to have a hybrid cloud strategy this year, according to Infoholic Research. The worldwide hybrid cloud computing market is expected to grow about 34% annually over the next five years, reaching $241.13 billion by 2022. Companies are embracing hybrid cloud because of the many advantages it offers compared to relying on a single provider for all of their cloud needs. Hybrid offers bala...
    "When we talk about cloud without compromise what we're talking about is that when people think about 'I need the flexibility of the cloud' - it's the ability to create applications and run them in a cloud environment that's far more flexible,” explained Matthew Finnie, CTO of Interoute, in this SYS-CON.tv interview at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
    @DevOpsSummit at Cloud Expo taking place Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center, Santa Clara, CA, is co-located with the 21st International Cloud Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is ...
    What's the role of an IT self-service portal when you get to continuous delivery and Infrastructure as Code? This general session showed how to create the continuous delivery culture and eight accelerators for leading the change. Don Demcsak is a DevOps and Cloud Native Modernization Principal for Dell EMC based out of New Jersey. He is a former, long time, Microsoft Most Valuable Professional, specializing in building and architecting Application Delivery Pipelines for hybrid legacy, and cloud ...
    Containers, microservices and DevOps are all the rage lately. You can read about how great they are and how they’ll change your life and the industry everywhere. So naturally when we started a new company and were deciding how to architect our app, we went with microservices, containers and DevOps. About now you’re expecting a story of how everything went so smoothly, we’re now pushing out code ten times a day, but the reality is quite different.
    There's a lot to gain from cloud computing, but success requires a thoughtful and enterprise focused approach. Cloud computing decouples data and information from the infrastructure on which it lies. A process that is a LOT more involved than dragging some folders from your desktop to a shared drive. Cloud computing as a mission transformation activity, not a technological one. As an organization moves from local information hosting to the cloud, one of the most important challenges is addressi...
    For organizations that have amassed large sums of software complexity, taking a microservices approach is the first step toward DevOps and continuous improvement / development. Integrating system-level analysis with microservices makes it easier to change and add functionality to applications at any time without the increase of risk. Before you start big transformation projects or a cloud migration, make sure these changes won’t take down your entire organization.
    21st International Cloud Expo, taking place October 31 - November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA, will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud strategy. Me...
    "We are a monitoring company. We work with Salesforce, BBC, and quite a few other big logos. We basically provide monitoring for them, structure for their cloud services and we fit into the DevOps world" explained David Gildeh, Co-founder and CEO of Outlyer, in this SYS-CON.tv interview at DevOps Summit at 20th Cloud Expo, held June 6-8, 2017, at the Javits Center in New York City, NY.
    Microservices are increasingly used in the development world as developers work to create larger, more complex applications that are better developed and managed as a combination of smaller services that work cohesively together for larger, application-wide functionality. Tools such as Service Fabric are rising to meet the need to think about and build apps using a piece-by-piece methodology that is, frankly, less mind-boggling than considering the whole of the application at once. Today, we'll ...
    Cloud Expo, Inc. has announced today that Andi Mann and Aruna Ravichandran have been named Co-Chairs of @DevOpsSummit at Cloud Expo Silicon Valley which will take place Oct. 31-Nov. 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. "DevOps is at the intersection of technology and business-optimizing tools, organizations and processes to bring measurable improvements in productivity and profitability," said Aruna Ravichandran, vice president, DevOps product and solutions marketing...
    In his session at Cloud Expo, Alan Winters, an entertainment executive/TV producer turned serial entrepreneur, presented a success story of an entrepreneur who has both suffered through and benefited from offshore development across multiple businesses: The smart choice, or how to select the right offshore development partner Warning signs, or how to minimize chances of making the wrong choice Collaboration, or how to establish the most effective work processes Budget control, or how to ma...
    SYS-CON Events announced today that CA Technologies has been named "Platinum Sponsor" of SYS-CON's 21st International Cloud Expo®, which will take place October 31-November 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. CA Technologies helps customers succeed in a future where every business - from apparel to energy - is being rewritten by software. From planning to development to management to security, CA creates software that fuels transformation for companies in the applic...
    In the decade following his article, cloud computing further cemented Carr’s perspective. Compute, storage, and network resources have become simple utilities, available at the proverbial turn of the faucet. The value they provide is immense, but the cloud playing field is amazingly level. Carr’s quote above presaged the cloud to a T. Today, however, we’re in the digital era. Mark Andreesen’s ‘software is eating the world’ prognostication is coming to pass, as enterprises realize they must be...
    A common misconception about the cloud is that one size fits all. Companies expecting to run all of their operations using one cloud solution or service must realize that doing so is akin to forcing the totality of their business functionality into a straightjacket. Unlocking the full potential of the cloud means embracing the multi-cloud future where businesses use their own cloud, and/or clouds from different vendors, to support separate functions or product groups. There is no single cloud so...
    Both SaaS vendors and SaaS buyers are going “all-in” to hyperscale IaaS platforms such as AWS, which is disrupting the SaaS value proposition. Why should the enterprise SaaS consumer pay for the SaaS service if their data is resident in adjacent AWS S3 buckets? If both SaaS sellers and buyers are using the same cloud tools, automation and pay-per-transaction model offered by IaaS platforms, then why not host the “shrink-wrapped” software in the customers’ cloud? Further, serverless computing, cl...
    Hybrid IT is today’s reality, and while its implementation may seem daunting at times, more and more organizations are migrating to the cloud. In fact, according to SolarWinds 2017 IT Trends Index: Portrait of a Hybrid IT Organization 95 percent of organizations have migrated crucial applications to the cloud in the past year. As such, it’s in every IT professional’s best interest to know what to expect.
    The taxi industry never saw Uber coming. Startups are a threat to incumbents like never before, and a major enabler for startups is that they are instantly “cloud ready.” If innovation moves at the pace of IT, then your company is in trouble. Why? Because your data center will not keep up with frenetic pace AWS, Microsoft and Google are rolling out new capabilities. In his session at 20th Cloud Expo, Don Browning, VP of Cloud Architecture at Turner, posited that disruption is inevitable for comp...
    Companies have always been concerned that traditional enterprise software is slow and complex to install, often disrupting critical and time-sensitive operations during roll-out. With the growing need to integrate new digital technologies into the enterprise to transform business processes, this concern has become even more pressing. A 2016 Panorama Consulting Solutions study revealed that enterprise resource planning (ERP) projects took an average of 21 months to install, with 57 percent of th...