All Projects → meadsteve → talepy

meadsteve / talepy

Licence: MIT license
📚Coordinate "transactions" across a number of services in python

Programming Languages

python
139335 projects - #7 most used programming language
shell
77523 projects

Projects that are alternatives of or similar to talepy

Mysql Notes
MySQL 学习笔记
Stars: ✭ 227 (+1035%)
Mutual labels:  distributed-transactions
YACLib
Yet Another Concurrency Library
Stars: ✭ 193 (+865%)
Mutual labels:  concurrent
effector-reeffect
Concurrent effects for Effector ☄️
Stars: ✭ 56 (+180%)
Mutual labels:  concurrent
hlswatch
keep track of hls viewer stats
Stars: ✭ 44 (+120%)
Mutual labels:  concurrent
concurrent-programming-for-java
🚀Java并发编程实战
Stars: ✭ 55 (+175%)
Mutual labels:  concurrent
core.horse64.org
THIS IS A MIRROR, CHECK https://codeberg.org/Horse64/core.horse64.org
Stars: ✭ 3 (-85%)
Mutual labels:  concurrent
Bytejta
ByteJTA is a distributed transaction manager based on the XA/2PC mechanism. It’s compatible with the JTA specification. User guide: https://github.com/liuyangming/ByteJTA/wiki
Stars: ✭ 208 (+940%)
Mutual labels:  distributed-transactions
java-multithread
Códigos feitos para o curso de Multithreading com Java, no canal RinaldoDev do YouTube.
Stars: ✭ 24 (+20%)
Mutual labels:  concurrent
pareach
a tiny function that "parallelizes" work in NodeJS
Stars: ✭ 19 (-5%)
Mutual labels:  concurrent
gini
A fast SAT solver
Stars: ✭ 139 (+595%)
Mutual labels:  concurrent
simplx
C++ development framework for building reliable cache-friendly distributed and concurrent multicore software
Stars: ✭ 61 (+205%)
Mutual labels:  concurrent
xoid
Framework-agnostic state management library designed for simplicity and scalability ⚛
Stars: ✭ 96 (+380%)
Mutual labels:  concurrent
funboost
pip install funboost,python全功能分布式函数调度框架,。支持python所有类型的并发模式和全球一切知名消息队列中间件,python函数加速器,框架包罗万象,一统编程思维,兼容50% python编程业务场景,适用范围广。只需要一行代码即可分布式执行python一切函数。旧名字是function_scheduling_distributed_framework
Stars: ✭ 351 (+1655%)
Mutual labels:  concurrent
microservice workshop
Microservices Architecture Workshop focuses on helping the developers / architects to understand the key Architecture paradigms with hands on section. The course helps the developers from Monolithic App mindset to a Microservices based App development. It also helps the developers with hands on development experience with key Microservices infra…
Stars: ✭ 69 (+245%)
Mutual labels:  distributed-transactions
mango
Core utility library & data connectors designed for simpler usage in Scala
Stars: ✭ 41 (+105%)
Mutual labels:  concurrent
Joice
Java分布式开发平台:Spring, Spring MVC, MyBatis, Dubbo, Redis, Shiro权限管理, Quartz分布式调度, RocketMQ通信, 本地缓存, Redis缓存, 分布式缓存, 分布式事务
Stars: ✭ 219 (+995%)
Mutual labels:  distributed-transactions
Hunch
Hunch provides functions like: All, First, Retry, Waterfall etc., that makes asynchronous flow control more intuitive.
Stars: ✭ 94 (+370%)
Mutual labels:  concurrent
shardingsphere-ui
Distributed database middleware
Stars: ✭ 41 (+105%)
Mutual labels:  distributed-transactions
sig-transaction
Resources for the transaction SIG
Stars: ✭ 59 (+195%)
Mutual labels:  distributed-transactions
practice
Java并发编程与高并发解决方案:http://coding.imooc.com/class/195.html Java开发企业级权限管理系统:http://coding.imooc.com/class/149.html
Stars: ✭ 39 (+95%)
Mutual labels:  concurrent

