Pattern: Processing Resource

How can an API provider allow its clients to trigger an action in it?


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

Pattern: Processing Resource

a.k.a. Command Service, Controller Resource, Executor, Processing Endpoint

Context

The functional requirements for an application have been specified, e.g., in the form of agile user stories and/or analysis-level business process models. An analysis of the functional requirements suggests that one or more remote capabilities should be invoked; Frontend Integration and/or Backend Integration are required and application domain-driven APIs and their clients have to be designed. A (micro-)services architecture and integration infrastructure have been defined initially.

Problem

How can an API provider allow its clients to trigger an action in it?

Such actions may be standalone commands (application domain-specific ones or technical utilities) or activities in a business process; they may or may not read and write provider-side application state. A suitable level of abstraction is desired that only exposes the action and hides data as much as possible.

Forces

When invoking provider-side processing upon request from remote clients, general design concerns are:

  • Contract expressiveness and service granularity (and their impact on coupling)
  • Learnability and manageability
  • Semantic interoperability
  • Response time
  • Security and privacy
  • Compatibility and evolvability

These forces conflict with each other partially. For instance, the more expressive a contract is, the more has to be learned, managed, and tested (w.r.t. interoperability). Finer-grained services might be easier to protect and evolve, but there will be many of them, which have to be integrated Neri et al. (2020).

A key decision is whether the endpoint should have activity- or data-oriented semantics. This pattern explains how to emphasize activity; its Information Holder Resource sibling focuses on data orientation.

Pattern forces are explained in depth in the book.

Solution

Add a Processing Resource endpoint to the API exposing operations that bundle and wrap application-level activities or commands.

Sketch

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

Figure 1: Processing Resources represent activity-oriented API designs. Some operations in the endpoint access and change application state, others do not. Data is only exposed in request and response messages.

Example

The Policy Management Backend of the Lakeside Mutual microservices sample contains a stateful Processing Resource InsuranceQuoteRequestProcessingResource that offers State Transition Operations which move an insurance quotation request through various stages. The resource is implemented as an HTTP resource API in Java and Spring Boot. It also contains RiskComputationService, a stateless Processing Resource that implements a single Computation Function called computeRiskFactor:

@RestController
@RequestMapping("/riskfactor")
public class RiskComputationService {
    @ApiOperation(
        value = "Computes the risk factor of a customer.")
    @PostMapping(
        value = "/compute")
    public ResponseEntity<RiskFactorResponseDto> 
        computeRiskFactor(
            @ApiParam(
                value = "the request containing relevant
                    customer attributes (e.g., birthday)", 
                required = true)
            @Valid @RequestBody
            RiskFactorRequestDto riskFactorRequest) {
        int age =
            getAge(riskFactorRequest.getBirthday());
        String postalCode =
            riskFactorRequest.getPostalCode();
        int riskFactor = 
            computeRiskFactor(age, postalCode);
        return ResponseEntity.ok(
            new RiskFactorResponseDto(riskFactor));
    }

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 Slack Web API is processing-oriented with its https://slack.com/api/METHOD_FAMILY.method syntax. It has the notion of “HTTP RPC methods” and even puts a command name in the resource URIs (which is considered a REST anti pattern by some authors in the Web API design community).

The layers of the Domain-Driven Design Sample Application, characterized here, implement (local) interfaces for Processing Resources, BookingService.java and CargoInspectionService.java.

You can find instances of Processing Resources in most integration architectures. Service-Oriented Architectures (SOAs) in enterprises often feature services exposing business capabilities rather than data abstractions in their interfaces; each of these services is a Processing Resource. An early example that went into production in early 2003 is the Dynamic Interface of a core banking backend described in an OOPSLA 2004 experience report and in Brandner et al. (2004).

Terravis provides a process hub for enabling fully digitalized mortgage processes between Swiss land registries, banks, notaries and other parti. It uses a variety of Command Services (e.g., Contract Signing) to trigger actions in partners when coordinating inter-organizational business processes Lübke and Lessen (2016).

More examples for usage of the pattern in a business information system (a.k.a. enterprise application) context can be found in the telecommunications order management SOA described in Zimmermann et al. (2005). This SOA introduces the notion of business services and application services.

More Information

Related Patterns

Processing Resources may contain operations hat differ in the way they deal with provider-side state (stateless services vs. stateful processors): State Transition Operation, State Creation Operation, Computation Function, and Retrieval Operation (some of which in turn have variants). These specializations also differ w.r.t. client commitment and expectations as expressed in pre- and postconditions and request and response message signatures in the API contract. The Information Holder Resource pattern represents opposite semantics and is an alternative to this pattern.

Processing Resources are commonly exposed in Community APIs and Public APIs; if this is done, they can be protected with an API Key and Rate Limits. Their usage is often governed by a Service Level Agreement that accompanies the technical API Contract. To avoid that technical parameters creep into the payload in request and response messages, such parameters can be isolated in a Context Representation.

The three patterns Command Message, Document Message and Request-Reply Hohpe and Woolf (2003) are used in combination when realizing this pattern. The Command pattern in Gamma et al. (1995) codifies a processing request and its invocation data as an object and as a message, respectively.1

This pattern and its operation-level companions (see above) can be seen as the remote API variant of the general Command pattern in Gamma et al. (1995) and Application Service in Alur, Malks, and Crupi (2013). Its provider-side implementations often use a Service Activator Hohpe and Woolf (2003).

Other Sources

Processing Resources correspond to interfacers that provide and protect access to service providers in Responsibility-Driven Design (RDD) Wirfs-Brock and McKean (2002). Domain-Driven Design (DDD) Evans (2003) and this pattern are also related in several ways:

