Temporal Application
A Temporal Application is a set of Workflow Execution.
Temporal applications include both code you develop and features provided by a Temporal SDK. As a developer, you are responsible for developing Workflow Definitions and Activity Definitions —code that represents your business logic—as well as configuring the Worker and Client components provided by the SDK.
Should a Worker crash during a Workflow Execution, another Worker will automatically reconstruct the previous state and continue the execution from that point forward, as if the crash had never occurred at all. It achieves this by using a technique called History Replay
, which in turn requires that execution of the Workflow Definition is deterministic. This affects how you should approach Temporal application development and the following are best practices to follow:
Best practices for Temporal Application Development
- Use a single class, rather than individual parameters, as input parameters and return values in Workflow and Activity definitions. This helps to support backwards-compatible evolution of the data supplied and returned in their execution.
- Since Temporal imposes limits on the size of Events in the history associated with a Workflow Execution, avoid using large amounts of data for the inputs and outputs of Workflows and Activities.
- Avoid common sources of non-determinism, such as random numbers and system time, in your Workflow code. For example, instead of using Java’s
Thread.sleep
method, you can useWorkflow.sleep
to introduce a delay during Workflow Execution. - Although Workflow Definitions must execute deterministically, there is no such constraint on Activity Definitions. If an Activity fails due to a bug in the code, you can deploy a fix while the Workflow is still running. Activity failure is normal and expected, since they are retried automatically, but failing a Workflow is much less common.
- Use Temporal’s logging API, which won’t result in duplicate messages during History Replay, but consider integrating a third-party logging implementation. This will give you better control over which messages are logged, how they are displayed, and where they are stored.