
Simulate failures
- Understand the application
- Run the application
- Simulate failures
Despite your best efforts, sometimes things go wrong - a network glitch, a server going offline, or a new bug. One of Temporal's most important features is its ability to maintain Workflow state when something fails. Simulate some failures and see how Temporal responds.
Recover from a server crash
Unlike many modern applications that require complex processes and external databases to handle failure, Temporal automatically preserves the state of your Workflow even if the server is down.
- Make sure your Worker is stopped. Press
CTRL+Cin the Worker terminal. - Switch back to the terminal where your Workflow ran. Start the Workflow again with
python run_workflow.py. - Verify the Workflow is running in the UI.
- Shut down the Temporal Server by pressing
CTRL+Cin the server terminal. - After the Cluster has stopped, restart it and reload the UI.
Your Workflow is still listed:

If the Temporal Cluster goes offline, you can pick up where you left off when it comes back online.
Recover from an unknown error in an Activity
This demo makes a call to an external service in an Activity. If that call fails due to a bug, the Activity produces an error.
To test this out, simulate a bug in the deposit() Activity method. Let your Workflow continue to run but don't start the Worker yet.
- Open the
activities.pyfile and switch out the comments on thereturnstatements so that thedeposit()method callsself.bank.deposit_that_fails. - Save your changes and switch to the Worker terminal.
- Start the Worker again:
python run_worker.py
You'll see the Worker complete withdraw() but error on deposit() - and keep retrying:
2024/02/12 10:59:09 INFO Started Worker
2024/02/12 10:59:09 Withdrawing $250 from account 85-150.
2024/02/12 10:59:09 Depositing $250 into account 43-812.
2024/02/12 10:59:09 ERROR Activity error. ActivityType Deposit Attempt 1 Error This deposit has failed.
2024/02/12 10:59:10 Depositing $250 into account 43-812.
2024/02/12 10:59:10 ERROR Activity error. ActivityType Deposit Attempt 2 Error This deposit has failed.
2024/02/12 10:59:12 Depositing $250 into account 43-812.
2024/02/12 10:59:12 ERROR Activity error. ActivityType Deposit Attempt 3 Error This deposit has failed.
...
The Workflow keeps retrying using the RetryPolicy defined earlier.
View more in the Web UI:

Traditionally, you'd implement timeout and retry logic in your service code itself. With Temporal, you specify timeout configurations in the Workflow code as Activity options.
Your Workflow is running, but only withdraw() has succeeded. In any other application, the whole process would be abandoned. With Temporal, you can debug and fix the issue while the Workflow is running.
Pretend that you found a fix. Switch the comments back on the return statements of the deposit() method and save your changes.
To restart the Worker, cancel it with CTRL+C, then restart:
python run_worker.py
On the next scheduled attempt, the Worker picks up right where the Workflow was failing and executes the fixed deposit() Activity:
Transfer complete.
Withdraw: {'amount': 250, 'receiver': '43-812', 'reference_id': '1f35f7c6-4376-4fb8-881a-569dfd64d472', 'sender': '85-150'}
Deposit: {'amount': 250, 'receiver': '43-812', 'reference_id': '1f35f7c6-4376-4fb8-881a-569dfd64d472', 'sender': '85-150'}
Visit the Web UI again and you'll see the Workflow has completed:

You have just fixed a bug in a running application without losing the state of the Workflow or restarting the transaction.
Conclusion
You now know how to run a Temporal Workflow and understand some of the value Temporal offers. You explored Workflows and Activities, you started a Workflow Execution, and you ran a Worker. You also saw how Temporal recovers from failures and retries Activities.
Key advantages Temporal offers:
- Temporal gives you full visibility in the state of your Workflow and code execution.
- Temporal maintains the state of your Workflow, even through server outages and errors.
- Temporal lets you time out and retry Activity code using options that exist outside your business logic.
- Temporal enables you to perform "live debugging" of your business logic while the Workflow is running.
Further exploration
Try the following before moving on:
- Change the Retry Policy in
workflows.pyso it only retries 1 time. Then change thedeposit()Activity inactivities.pyso it uses therefund()method. Does the Workflow place the money back into the original account?
What's next?
Get notified when we launch new educational content
New courses, tutorials, and learning resources - straight to your inbox.