v0.11.2

Introduction

Workflow Examples

We will give here some examples of workflows to illustrate how powerful Infinitic is.

Bookings and Saga

We implement a booking process combining a car rental, a flight, and a hotel reservation. We require that all three bookings have to be successful together: if any of them fails, we should cancel the other successful bookings.

Bookings and Saga

This is HotelBookingService's signature (CarRentalService and FlightBookingService's signatures are similar):

The orchestration of a complete booking will be done through the book method of BookingWorkflow:

This is really all we need to implement this workflow.

Inside a workflow, using the dispatch function triggers the execution of a task without blocking the flow of the workflow. Multiple uses of this function will trigger parallel executions of multiple tasks. The dispatch function returns a Deferred object, which is a reference to the dispatched task. By applying the await() method to it, we tell the workflow to wait for the task completion and to return its result.

Monthly invoicing

Let's consider now a workflow where, every month, we will:

  • use a Consumption service to get some metrics from a user
  • use a payment service to charge the user payment card
  • generate an invoice
  • send the invoice to the user

Monthly invoicing

With Infinitic, we do not need any cron, writing such workflow is as simple as:

Inside a workflow, awaiting a timer blocks the flow of the workflow up to the desired Instant or Duration (no resources are used during this waiting time).

Inside a workflow, all instructions must be deterministic - that's why the instruction LocalDate.now() must be in a task. Here, the inline function creates a pseudo-task inlined in the workflow.

A workflow must not contain a very high number of tasks, that's why loops should be avoided. Here, we have a limited number of possible iterations (running for 10 years will generate only 120 iterations) and 7 tasks per iteration. So we are fine in this case.

Loyalty program

Let's consider now a point-based loyalty program where:

  • users receive 10 points every week
  • users receive 100 points every time they complete a form
  • users receive 100 points every time they complete an order
  • users can burn points

Loyalty program

With Infinitic, we can implement such a loyalty program like this:

An Infinitic client (or another workflow) can call methods of a running workflow. Multiple methods of the same workflow instance can run in parallel (but only one is running at a given time - one way to think of it is as an asynchronous but single-threaded execution)

Properties in workflows can be used to store information mutable from multiple methods.

A workflow must not contain a very high number of tasks, that's why loops should be avoided. Here we have a limited number of possible iterations (running for 10 years will generate 560 iterations only) and 2 tasks per iteration. So we are fine in this case.

Location Booking

Let's consider now an Airbnb-like service, where a traveler does a request to a host. The host will be notified of the request at most 3 times. If the response is positive, the traveler should pay a deposit, then both are notified.

Location Booking

This workflow could be implemented as such:

We can send external signals to a workflow to notify it that something happened. A signal is a serializable object. To receive a signal, a workflow must have a channel.

As illustrated here with the PaymentWorkflow, a workflow can dispatch (synchronously or asynchronously) another sub-workflow. It opens unlimited possibilities.

Projects examples

  • "Hello World": simple workflow with 2 sequential tasks (java, kotlin)
  • "Booking Workflow": saga pattern implementation with 3 tasks (java, kotlin)
  • "Loyalty Workflow": loyalty points are maintained as workflow properties and updated through a method (java, kotlin)
  • "Sync Workflow": the workflow continuoulsy receives events. Each event triggers 3 sequential tasks that must be processed before processing the next event (java)
Previous
Event-Driven

New version 0.11.2!