API Pattern of the Week: State Transition Operation
API Design Pattern of the Week 8: State Transition Operation, taken from "Patterns for API Design" (Addison Wesley 2022)

API Pattern of the Week: State Transition Operation

Thank you, Olaf Zimmermann, for passing the API Pattern of the Week series baton (see and follow the hashtag #apidpotw for the previous articles). In the previous issue, Olaf looked at how two or more communication participants can exchange data without knowing each other using a Data Transfer Resource; this time, we'll zoom into the State Transition Operation pattern, so let's start with some context information:

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 clients can advance it. For example, functionality in longer-running business processes might require data exchanges, including incremental updates and coordinated application state management to move process instances from initiation to termination stepwise.

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?

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

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.

Figure 1 sketches this solution (PlantUML, from pre-book times):

No alt text provided for this image
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 change provider-side state, convey business semantics, and have nontrivial pre- and postconditions and invariants (for instance, "do not deliver the goods and invoice the customer before the customer has checked out and confirmed the order").

Discussion

The resolution of the pattern forces is discussed in the book.

More Information

There 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 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 calling out endpoint roles and operation responsibilities, such as State Transition Operations when preparing and refining candidate endpoint lists.

References

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.

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.

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.

Wirfs-Brock, Rebecca, and Alan McKean. 2002. Object Design: Roles, Responsibilities, and Collaborations. Pearson Education.




The "API Pattern of the Week" series here on LinkedIn featured the following patterns: Wish List, Pagination, Error Report, API Key, Processing Resource, Information Holder Resource, and Data Transfer Resource.

Find the complete pattern description in Chapter 5 of "Patterns for API Design," for instance, at InformIT. There is a 35% discount on the book with code API-PATTERNS.

要查看或添加评论,请登录

Mirko Stocker的更多文章

  • API Pattern of the Week: API Description

    API Pattern of the Week: API Description

    In the previous thirteen issues, we covered many patterns applicable during different steps in the design of an API…

    6 条评论
  • API Pattern of the Week: Conditional Request

    API Pattern of the Week: Conditional Request

    After the last issues discussion of Embedded Entity and Linked Information Holder, we will visit a further Quality…

  • API Pattern of the Week: Linked Information Holder

    API Pattern of the Week: Linked Information Holder

    After last week's Embedded Entity, we will now look at its sibling pattern: Linked Information Holder. Context An API…

  • API Pattern of the Week: Embedded Entity

    API Pattern of the Week: Embedded Entity

    The next two patterns we will discuss in this series are for reference management: Embedded Entity and Linked…

    2 条评论
  • API Pattern of the Week: Id Element

    API Pattern of the Week: Id Element

    Last week, we looked at the first Element Stereotype pattern: Metadata Element. Element stereotypes give meaning to the…

    1 条评论
  • API Pattern of the Week: Metadata Element

    API Pattern of the Week: Metadata Element

    Our API pattern language is divided into several categories. This week, we'll revisit the Structure category, from…

    1 条评论
  • LegalFly – Die Schweizer Spezialisten

    LegalFly – Die Schweizer Spezialisten

    Bald beginnt der Sommer und mit ihm die Hauptsaison der Reisenation Schweiz. Sei es ein Familienurlaub in Mallorca oder…

    1 条评论

社区洞察

其他会员也浏览了