Demonstrates durable execution by using a simple counter in Python (before and after Temporal)
- Create a virtual environment:
python -m venv . - Activate virtual environment:
source ./bin/activate - Install Temporal SDK:
pip install temporalio
cd normal-execution- Open
businesslogic.pyin an editor and briefly explain the code, and then explainstart-execution.py, which calls it. - Execute by running
python start-execution.py - While it is running, press Ctrl-C in the terminal to terminate it
- Point out the last number displayed and ask the audience what number they expect to see upon restarting it. Most programmers should recognize that it will begin with 1, since all state from the previous execution is lost, though non-technical people may be surprised by this.
- Repeat step 2 to restart the execution, point out that it began with 1 even though that repeats what was done before. Explain why this would be bad (e.g., it's inefficient and could have a detrimental effect in some cases, such as when a customer gets charged twice for a single purchase).
Note that there is no need to show the code, although technical
audiences may benefit from seeing the Workflow code (in the
businesslogic.py file), since the code is not very different
than what they saw before (though there are a few small changes)
cd durable-execution- Run the Temporal Service:
temporal server start-dev(optionally add the--db-filenameoption, so that the state of Workflow Executions isn't lost if the service crashes). - Run
python start-execution.py(this launches a Worker, submits the Workflow for execution, and shuts down the Worker when that execution is complete. - Press Ctrl-C to terminate the process while the count is underway. Point out the last number displayed and ask what the next number will be. Unlike the normal execution shown before, this is a durable execution because of Temporal, so it's going to resume where it left off as if nothing had happened.
- Deactivate the virtual environment:
cd ..; deactivate