Pattern: State Transition Operation

How can a client initiate a processing action that causes the provider-side application state to change? How can API clients and API providers share the responsibilities required to execute and control business processes and their activities?


The final version of this pattern is featured in our book Patterns for API Design: Simplifying Integration with Loosely Coupled Message Exchanges.

Pattern: State Transition Operation

a.k.a. Read-Write Operation, Data Change Operation, Business Activity Processor

Context

It has been decided to expose business functionality in an API. The functionality should be decomposed into multiple activities, whose execution state should be visible in the API so that clients can advance it. For example, functionality that is part of longer-running business processes might require data exchanges including incremental updates and coordinated application state management to move process instances from initiation to termination in a stepwise fashion.

The business process behavior and interaction dynamics might have been specified in a use case model and/or set of related user stories, or even an analysis-level business process model (using BPMN, UML activity diagrams or an equivalent notation).

Problem

How can a client initiate a processing action that causes the provider-side application state to change?

How can API clients and API providers share the responsibilities required to execute and control business processes and their activities? More specifically:

  • How can API clients ask an API provider to take over certain functions that represent business activities of varying granularities, from atomic activities to subprocesses to entire processes, but still own the process state (“Frontend BPM”)?
  • How can API clients initiate, control and follow the asynchronous execution of remote business processes (including subprocesses and activities) exposed and owned by an API provider (“Business Process Management (BPM) services”)?

A canonical example process from the insurance domain is claim processing, with activities such as initial validation of a received claim form, fraud check, additional customer correspondence, decision, payment/settlement, and archiving. Instances of this process can live for days to months or even years. Process instance state has to be managed; some parts of the processing can run in parallel whereas others have to be executed one by one sequentially. When dealing with such complex domain semantics, the control and data flow depends on a number of decisions. Multiple systems and services might be involved along the way, each exposing one or more APIs. Other services and application frontends act as API clients. The process instances and the state ownership can lie with the API client (Frontend BPM), with the API provider (BPM services), or be shared.

Forces

The following specific forces have to be resolved when representing business processes and their activities as API operations, or, more generally speaking, updating provider-side application state:

  • Service granularity
  • Consistency and auditability
  • Dependencies on state changes being made beforehand, which may collide with other state changes (e.g., transactions).
  • Workload management
  • Networking efficiency versus data parsimony (message sizes)

Time management and reliability also qualify as forces of this pattern; these design concerns are discussed in the pattern State Creation Operation.

Pattern forces are explained in depth in the book.

Solution

Introduce an operation in an API endpoint that combines client input and current state to trigger a provider-side state change sto: (in,S) -> (out,S'). Model the valid state transitions within the endpoint, which may be a Processing Resource or an Information Holder Resource, and check the validity of incoming change requests and business activity requests at runtime.

Pair a Command Message with a Document Message (two “Enterprise Integration Patterns” Hohpe and Woolf (2003)) to describe the input and the desired action and receive an acknowledgment or result.

Sketch

A solution sketch for this pattern from pre-book times is:

Figure 1: State Transition Operations are stateful, both reading and writing provider-side storage.

Example

The activity “proceed to checkout and pay” in an online shop illustrates the pattern in an order management process. “Add item to shopping basket” then is an activity in the “product catalog browsing” subprocess. These operations do change provider-side state, they do convey business semantics, and they do have nontrivial pre- and postconditions as well as invariants (for instance, “do not deliver the goods and invoice the customer before the customer has checked out and confirmed the order”).

The following example from the insurance domain illustrates the two extremes of the pattern; see Figure 4. Offers are created in a single-step operation; claims are managed step-by-step, causing incremental state transitions on the provider side. Some of the primitives from Figure 3 are assigned to State Transition Operations in the example.

Figure 4: Two examples of State Transition Operations: coarse-grained BPM service and fine-grained Frontend BPM process execution

Are you missing implementation hints? Our papers publications provide them (for selected patterns).

Consequences

The resolution of pattern forces and other consequences are discussed in our book.

Known Uses

The Application Layer of the Domain-Driven Design Sample Application implements (local) interfaces for two instances of this pattern: BookingService.java and CargoInspectionService.java.

PayPal has the notion of controller resources and M. Nygard also recommends this behavior- and reponsibility-oriented pattern when talking about activity sets and process services. Note that Nygard considers entity services an anti pattern in all cases, unlike other authors who argue that context matters.

Advocates of workflow engines recommend lightweight microservice compositions as well, for instance to decouple steps with an event command transformation.

A large body of State Transfer Operations can be found in enterprise settings (just to show how common the pattern is):

  • Most of the 1000+ services in the core banking SOA featured in Brandner et al. (2004) qualify as known uses of this pattern, for instance, money transfers.
  • The same holds for the business and application services in the telecommunications order management SOA presented in Zimmermann et al. (2005); for instance, the scheduling of a technician visit when customers relocate or upgrade their telephony services is part of a medium complex business process (or workflow).
  • The Swiss land register Terravis uses State Transition Operations in its backend infrastructure, e.g., for managing mortgages in a position keeping service (e.g., transfer mortgage from one depot to another) or for moving forward in a business process instance (e.g., submit digitally signed document) Lübke and Lessen (2016).

More Information

Related Patterns

The patterns differs from its siblings like this: A Computation Function does not touch the provider side application state (read or write) at all; a State Creation Operations only writes to it (in append mode). Instances of Retrieval Operation read, but do not write it; State Transition Operation instances both read and write the provider-side state. Computation Function and Retrieval Operation pull information from the provider; State Creation Operations (such as instances of its Event Notification Operation variant) push updates to the provider. State Transition Operations may push and/or pull. A State Transition Operation may refer to a provider-side state element in its request message (for instance, an order id or serial number of a staff member); State Creation Operations usually do not do this. A single API endpoint may, but not necessarily should apply more than one of these patterns; command-query separation is a principle from object-oriented programming also eligible on the architectural level.

State Transition Operations can be seen to trigger and/or realize the Business Transactions Fowler (2002). Instances of this pattern may participate in long running and therefore stateful conversations Hohpe (2007). They can use and go along with one or more of the RESTful conversation patterns from Pautasso, Ivanchikj, and Schreier (2016). For instance, one may want to consider factoring out the state management and the computation part of the pattern into separate services. Conversation patterns or choreographies and/or orchestrations may then define the valid combinations and execution sequences of these services.

State Transition Operations are often exposed in Community APIs; if this is done, they can be protected with an API Key and their usage can be governed with a Service Level Agreement.

In Domain-Driven Design (DDD) Evans (2003), the Aggregate and Entity patterns have related semantics (i.e., they represent groups of domain concepts that have an identify and a lifecyle). Hence, these patterns can help to identify State Transition Operation candidates during endpoint identification. It is important not to expose the entire domain as Published Language on the API level because this creates an undesired tight coupling between the API clients and the provider-side API implementation.

Other Sources

The is a large body of literature on BPM(N) and workflow management that introduces concepts and technologies to implement stateful service components in general and State Transition Operations in particular, for instance Leymann and Roller (2000), Leymann, Roller, and Schmidt (2002), Bellido, Alarcón, and Pautasso (2013), Gambi and Pautasso (2013).

In Responsibility-Driven Design (RDD), State Transition Operations correspond to coordinators and controllers that are encapsulated as service providers made accessible from remote with the help of an interfacer as described in Wirfs-Brock and McKean (2002).

The seven-step service design method in the Software/Service/API Design Practice Repository (DPR) suggests to call out endpoint roles and operation responsibilities such as State Transition Operation when preparing candidate endpoint lists and refining them.

References

Aalst, Wil M. P. van der. 2011. Process Mining: Discovery, Conformance and Enhancement of Business Processes. Springer.
Bellido, Jesus, Rosa Alarcón, and Cesare Pautasso. 2013. “Control-Flow Patterns for Decentralized RESTful Service Composition.” ACM Transactions on the Web (TWEB) 8 (1): 5:1–30. https://doi.org/10.1145/2535911.
Brandner, Michael, Michael Craes, Frank Oellermann, and Olaf Zimmermann. 2004. “Web Services-Oriented Architecture in Production in the Finance Industry.” Informatik-Spektrum 27 (2): 136–45. https://doi.org/10.1007/s00287-004-0380-2.
Evans, Eric. 2003. Domain-Driven Design: Tacking Complexity in the Heart of Software. Addison-Wesley.
Fehling, Christoph, Frank Leymann, Ralph Retter, Walter Schupeck, and Peter Arbitter. 2014. Cloud Computing Patterns: Fundamentals to Design, Build, and Manage Cloud Applications. Springer.
Fowler, Martin. 2002. Patterns of Enterprise Application Architecture. Addison-Wesley.
Gambi, Alessio, and Cesare Pautasso. 2013. “RESTful Business Process Management in the Cloud.” In Proc. 5th ICSE International Workshop on Principles of Engineering Service-Oriented Systems (PESOS), 1–10. https://doi.org/10.1109/PESOS.2013.6635971.
Gysel, Michael, Lukas Kölbener, Wolfgang Giersche, and Olaf Zimmermann. 2016. “Service Cutter: A Systematic Approach to Service Decomposition.” In Proc. European Conference on Service-Oriented and Cloud Computing (ESOCC), 185–200. Springer.
Hohpe, Gregor. 2007. Conversation Patterns: Interactions between Loosely Coupled Services.” In Proc. 12th European Conference on Pattern Languages of Programs (EuroPLoP), 1–45. Irsee, Germany.
Hohpe, Gregor, and Bobby Woolf. 2003. Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions. Addison-Wesley.
Leymann, Frank, and Dieter Roller. 2000. Production Workflow: Concepts and Techniques. Prentice Hall.
Leymann, Frank, Dieter Roller, and Marc-Thomas Schmidt. 2002. “Web Services and Business Process Management.” IBM System Journal 41 (2): 198–211. https://doi.org/10.1147/sj.412.0198.
Lübke, Daniel, and Tammo van Lessen. 2016. “Modeling Test Cases in BPMN for Behavior-Driven Development.” IEEE Software 33 (5): 15–21. https://doi.org/10.1109/MS.2016.117.
Pardon, Guy, and Cesare Pautasso. 2011. “Towards Distributed Atomic Transactions over RESTful Services.” In REST: From Research to Practice, 507–24. Springer. https://doi.org/10.1007/978-1-4419-8303-9_23.
Pautasso, Cesare, Ana Ivanchikj, and Silvia Schreier. 2016. “A Pattern Language for RESTful Conversations.” In Proceedings of the 21st European Conference on Pattern Languages of Programs (EuroPLoP). Irsee, Germany.
Wirfs-Brock, Rebecca, and Alan McKean. 2002. Object Design: Roles, Responsibilities, and Collaborations. Pearson Education.
Zimmermann, Olaf, Vadim Doubrovski, Jonas Grundler, and Kerard Hogg. 2005. “Service-Oriented Architecture and Business Process Choreography in an Order Management Scenario: Rationale, Concepts, Lessons Learned,” 301–12.
Zimmermann, Olaf, Jonas Grundler, Stefan Tai, and Frank Leymann. 2007. “Architectural Decisions and Patterns for Transactional Workflows in SOA.” In Proc. Fifth International Conference on Service-Oriented Computing (ICSOC), 81–93. Springer. https://doi.org/10.1007/978-3-540-74974-5_7.
Zimmermann, Olaf, Mirko Stocker, Daniel Lübke, and Uwe Zdun. 2017. “Interface Representation Patterns: Crafting and Consuming Message-Based Remote APIs.” In Proc. 22nd European Conference on Pattern Languages of Programs (EuroPLoP), 27:1–36. ACM. https://doi.org/10.1145/3147704.3147734.