Workflows
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 send_email_notification
raises an exception even for one user, it would halt the execution of the notify_all_users
function. Moreover, retrying notify_all_users
would resend the same email to all users who already got that email. Sounds like a nightmare.
However, with Dispatch, only that one failed send_email_notification
call would retry, ensuring a consistent delivery of all emails.
Fan in
Unlike batch
, gather
waits for the completion of all functions 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.