Skip to main content

The Challenge

Let's start out with a common money transfer problem. Let's say that you need to write a basic reimbursement function that:

  • Withdraws a set amount from the company bank
  • Deposits that amount into the employee bank
  • Lets the user know that the reimbursement was successfully completed

But with distributed systems, a lot of failures can occur. For example, what if the withdrawal succeeds but the network crashes before the deposit? Not only would the service go down, but you could also lose the code’s state. If you try to rerun it, you might end up with two withdrawals but only one deposit.

Let's change this function into a durable Workflow.

Basic Reimbursement Function
async def reimbursement_workflow(user_id: str, amount: float) -> str:
# Insert code that withdraws money from company bank
# Insert code that deposits money into employee bank
return f"reimbursement to {user_id} successfully complete"
2 / 9