# Why can't Workflows contain non deterministic code? And how does using activity solve the problem?

**URL:** <https://community.temporal.io/t/why-cant-workflows-contain-non-deterministic-code-and-how-does-using-activity-solve-the-problem/3231>\
**Category:** Community Support\
**Tags:** java-sdk\
**Created:** [October 24, 2021, 12:53pm UTC](https://community.temporal.io/t/why-cant-workflows-contain-non-deterministic-code-and-how-does-using-activity-solve-the-problem/3231 "2021-10-24T12:53:21Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![Abhishek\_Chatterjee](https://sea2.discourse-cdn.com/flex016/user_avatar/community.temporal.io/abhishek_chatterjee/32/4866_2.png) [@Abhishek\_Chatterjee](https://community.temporal.io/u/Abhishek_Chatterjee)\
**Post date:** [January 28, 2024, 10:48am UTC](https://community.temporal.io/t/why-cant-workflows-contain-non-deterministic-code-and-how-does-using-activity-solve-the-problem/3231/7 "2024-01-28T10:48:56Z")

</div>

Hi @tihomir, thanks for clarification. being a new bee in the temporal world, I have a similar question on determinism. Say I have the below activitis,

1. authenticate request ( **deterministic** activity)
2. check balance ( **non-deterministic** activity)
3. debit amount ( **non-deterministic** activity)

Now the “balance check” activity invokes some third-party API to fetch the balance and my workflow crashes during “debit amount” step. Now since this “balance check” step was completed, so will that be executed again during default retry operation? If no, then how to ensure that during retry, both “balance check” and “debit amount” steps get executed?

Also, what is meant by “operations which write to the workflow event history”? Does it mean, that only below 2 type of invocations writes to the event history,

- static methods of “Workflow” class (like sleep, await etc.), when invoked explicitely
- our custom @WorkflowMethod, activity method, @SignalMethod  
but not the java statements/lines in the body of the activity method that does not belong to above two types?

---

_[View the full topic](https://community.temporal.io/t/why-cant-workflows-contain-non-deterministic-code-and-how-does-using-activity-solve-the-problem/3231)._