  • DDD Services are good candidates for remote interface exposure.
  • A DDD Bounded Context can map and correspond to an API (with several endpoints).
  • A DDD Aggregate can also map and correspond to an API (with several endpoints, starting with the root entity).
  • DDD Factories and Repositories deal with entity lifecycle management, which involves read and write access to API provider-side application state.
  • DDD Value Objects can be exposed as Data Transfer Representations (DTRs) in the Published Language established by the data part of the API Description (a.k.a. service contract).

Chapter 6 in “SOA in Practice” Josuttis (2007) is on service classification; it compares several taxonomies including the one from “Enterprise SOA” Krafzig, Banke, and Slama (2004). Some of the examples in the process services type/category in these SOA books qualify as known uses (these books also include project examples/case studies from domains such as banking and telecommunications).

The online article “Understanding RPC Vs REST For HTTP APIs” talks about RPC vs. REST, but taking a closer look it actually (also) is about deciding between Processing Resource and Information Holder Resource.

The action resource topic area/category in the API Stylebook provides a (meta) known use for this pattern. Its undo topic is also related.

References

Allamaraju, Subbu. 2010. RESTful Web Services Cookbook. O’Reilly.
Alur, Deepak, Dan Malks, and John Crupi. 2013. Core J2ee Patterns: Best Practices and Design Strategies. 2nd ed. Prentice Hall.
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.
Buschmann, Frank, Kevlin Henney, and Douglas Schmidt. 2007. Pattern-Oriented Software Architecture: A Pattern Language for Distributed Computing. Wiley.
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.
Gamma, Erich, Richard Helm, Ralph Johnson, and John Vlissides. 1995. Design Patterns: Elements of Reusable Object-Oriented Software. Addison-Wesley.
Hohpe, Gregor, and Bobby Woolf. 2003. Enterprise Integration Patterns: Designing, Building, and Deploying Messaging Solutions. Addison-Wesley.
Josuttis, Nicolai. 2007. SOA in Practice: The Art of Distributed System Design. O’Reilly.
Julisch, Klaus, Christophe Suter, Thomas Woitalla, and Olaf Zimmermann. 2011. “Compliance by Design–Bridging the Chasm Between Auditors and IT Architects.” Computers & Security 30 (6): 410–26.
Krafzig, Dirk, Karl Banke, and Dirk Slama. 2004. Enterprise SOA: Service-Oriented Architecture Best Practices (the Coad Series). Prentice Hall.
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.
Lübke, Daniel, Olaf Zimmermann, Mirko Stocker, Cesare Pautasso, and Uwe Zdun. 2019. “Interface Evolution Patterns - Balancing Compatibility and Extensibility Across Service Life Cycles.” In Proc. 24th European Conference on Pattern Languages of Programs (EuroPLoP), 15:1–24. https://doi.org/10.1145/3361149.3361164.
Neri, Davide, Jacopo Soldani, Olaf Zimmermann, and Antonio Brogi. 2020. “Design Principles, Architectural Smells and Refactorings for Microservices: A Multivocal Review.” SICS Software-Intensive Cyber Physical Systems 35 (1): 3–15. https://doi.org/10.1007/s00450-019-00407-8.
Pautasso, Cesare, and Olaf Zimmermann. 2018. “The Web as a Software Connector: Integration Resting on Linked Resources.” IEEE Software 35: 93–98. https://doi.org/10.1109/MS.2017.4541049.
Pautasso, Cesare, Olaf Zimmermann, Mike Amundsen, James Lewis, and Nicolai M. Josuttis. 2017. “Microservices in Practice, Part 1: Reality Check and Service Design.” IEEE Software 34 (1): 91–98. https://doi.org/10.1109/MS.2017.24.
Richardson, Chris. 2018. Microservices Patterns. Manning.
Voelter, Markus, Michael Kircher, and Uwe Zdun. 2004. Remoting Patterns - Foundations of Enterprise, Internet, and Realtime Distributed Object Middleware. Wiley.
Wirfs-Brock, Rebecca, and Alan McKean. 2002. Object Design: Roles, Responsibilities, and Collaborations. Pearson Education.
Zimmermann, Olaf. 2015. “Architectural Refactoring: A Task-Centric View on Software Evolution.” IEEE Software 32 (2): 26–29. https://doi.org/10.1109/MS.2015.37.
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.


  1. A pattern language for distributed systems design that pulls patterns from other books can be found in Buschmann, Henney, and Schmidt (2007).↩︎