Skip to content

illyasch/saga-service

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

saga-service

The service orchestrates the work of other services using the saga pattern.

Pattern: Saga

Maintain data consistency across services using a sequence of local transactions coordinated using asynchronous messaging.

Overview

Sagas are a mechanism to maintain data consistency in a microservice architecture. You define a saga for each system command that needs to update data in multiple services. A saga is a sequence of local transactions. Each local transaction updates data within a single service. The system operation initiates the first step of the saga. Completing a local transaction triggers the execution of the following local transaction.

An essential benefit of asynchronous messaging is that it ensures that all the steps of a saga are executed even if one or more of the saga's participants is temporarily unavailable.

Saga Service Diagram

HTTP handlers

The entry point to the code is in cmd/saga-service/saga-service.go. The service has the following HTTP handlers:

  • /start - use POST method and x-www-form-urlencoded parameter saga_id with a new saga ID in UUID format. Returns base62 code of the URL.
  • /readiness - check if the database is ready and will return a 500 status if it's not.
  • /liveness - return simple status info if the service is alive.

Prerequisites

Installation

  1. Clone this repository in the current directory:

    git clone https://github.com/illyasch/saga-service
    
  2. Build Docker images:

    make image
  3. Migrate and seed the database and queues (uses Docker):

    make init
    
  4. Start the local development environment (uses Docker):

    make up
    

    At this point you should have the saga-service service running. To confirm the state of the running Docker container, run

    $ docker ps
    

How to

Run unit tests

from the docker container

make test

Run manual tests

Start a new saga

$ curl -i --data-urlencode "saga_id=72639776-a13f-4c1b-b0c3-5feb2d525e4e" http://localhost:3000/start
HTTP/1.1 200 OK
Content-Type: application/json
Date: Sun, 26 Jun 2022 10:28:02 GMT
Content-Length: 4

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published