Reader small image

You're reading from  Kotlin Design Patterns and Best Practices - Third Edition

Product typeBook
Published inApr 2024
PublisherPackt
ISBN-139781805127765
Edition3rd Edition
Right arrow
Author (1)
Alexey Soshin
Alexey Soshin
author image
Alexey Soshin

Alexey Soshin is a software architect with 18 years of experience in the industry. He started exploring Kotlin when Kotlin was still in beta, and since then has been a big enthusiast of the language. He's a conference speaker, published writer, and the author of a video course titled Pragmatic System Design
Read more about Alexey Soshin

Right arrow

Saga

The Saga pattern in distributed systems is akin to transactions in databases. It ensures that multiple operations across different services either succeed or fail together, maintaining consistency. Saga orchestrates this by associating each action with a compensatory action, which reverses the changes made by the action if any subsequent steps fail.

This functionality is crucial in avoiding inconsistent states in distributed environments. While similar to Software Transactional Memory (STM), Sagas specifically address distributed systems.

Consider the operation of a donut shop accepting delivery orders. The process involves several steps:

  1. Putting donuts into a box:
    • If subsequent steps fail, the donuts shouldn’t just be left in the box; they need to be unpacked and displayed again.
  2. Putting a label on the box:
    • If a failure occurs after this step, the label needs to be removed.
  3. Handing the...
lock icon
The rest of the page is locked
Previous PageNext Page
You have been reading a chapter from
Kotlin Design Patterns and Best Practices - Third Edition
Published in: Apr 2024Publisher: PacktISBN-13: 9781805127765

Author (1)

author image
Alexey Soshin

Alexey Soshin is a software architect with 18 years of experience in the industry. He started exploring Kotlin when Kotlin was still in beta, and since then has been a big enthusiast of the language. He's a conference speaker, published writer, and the author of a video course titled Pragmatic System Design
Read more about Alexey Soshin