Python | Durable Task SDK
Demonstrates the Saga pattern (compensating transactions) using the Durable Task SDK for Python. A travel booking orchestration reserves a flight, hotel, and rental car in sequence. If any step fails, previously completed steps are rolled back using compensating actions.
This pattern is useful for:
- Distributed transactions across multiple services
- Booking systems where all-or-nothing semantics are required
- Any multi-step process requiring rollback on failure
- Python 3.10+
- Docker (for the emulator)
-
Start the Durable Task Scheduler emulator:
docker run -d -p 8080:8080 -p 8082:8082 mcr.microsoft.com/dts/dts-emulator:latest
-
Install dependencies:
pip install durabletask
-
Start the worker (in one terminal):
python worker.py
-
Run the client (in another terminal):
python client.py
-
View in the dashboard: http://localhost:8082
- The orchestration attempts to book a flight, hotel, and car in sequence
- Each booking activity returns a confirmation ID on success
- If any step fails (e.g., no cars available), the orchestration enters compensation mode
- Compensation runs in reverse order — cancelling the hotel, then the flight
- The orchestration returns either a successful booking or a failure with details of what was rolled back