saga-service

module
v0.0.0-...-e360745 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 26, 2022 License: Apache-2.0

README

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

Directories

Path Synopsis
cmd
saga-service
Grüezi! The saga-service orchestrates work of other services using saga pattern.
Grüezi! The saga-service orchestrates work of other services using saga pattern.
saga-service/handlers
Package handlers manages the different versions of the API.
Package handlers manages the different versions of the API.
tooling/admin
This program performs administrative tasks for the saga-service service.
This program performs administrative tasks for the saga-service service.
pkg
business/saga
Package saga implements saga orchestration logic.
Package saga implements saga orchestration logic.
data/database
Package database provides support for access the database.
Package database provides support for access the database.
data/database/dbschema
Package dbschema contains the database schema, migrations and seeding data.
Package dbschema contains the database schema, migrations and seeding data.
sys/logger
Package logger provides a convenience function to constructing a logger for use.
Package logger provides a convenience function to constructing a logger for use.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL