Choreography Saga Pattern With Spring Boot — Microservice Design Patterns

A Simple Transaction:

Saga Pattern:

  • Choreography approach
  • Orchestration approach

Event Sourcing:

  1. Order created event basically informs that a new order request has been received and kept in the PENDING/CREATED status by order-service. It is not yet fulfilled.
  2. The event object will be named in the past tense always as it already happened!
  • There is no service dependency. payment-service/inventory-service do not have to be up and running always.
  • Loose coupling
  • Horizontal scaling
  • Fault tolerant
  • order-services receives a POST request for a new order
  • It places an order request in the DB in the ORDER_CREATED state and raises an event
  • payment-service listens to the event, confirms about the credit reservation
  • inventory-service also listens to the order-event and conforms the inventory reservation
  • order-service fulfills order or rejects the order based on the credit & inventory reservation status.


  • I created a simple Spring Boot project using kafka-cloud-stream. I have basic project structure which looks like this.
  • It contains the basic DTOs, Enums and Event objects.

Payment Service:

Inventory Service:

Order Service:

  • order events publisher
  • Order service also consumes payment and inventory events to take decision on the order.
  • I am unable to provide the entire project code here. So do check the GitHub link at the end of this article for the complete source code.


  • Once I start my application, I send an order request. The productId=3 costs $300 and user’s credit limit is $1000.
  • As soon as I send a request, I get the immediate response saying the order_created / order_pending.
  • I send 4 requests.
  • If I send /order/all requests to see all the orders, I see that 3 orders in fulfilled and the 4th order in cancelled status as the user does not have enough balance to fulfill the 4th order.
  • We can add additional services in the same way. For ex: once order-service fulfills the order and raises an another event. A shipping service listening to the event and takes care of packing and shipping to the given user address. Order-service might again listen to those events updates its DB to the order_shipped status.





Principal Software Engineer — passionate about software architectural design, microservices.

Love podcasts or audiobooks? Learn on the go with our new app.

Recommended from Medium

Creating an FX Correlation Heatmap in Python — Simplifying Trading Decisions.

ForrestJS — Universal React

What the heck is std::move() anyway?

max fashion customer care number/8584892738//8584892738/max fashion customer care…

Gevent Part 2: Correctness

Modernizing monolithic applications to serverless architecture on AWS

How to deploy a Python/Flask App to Vercel

It’s January 25 2017 at 08:00AM good morning people!!

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Vinoth Selvaraj

Vinoth Selvaraj

Principal Software Engineer — passionate about software architectural design, microservices.

More from Medium

Reactive Programming Using Spring Webflux

Definition of IOC Container & DI in Spring Framework

Spring Boot Microservices — Part4 — OpenFeign

Circuit Breaker Pattern With Netflix-Hystrix: Java