blue86321 / microservices-saga-demo

Microservices architecture demo based on Saga pattern: choreography and orchestration. The origin article is on Medium.

Home Page:https://medium.com/p/d40f68cafbf0

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Microservices Saga Demo

This repo is a demo to implement microservices architecture based on Saga.

The origin article is on Medium: Transactional Patterns in Microservices Based on Saga.

Overview

  • Choreography-Based Saga: Each service focuses on event publish and subscription, indirectly communicate with each other through message queue.
  • Orchestration-Based Saga: Service dependency is managed by an orchestrator.

Choreography-Based Saga

Demo Overview

choreography-demo-overview
Choreography-Based Demo Overview

Run

# Deploy container (Ctrl-C to exit)
docker compose -f docker-compose-choreography.yaml up

choreography-service-ready
Choreography-Based Saga: Services Ready

Send Request

# Send Request to Gateway
curl -XPOST 'http://localhost:8080/order' -d '{"userId": "user1", "productId": "DUMMY_PRODUCT", "quantity": 1, "totalPrice": 100}' -H "Content-Type: application/json"

Result

##### [Gateway]: PlaceOrder - Go to Order Service                   # Step 2
##### [Order]: Send CheckInventoryRequest to Message Queue          # Step 3
##### [Product]: Receive CheckInventoryRequest from Message Queue   # Step 4
##### [Product]: Checking Inventory
##### [Product]: Send CheckInventoryResponse to Message Queue       # Step 5
##### [Order]: Receive CheckInventoryResponse from Message Queue    # Step 6
##### [Order]: Creating Order
##### [Order]: PlaceOrder Done and Return                           # Step 7
##### [Gateway]: PlaceOrder Done and Return                         # Step 8

choreography-result
Choreography-Based Saga: Result

Delete

# Delete all containers and relevant images
docker compose -f docker-compose-choreography.yaml down --rmi all

Orchestration-Based Saga

Demo Overview

orchestration-demo-overview
Orchestration-Based Demo Overview

Run

# Deploy container (Ctrl-C to exit)
docker compose -f docker-compose-orchestration.yaml up

orchestration-service-ready
Orchestration-Based Saga: Services Ready

Send Request

# Send Request to Gateway
curl -XPOST 'http://localhost:8080/order' -d '{"userId": "user1", "productId": "DUMMY_PRODUCT", "quantity": 1, "totalPrice": 100}' -H "Content-Type: application/json"

Result

##### [Gateway]: PlaceOrder - Go to Orchestration Service                 # Step 2
##### [Orchestrator]: PlaceOrder - Check Inventory with Product Service   # Step 3
##### [Product]: Checking Inventory
##### [Orchestrator]: PlaceOrder - Check Inventory Done                   # Step 4
##### [Orchestrator]: PlaceOrder - Create Order with Order Service        # Step 5
##### [Order]: Creating Order
##### [Orchestrator]: PlaceOrder - Order Created                          # Step 6
##### [Orchestrator]: PlaceOrder Done and Return                          # Step 7
##### [Gateway]: PlaceOrder Done and Return                               # Step 8

orchestration-result
Orchestration-Based Saga: Result

Delete

# Delete all containers and relevant images
docker compose -f docker-compose-orchestration.yaml down --rmi all

About

Microservices architecture demo based on Saga pattern: choreography and orchestration. The origin article is on Medium.

https://medium.com/p/d40f68cafbf0

License:MIT License


Languages

Language:Java 95.5%Language:Makefile 3.2%Language:Dockerfile 1.3%