Skip to main content
This guide shows how to use the Restate to execute a list of tasks in parallel and then gather their result, also known as fan-out, fan-in.

How does Restate help?

  • Restate lets you schedule the tasks asynchronously and guarantees that all tasks will run, with retries and recovery on failures.
  • Restate turns Promises/Futures into durable, distributed constructs that are persisted in Restate and can be recovered and awaited on another process.
  • You can deploy the subtask executors on serverless infrastructure, like AWS Lambda, to let them scale automatically. The main task, that is idle while waiting on the subtasks, gets suspended until it can make progress.
Fan out: You can fan out tasks with Restate by creating a handler that processes a single subtask, and then scheduling it repeatedly from another handler. Fan in: You can fan in the results of the subtasks by using Restate’s Promise Combinators to wait for all promises to resolve.

Example

The example implements a worker service:
  1. It splits a task into subtasks.
  2. It schedules all the subtasks. Each subtask results in a promise that gets added to a list.
  3. The result is gathered by waiting for all promises to resolve.
You can run this on FaaS infrastructure, like AWS Lambda, and it will scale automatically. The run handler will then suspend while it waits for all subtasks to finish. Restate will then resume the handler when all subtasks are done.