Saga transactions

Ondra Chaloupka / ochaloup@redhat.com

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

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

Sagas

  • 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

@Inject
private AlohaService alohaService;

@Inject
private LRAClientAPI lraClient;

@GET
@Path("/hello")
@LRA(value = LRA.Type.REQUIRED)
public List<String> hello() {
    alohaService.aloha(lraClient.getCurrent())
}

@POST
@PUT("/complete")
@Complete
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();
}

@POST
@Path("/compensate")
@Compensate
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

microprofile

cajk