Saga pattern in Kafka based micro-services – let’s do distributed commits

Often times there is a need to create the concept of an atomic commit in a distributed system. Consider the following scenario: you split your former monolith into several micro-services, that communicate among them via asynchronous message passing. If a business process requires the contribution of several services, it might be the case that a single service failure implies the rollback of the entire flow. A practical example is the processing of a web store’s shopping basket, if the credit card service is unable to charge the customer, the order must be canceled.

This article presents the saga pattern and discusses its implementation in a Kafka based micro-services system.

Moving away from 2PC

The saga pattern

Creating a saga

Injecting a saga into a Kafka message

Deduplication

Sagas benefits

Conclusions