Photo from Unsplash

MicroProfile Long Running Actions (LRA) is a long-awaited specification that provides a lock-free, and consequently loosely-coupled, approach to achieve consistency in a microservice environment.

LRA follows the SAGA pattern, where asynchronous compensations are used to maintain eventual data integrity without staging expensive isolation. This method removes the additional burden of monitoring your data integrity and provides greater scalability - features that are highly valued in the world of microservices.

LRA Transaction

Every LRA transaction can be joined by multiple participants. Participants are JAX-RS resources with methods annotated with LRA-specific annotations.
These annotations are used to join @LRA and others so they can be called together when compensating @Compensate or completing @Complete the transaction.

public class LRAExampleResource {

    @LRA(value = LRA.Type.REQUIRES_NEW, timeLimit = 500, timeUnit = ChronoUnit.MILLIS)
    public Response startExample(@HeaderParam(LRA_HTTP_CONTEXT_HEADER) URI lraId, String data) {
        // Executed in the scope of new LRA transaction
        return Response.ok().build();

    public Response completeExample(@HeaderParam(LRA_HTTP_CONTEXT_HEADER) URI lraId) {
        // Called by LRA coordinator when startExample method sucessfully finishes
        return LRAResponse.completed();

    public Response compensateExample(@HeaderParam(LRA_HTTP_CONTEXT_HEADER) URI lraId) {
        // Called by LRA coordinator when startExample method throws exception or don't finish before time limit
        return LRAResponse.compensated();

Every participant joining the LRA transaction needs to provide its compensation links, those URLs leading to resources annotated with @Compensate, @Complete, @AfterLRA etc. The LRA coordinator keeps track of which resources to call when the LRA transaction state changes. When the JAX-RS resource method is annotated with @LRA(REQUIRES_NEW), every intercepted call starts a new LRA transaction within the coordinator and joins it as new participant before the resource method is invoked. The id of the created LRA transaction is accessible in the resource method through the Long-Running-Action header. When the resource method invocation successfully finishes, the LRA transaction is reported to the coordinator as closed. If a participant has the @Complete method, then it is eventually invoked again by the coordinator with the appropriate LRA id header and the @Complete method of all of the other participants joined within the LRA transaction.


When a resource method finishes exceptionally, LRA is reported to the coordinator as cancelled and the coordinator calls the @Compensate method on all of the participants registered under that transaction.

Participant cancel

When a transaction isn’t closed before it’s timeout is reached, the coordinator cancels the transaction and calls the compensate endpoints for all participants of the timed-out transaction.

Participant timeout

LRA Coordinator

The Long Running Actions implementation in Helidon requires the LRA coordinator to orchestrate LRA across the cluster. This is an extra service so you will need to enable the LRA functionality in your cluster. The LRA coordinator keeps track of which participant joined which LRA transaction and calls the participant’s LRA compensation resources when LRA transaction completes or is cancelled.

Helidon supports:

  • Narayana LRA Coordinator
  • Experimental Helidon LRA Coordinator

Narayana LRA Coordinator

Narayana is a well-known transaction manager with a long history of reliability in the field of distributed transactions built around the Arjuna core. The Narayana LRA coordinator brings support for Long Running Actions and is the first LRA coordinator on the market.

wget \
-O narayana-coordinator.jar \
&& java -Dquarkus.http.port=8070 -jar narayana-coordinator.jar

Experimental Helidon LRA Coordinator

Helidon now has its own experimental coordinator that is easy to set up for development and testing purposes. While it is not recommended for use in production enviornments, it is a great lightweight solution for testing your LRA resources.

docker build -t helidon/lra-coordinator
docker run -dp 8070:8070 --name lra-coordinator --network="host" helidon/lra-coordinator

Let’s take a look at a specific use case.

Photo by Kilyan Sockalingum on Unsplash

Online Cinema Booking System

Our hypothetical cinema needs an online reservation system. We will split it into two scalable services: one for booking the seat and another for making the payment. Our services will be completely separated, integrated only through the REST API calls.

Our booking service is going to reserve the seat first. The reservation service will start a new LRA transaction and join it as a first transaction participant. All communication with the LRA coordinator is done behind the scenes and can be accessed through the LRA id assigned to the new transaction in our JAX-RS method as a request header Long-Running-Action. Note that LRA stays active after JAX-RS method finishes because Lra#end is set to false.

    // Create new LRA transaction which won't end after this JAX-RS method end
    // Time limit for new LRA is 30 sec
    @LRA(value = LRA.Type.REQUIRES_NEW, end = false, timeLimit = 30)
    public Response createBooking(@HeaderParam(LRA.LRA_HTTP_CONTEXT_HEADER) URI lraId,
                                  @PathParam("id") long id,
                                  Booking booking) {

        // LRA ID assigned by coordinator is provided as artificial request header

        if (repository.createBooking(booking, id)) {
  "Creating booking for " + id);
            return Response.ok().build();
        } else {
  "Seat " + id + " already booked!");
            return Response
                            .add("error", "Seat " + id + " is already reserved!")
                            .add("seat", id)

Create new seat booking

Once a seat is successfully reserved, payment service is going to be called under the same LRA transaction. An artificial header Long-Running-Action is present in the response so that it can be accessed on the client. () {
            .then(res => {
                if (res.ok) {
                    // Notice how we can access LRA ID even on the client side
                    let lraId = res.headers.get("Long-Running-Action");
                    paymentView.attr("data-lraId", lraId);
                } else {
                    res.json().then(json => {

We can call other backend resources with the same LRA transaction just by setting Long-Running-Action again.

    function makePayment(cardNumber, amount, lraId) {
        return fetch('/booking/payment', {
            method: 'PUT',
            headers: {
                'Content-Type': 'application/json',
                'Long-Running-Action': lraId
            body: JSON.stringify({"cardNumber": cardNumber, "amount": amount})

Payment form

The backend calls different service over the JAX-RS client, we don’t need to set the Long-Running-Action header to propagate the LRA transaction. As with all JAX-RS clients, LRA implementation will do that for us automatically.

    // Needs to be called within LRA transaction context
    // Doesn't end LRA transaction
    @LRA(value = LRA.Type.MANDATORY, end = false)
    public Response makePayment(@HeaderParam(LRA.LRA_HTTP_CONTEXT_HEADER) URI lraId,
                                JsonObject jsonObject) {"Payment " + jsonObject.toString());
        // Notice that we don't need to propagate LRA header
        // When using JAX-RS client, LRA header is propagated automatically
                .put(Entity.entity(jsonObject, MediaType.APPLICATION_JSON))
                .whenComplete((res, t) -> {
                    if (res != null) {
               + " " + res.getStatusInfo().getReasonPhrase());
        return Response.accepted().build();

The payment service will join this transaction as another participant. Any card number other than 0000-0000-0000 will cancel the LRA transaction. Finishing the resource method is going to complete the LRA transaction because Lra#end is set to true.

    // This resource method ends/commits LRA transaction as successfully completed
    @LRA(value = LRA.Type.MANDATORY, end = true)
    public Response makePayment(@HeaderParam(LRA.LRA_HTTP_CONTEXT_HEADER) URI lraId,
                                Payment payment) {
        if (!payment.cardNumber.equals("0000-0000-0000")) {
            LOG.warning("Payment " + payment.cardNumber);
            throw new IllegalStateException("Card " + payment.cardNumber + " is not valid! "+lraId);
        }"Payment " + payment.cardNumber+ " " +lraId);
        return Response.ok(JSON.createObjectBuilder().add("result", "success").build()).build();

If the payment operation fails or times out, the LRA transaction is going to be cancelled and all participants are going to be notified through the compensation links provided when they joined. The LRA coordinator is going to call the method annotated with @Compensate with the LRA id as a parameter. That is all we need in our booking service to clear the seat reservation and make it available for another customer.

    public Response paymentFailed(URI lraId) {"Payment failed! " + lraId);
                .ifPresent(booking -> {
          "Booking for seat " + booking.getSeat().getId() + "cleared!");
                            .ifPresent(b -> b.broadcast(new OutboundEvent.Builder()
        return Response.ok(;

Payment form

A sample Cinema Booking project leveraging LRA is available on GitHub:


This sample project provides a set simple Kubernetes (K8s) services prepared for deployment to Oracle Kubernetes Engine or locally to Minikube.

Deploy to minikube


Build images

As we work directly with minikube docker daemon all we need to do is build the docker images.


Note that the first build can take few minutes for all of the artifacts to download. Subsequent builds are going to be much faster as the layer with dependencies is cached.

Deploy to minikube


This script recreates the whole namespace, any previous state of the cinema-reservation is obliterated. Deployment is exposed via the NodePort and the URL with port is printed at the end of the output:

namespace "cinema-reservation" deleted
namespace/cinema-reservation created
Context "minikube" modified.
service/booking-db created
service/lra-coordinator created
service/payment-service created
service/seat-booking-service created
deployment.apps/booking-db created
deployment.apps/lra-coordinator created
deployment.apps/payment-service created
deployment.apps/seat-booking-service created
service/cinema-reservation exposed
Application cinema-reservation will be available at

Deploy to OCI OKE cluster


  • OKE K8s cluster
  • OCI Cloud Shell with git, docker and kubectl configured to access the Oracle Container Engine for Kubernetes (OKE) cluster

Pushing images to your OCI Container registry

The first thing you will need is a place to push your docker images to so that OKE K8s have a location to pull from. Container registry is part of your OCI tenancy, so to be able to push to it you need to log in: docker login <REGION_KEY> Username of the registry is <TENANCY_NAMESPACE>/ where is your OCI user. Password will be auth token of your To get your region key and tenancy namespace, execute the following command in your OCI Cloud Shell:

# Get tenancy namespace and container registry
echo "" && \
echo "Container registry: ${OCI_CONFIG_PROFILE}" && \
echo "Tenancy namespace: $(oci os ns get --query "data" --raw-output)" && \
echo "" && \
echo "docker login ${OCI_CONFIG_PROFILE}" && \
echo "Username: $(oci os ns get --query "data" --raw-output)/" && \
echo "Password: --- Auth token for user" && \
echo ""

Example output:

Container registry:
Tenancy namespace: fr8yxyel2vcv

docker login
Username: fr8yxyel2vcv/
Password: --- Auth token for user

Save your container registry, tenancy namespace, and auth token for later.

When your local docker is logged in to OCI Container Registry, you can execute with the container registry and tenancy namespace as the parameters.


bash fr8yxyel2vcv

Example output:

docker build -t .
docker push
docker build -t .
docker push

The script will print out docker build commands before executing them. Note that the first build can take few minutes for all the artifacts to download. Subsequent builds are going to be much faster as the layer with dependencies is cached.

To make your pushed images publicly available, open your OCI console and set both repositories to Public:

Developer Tools>Containers & Artifacts> Container Registry

Deploy to OKE

You can use the cloned helidon-lra-example repository in the OCI Cloud shell with your K8s descriptors. Your changes are built to the images you pushed in the previous step.

In the OCI Cloud shell:

git clone
cd helidon-lra-example

kubectl get services

Example output:

NAME                         TYPE           CLUSTER-IP      EXTERNAL-IP   PORT(S)          AGE
booking-db                   ClusterIP    <none>        3306/TCP         34s
lra-coordinator              NodePort    <none>        8070:32434/TCP   33s
oci-load-balancing-service   LoadBalancer    <pending>     80:31192/TCP     33s
payment-service              NodePort    <none>        8080:30842/TCP   32s
seat-booking-service         NodePort    <none>        8080:32327/TCP   32s

You can see that right after the deployment, the EXTERNAL-IP of the external LoadBalancer reads as <pending> because OCI is provisioning it for you. You can invoke kubectl get services a little later and see that it now gives you an external IP address with Helidon Cinema example exposed on port 80.


Maintaining integrity in distributed systems with compensation logic isn’t a new idea, but it can be quite complicated to achieve without special tooling. MicroProfile Long Running Actions is exactly that, tooling that hides the complexities so you can focus on business logic.

We are already working on additional exciting features, like compatibility with other LRA coordinators or support of LRA context in messaging.

So stay tuned and happy coding!