Tale Distributed Transactions

Build Status

What?

Tale is a small library to help write a "distributed transaction like" object across a number of services. It's loosely based on the saga pattern. A good intro is available on the couchbase blog: https://blog.couchbase.com/saga-pattern-implement-business-transactions-using-microservices-part/

Installation

pipenv install talepy

Example Usage

An example use case of this would be some holiday booking software broken down into a few services.

Assuming we have the following services: Flight booking API, Hotel booking API, and a Customer API.

We'd write the following steps:

from talepy.steps import Step

class DebitCustomerBalance(Step):

    def __init__(self):
        self.payment_client= {}

    def execute(self, state):
        state['payment_id'] = self.payment_client.bill(state.customer_id, state.payment_amount)
        return state
        
    def compensate(self, state):
        self.payment_client.refund(state['payment_id'])
       

and so on for any of the steps needed. Then in whatever is handling the user's request a distributed transaction can be built:

from talepy import run_transaction

run_transaction(
    steps=[
        DebitCustomerBalance(), 
        BookFlight(), 
        BookHotel(), 
        EmailCustomerDetailsOfBooking()
    ],
    starting_state={}
)

If any step along the way fails then the compensate method on each step is called in reverse order until everything is undone.

Steps as Lambdas

For some cases you may not want to create a class for the step. Lambdas can be used directly instead. Extending the previous example:

from talepy import run_transaction

run_transaction(
    steps=[
        DebitCustomerBalance(), 
        BookFlight(),
        lambda _: print("LOG -- The flight has been booked"),
        BookHotel(), 
        EmailCustomerDetailsOfBooking()
    ],
    starting_state={}
)

This new print statement will now execute following a success in BookFlight.

It's also possible to implement compensations by adding another lambda as a tuple pair:

from talepy import run_transaction

run_transaction(
    steps=[
        DebitCustomerBalance(), 
        BookFlight(),
        (
            lambda _: print("LOG -- The flight has been booked"), 
            lambda _: print("LOG -- ┌[ ಠ ▃ ಠ ]┐ something went wrong")
        ),
        BookHotel(), 
        EmailCustomerDetailsOfBooking()
    ],
    starting_state={}
)

Automatic retries

You may also want to try a step a few times before giving up. A convinence function is provided to help out with this. Starting with the initial example. If the hotel booking step is a bit unreliable and we want to try it 3 times:

from talepy import run_transaction
from talepy.retries import attempt_retries

run_transaction(
    steps=[
        DebitCustomerBalance(), 
        BookFlight(),
        attempt_retries(BookHotel(), times=2), 
        EmailCustomerDetailsOfBooking()
    ],
    starting_state={}
)

The book hotel step will now be executed 3 times before the transaction is aborted. Once all these attempts fail the normal compensation logic will be applied.

Async

If you want to make use of async in your steps you will need to import run_transaction from talepy.async_transactions. This can be awaited on and allows async steps and compensations. In addition you can also run_concurrent_transaction where all steps will be executed concurrently. The downside here is that the ordering of the steps isn't guaranteed. This means all steps receive the same starting state.

example

from talepy.async_transactions import run_transaction
from talepy.steps import Step

class AsyncBookFlight(Step):

    async def execute(self, state):
        # do something
        return state
        
    async def compensate(self, state):
        # revert something
        pass
       

await run_transaction(
    step_defs=[
        DebitCustomerBalance(), 
        AsyncBookFlight(),
        EmailCustomerDetailsOfBooking()
    ],
    starting_state={}
)

Concurrent example

from talepy.async_transactions import run_concurrent_transaction
from talepy.steps import Step

class AsyncBookFlight(Step):

    async def execute(self, state):
        # do something
        return state
        
    async def compensate(self, state):
        # revert something
        pass
       

await run_concurrent_transaction(
    steps=[
        DebitCustomerBalance(), 
        AsyncBookFlight(),
        EmailCustomerDetailsOfBooking()
    ],
    starting_state={}
)

Testing / Development

TODO

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].