The Key to Mixing Services with Web API Workflow
The four elements of a robust loosely-coupled workflow system.
Below is an excerpt from my book "RESTful Web API Patterns and Practices Cookbook" from O'Reilly Media
For many, the ultimate goal of creating service interface APIs is to foster flexible and robust workflow solutions that mix existing services in unique ways to solve new problems. In fact, this goal is embodied in the keystone principle discussed in “Shared Principles for Scalable Services on the Web”.
The process of linking services together is not a great challenge when these services were designed from the start to work in concert. However, enlisting services that were not built as a group, know nothing of each other, and are oblivious to the solution being created is a much bigger challenge.
This second approach (enlisting unrelated services) depends on important implementation details that make a number of activities possible, such as sharing solution state, progressing through multiple steps to accomplish a goal, and tracking/displaying that progress. Anytime you mix service interfaces together, there is a chance of execution errors that might require rerunning some steps, undoing others, and knowing when this is needed.
“These four elements (patterns, generalized flow, optimization, and management) make up a healthy hypermedia workflow system.”
Often, we build our own services as a related collection. In fact, if the same team is building more than one service, those services are bound to have hidden dependencies that are difficult to untangle. Keeping this tangle at bay takes discipline, design, and determination.
The bad news is that designing and supporting successful workflow on the web requires additional effort. The good news is that, as long as you implement each individual service with a simple API and establish a general processing and tracking model that all services support, you can create a resilient, flexible, and evolvable workflow environment that clients can safely use to solve new and interesting problems.
Supporting a hypermedia workflow means focusing on common patterns like page navigation, works in progress, most recently used, etc. It also means supporting a generalized hypermedia-driven workflow via jobs and tasks, along with some optimization techniques to keep things flowing. Finally, there is a second-level set of activities centered around managing the workflow process itself.
These four elements (patterns, generalized flow, optimization, and management) make up a healthy hypermedia workflow system.