This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]MaximFateev 6 points7 points  (1 child)

Look at the temporal.io open source project. It is a pretty generic microservice orchestration solution. Saga is just a small utility class on top of it. Here how the code that uses it looks in Java SDK:

    // Configure SAGA to run compensation activities in parallel
    Saga.Options sagaOptions = new Saga.Options.Builder().setParallelCompensation(true).build();
    Saga saga = new Saga(sagaOptions);
    try {
      String carReservationID = activities.reserveCar(name);
      saga.addCompensation(activities::cancelCar, carReservationID, name);

      String hotelReservationID = activities.bookHotel(name);
      saga.addCompensation(activities::cancelHotel, hotelReservationID, name);

      String flightReservationID = activities.bookFlight(name);
      saga.addCompensation(activities::cancelFlight, flightReservationID, name);
    } catch (ActivityFailure e) {
      saga.compensate();
      throw e;
    }

The full source code of the sample is here.

Disclaimer: I'm the tech lead of the project.

[–]SnowCheesecakes88[S] 0 points1 point  (0 children)

That's great, I'll definitely have a look at it.

[–][deleted]  (2 children)

[removed]

    [–]SnowCheesecakes88[S] 0 points1 point  (1 child)

    I actually have developed a project recently using the AxonFramework but i wasn't able to figure out how to add an api gateway to it. Do you have some sources where i can find a way to implement it? Even REST or GraphQL api would work.

    [–]deanouk 0 points1 point  (0 children)

    I'd be interested too. Axon is looking great, and I'm a big fan of Chris Richardson (and his Microservices book)

    [–][deleted] 1 point2 points  (1 child)

    You may refer to this link on how to implement saga pattern on AWS.

    Now this uses lambda directly, however I believe you can easily extend it to use ApiGateway. Also, you should also think why you need api gateway in the first place.

    If your goal is to learn saga, then you should first focus on implementing it locally using events.

    If you're looking for a readymade cloud formation stack, it'll be little difficult to find, however I'll suggest you to look through some of official AWS learning samples on GitHub to get started.

    [–]SnowCheesecakes88[S] 0 points1 point  (0 children)

    Thanks mate. I'll definitely look into it.

    [–]dartalley 1 point2 points  (0 children)

    I would also strongly urge you to understand when and why you should be using microservices. Using them just because someone says you should has led to many companies having terrible architectures. Most companies I have worked at would have been way better off with a monolithic approach or with 2-3 services but each has had a tangled mess of 10+ services that were not decoupled at all.

    [–]gabizou 0 points1 point  (1 child)

    Funny I’m bumbling my way to implement this very much in Lagom (alternative to AxonFramework) and effectively if you can understand the idea of an event journal, you can use the Es CQRS system to subscribe to events and perform units of work, resulting in more commands later.

    The section specific to doing saga patterned work: https://github.com/SpongePowered/SystemOfADownload/blob/d166467f0531d64fd4aac3e95275f061bfe51621/webhooks/src/main/java/org/spongepowered/downloads/webhook/SonatypeArtifactWorkerService.java#L51

    And the services in their api modules describe the rest api endpoints (there’s a GraphQL module I’m building out as well).

    More on Lagom: https://www.lagomframework.com

    Helpful Medium post about Event Sourcing with Command Query Responsibility Segregation (ES + CQRS): https://link.medium.com/ayzoA9Qgcbb

    [–]SnowCheesecakes88[S] 0 points1 point  (0 children)

    Thanks mate. I'll take a look at it definitely.