One read of the clock breaks a workflow, hours later
transcript
One line reads the system clock. It works perfectly today. Hours later, the same workflow fails. Nobody touched it.
First, the problem it solves. Your code reserves inventory, then crashes. On restart, reserve again? Double reservation. Skip it? The order is stuck. Temporal records every completed activity. After a crash, it replays your workflow from the start. Completed steps aren't run again. They just return their recorded result.
But here's the catch. Replay means your workflow code runs again. And it must make exactly the same decisions every time.
A developer checks the system clock, to see if a promo discount applies. First run: before the deadline. Discount applied. Recorded. Then a crash. The replay happens hours later. Now the clock says the promo ended. Different branch from the history. A non-determinism error.
So in workflow code: no system time, no random numbers, no fresh UUIDs. No HTTP calls or database queries either. Use workflow dot now instead. It matches the recorded history. And every side effect goes in an activity. Clock sync won't save you.
Workflows make decisions, and replay them exactly. Activities do the work, and their results are recorded. Anything that changes between runs belongs in an activity.
Full breakdown in the lecture.