All Projects → nomisRev → Saga

nomisRev / Saga

Licence: Apache-2.0 License
Saga pattern implementation in Kotlin build in top of Kotlin's Coroutines.

Programming Languages

kotlin
9241 projects

Projects that are alternatives of or similar to Saga

grabbit
A lightweight transactional message bus on top of RabbitMQ
Stars: ✭ 87 (+262.5%)
Mutual labels:  saga, saga-pattern
OpenSleigh
OpenSleigh is a Saga management library for .NET Core.
Stars: ✭ 198 (+725%)
Mutual labels:  saga, saga-pattern
kmm
Rick & Morty Kotlin Multiplatform Mobile: Ktor, Sqldelight, Koin, Flow, MVI, SwiftUI, Compose
Stars: ✭ 52 (+116.67%)
Mutual labels:  coroutines, ktor
Sunset-hadith
Islamic app written with Kotlin, using KTOR + coroutines + flow + MVVM + Android Jetpack + Navigation component. Old version using RxJava + Retrofit + OKHttp
Stars: ✭ 26 (+8.33%)
Mutual labels:  coroutines, ktor
Lastik
Kotlin Multiplatform + Jetpack Compose pet project, based on www.last.fm/api (in development)
Stars: ✭ 37 (+54.17%)
Mutual labels:  coroutines, ktor
kotlinx-sockets
Kotlinx coroutines sockets
Stars: ✭ 54 (+125%)
Mutual labels:  coroutines
Keemun
No description or website provided.
Stars: ✭ 13 (-45.83%)
Mutual labels:  coroutines
JustJava-Android
JustJava is a mock food ordering and delivery application for a coffee shop.
Stars: ✭ 59 (+145.83%)
Mutual labels:  coroutines
koru
Simple coroutine wrappers for Kotlin Native. Generated from annotations. Compatible with RxSwift, Combine etc.
Stars: ✭ 141 (+487.5%)
Mutual labels:  coroutines
elixir cluster
Distributed Elixir Cluster on Render with libcluster and Mix Releases
Stars: ✭ 15 (-37.5%)
Mutual labels:  distributed-systems
kit
C++11 libs: await, channels, reactive/signals, timelines, alarms, logging, args, etc.
Stars: ✭ 21 (-12.5%)
Mutual labels:  coroutines
open-box
Generalized and Efficient Blackbox Optimization System [SIGKDD'21].
Stars: ✭ 174 (+625%)
Mutual labels:  distributed-systems
v6d
vineyard (v6d): an in-memory immutable data manager. (Project under CNCF)
Stars: ✭ 557 (+2220.83%)
Mutual labels:  distributed-systems
node-cqrs
CQRS backbone with event sourcing for Node.js
Stars: ✭ 63 (+162.5%)
Mutual labels:  saga
chapar
A framework for verification of causal consistency for distributed key-value stores and their clients in Coq [maintainer=@palmskog]
Stars: ✭ 29 (+20.83%)
Mutual labels:  distributed-systems
XLearning-GPU
qihoo360 xlearning with GPU support; AI on Hadoop
Stars: ✭ 22 (-8.33%)
Mutual labels:  distributed-systems
FreeSql.Cloud
提供跨数据库访问,分布式事务TCC、SAGA解决方案。
Stars: ✭ 42 (+75%)
Mutual labels:  saga
ktor-health-check
Simple, opinionated health checks Kubernetes-style health checks for ktor
Stars: ✭ 26 (+8.33%)
Mutual labels:  ktor
GitHubApplication
GitHubApplication 📱 is an Android application built to demonstrate the use of modern Android development tools - (Kotlin, Coroutines, Hilt, LiveData, View binding, Data Store, Architecture components, MVVM, Room, Retrofit, Navigation).
Stars: ✭ 11 (-54.17%)
Mutual labels:  coroutines
Layr
A decentralized (p2p) file storage system built atop Kademlia DHT that enforces data integrity, privacy, and availability through sharding, proofs of retrievability, redundancy, and encryption, with smart-contract powered incentive scheme
Stars: ✭ 90 (+275%)
Mutual labels:  distributed-systems

Module Saga

Maven Central Latest snapshot Website can be found here

Add in build.gradle.kts

repositories {
    mavenCentral()
}

dependencies {
    implementation("io.github.nomisrev:saga:0.1.3")
}

The saga design pattern is a way to manage data consistency across microservices in distributed transaction scenarios.

A [Saga] is useful when you need to manage data in a consistent manner across services in distributed transaction scenarios. Or when you need to compose multiple [action]s with a [compensation] that needs to run in a transaction like style. For example, let's say that we have following domain types Order, Payment.

data class Order(val id: UUID, val amount: Long)
data class Payment(val id: UUID, val orderId: UUID)

The creation of an Order can only remain when a payment has been made.

In SQL you might run this inside a transaction, which can automatically rollback the creation of the Order when the creation of the Payment fails. When you need to do this across distributed services, or a multiple atomic references, etc you need to manually facilitate the rolling back of the performed actions, or compensating actions.

The [Saga] type, and [saga] DSL remove all the boilerplate of manually having to facilitate this with a convenient suspending DSL.

data class Order(val id: UUID, val amount: Long)

suspend fun createOrder(): Order = Order(UUID.randomUUID(), 100L)
suspend fun deleteOrder(order: Order): Unit = println("Deleting $order")

data class Payment(val id: UUID, val orderId: UUID)

suspend fun createPayment(order: Order): Payment = Payment(UUID.randomUUID(), order.id)
suspend fun deletePayment(payment: Payment): Unit = println("Deleting $payment")

suspend fun Payment.awaitSuccess(): Unit = throw RuntimeException("Payment Failed")

suspend fun main() {
  saga {
    val order = saga { createOrder() }.compensate(::deleteOrder).bind()
    val payment = saga { createPayment(order) }.compensate(::deletePayment).bind()
    payment.awaitSuccess()
  }.transact()
}

// Deleting Payment(id=5753e9bb-248a-4385-8c9c-4a524e80c0f9, orderId=3a55ffab-a3f5-40a9-a2b3-681dc17b174e)
// Deleting Order(id=3a55ffab-a3f5-40a9-a2b3-681dc17b174e, amount=100)
// Exception in thread "main" java.lang.RuntimeException: Payment Failed
//   at io.github.nomisrev.TestKt.awaitSuccess(test.kt:11)
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].