With Dispatch and resumable functions, it’s easy to build reliable workflows that perform a lot of work simultaneously or step-by-step.
Fan out
Consider an example scenario, where an application needs to send email notifications to all users. Use Batch to send emails to all users in parallel without waiting for completion.
Normally, when notifyUser returns an error even for one user, it would halt the execution of the notifyAllUsers function. Moreover, retrying notifyAllUsers would resend the same email to all users who already got that email. Sounds like a nightmare.
However, with Dispatch, only that one failed notifyUser call would retry, ensuring a consistent delivery of all emails.
Fan in
Gather waits for the completion of all function calls and returns their results. The order of results will be in the same order as the functions that returned them.
Take a look at this theoretical application that generates invoices. For each client in the database, it generates a PDF invoice and then uploads it to S3.
Gather makes building fault-tolerant multi-step workflows with fan-out/fan-in a breeze.