When to use concurrent tasks
Use concurrent tasks when you need to:- Call multiple external services simultaneously (e.g., fetching data from different APIs)
- Race multiple operations and use the first result (e.g., trying multiple LLM providers)
- Implement timeouts by racing an operation against a timer
- Perform batch operations where individual tasks can run in parallel
Key benefits
- Deterministic replay: Restate logs the order of completion, ensuring consistent behavior during failures
- Fault tolerance: If your handler fails, tasks that were already completed will be replayed with their results, while pending tasks will be retried
Parallelizing tasks
Start multiple durable operations concurrently by calling them without immediately awaiting:Retrieving results
Restate provides several patterns for coordinating concurrent tasks. All patterns useDurableFuture
combinators that log the order of completion, ensuring deterministic behavior during replays.
Wait for the first completion
Select creates aDurableFuture
that returns on the first completed DurableFuture
of the provided ones.
The semantics are similar to CompleteableFuture.anyOf()
, but the outcome is stored in the Restate journal to be deterministically replayable.
Wait for all tasks to complete
Await all creates aDurableFuture
that awaits for all the provided DurableFutures to resolve.
The semantics are similar to CompleteableFuture.allOf()
, but the outcome is stored in the Restate journal to be deterministically replayable.