Saga transactions

Ondra Chaloupka /

wfly narayana

Saga (transactions)

wtf pleasant

An ACID transaction

  • One logical unit of work

    • everything or nothing happens

    • usually in regards of a data manipulation

  • Protecting shared resources from multiple users

  • ACID properties guaranteed

Distributed transaction: 2PC


ACID transactions: assuming

  • closely coupled environment

    • harder to scale

    • tight data coupling

  • short duration

    • locking reduces parallelism

Microservice architecture: expecting

  • loosely coupling

  • scaling

  • long duration for transaction


  • Relaxing ACID properties

  • Eventual consistency

  • Saga paper (H. Garcia-Molina, K. Salem; 1987)

Sagas (2)

saga confirm

  • consists of a sequence of autonomous operations, each immediatelly visible to outer world

  • responsibility of failures handling to developer (handlers)

  • transaction manager is responsible for calling handlers

Sagas (3)

saga compensate

  • compensation handler defined by developer, called by transaction manager

Narayana LRA

private AlohaService alohaService;

private LRAClientAPI lraClient;

@LRA(value = LRA.Type.REQUIRED)
public List<String> hello() {

public Response completeWork(@HeaderParam(LRAClient.LRA_HTTP_HEADER) String lraId) {
    String txId = LRAClient.getLRAId(lraId);
    System.out.printf("ActivityController completing %s%n", txId);
    return Response.ok().build();

public Response compensateWork(@HeaderParam(LRAClient.LRA_HTTP_HEADER) String lraId) {
    String txId = LRAClient.getLRAId(lraId);
    System.out.printf("ActivityController compensating %s%n", txId);
    return Response.ok().build();

Narayana LRA

msa calls

  • LRA: Long Running Actions

  • transaction context over REST