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.
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.
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.
- Docker and docker-compose
- Git
- GNU Make
- Go (if you want to compile and run the service without docker)
-
Clone this repository in the current directory:
git clone https://github.com/illyasch/saga-service -
Build Docker images:
make image
-
Migrate and seed the database and queues (uses Docker):
make init -
Start the local development environment (uses Docker):
make upAt this point you should have the saga-service service running. To confirm the state of the running Docker container, run
$ docker ps
from the docker container
make test
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
