Course contentsShow
← Cloud and Infrastructure
Lesson 2521 of 2,98954. Serverless ArchitecturesFree lesson

Parallel and Map States

Implementing concurrent execution branches and dynamic parallel processing with map states for batch operations.

Parallel and Map States

What you'll learn: How to run multiple branches at once or process large batches in parallel within serverless workflows.

The Power of Concurrency in State Machines

When orchestrating serverless workflows, you often need to do multiple things simultaneously or process a list of items in bulk. That's where Parallel and Map states shine. Both enable concurrent execution, but they serve different purposes.

Parallel State: Multiple Independent Branches

A Parallel state lets you execute multiple workflow branches at the same time. Think of it like splitting a recipe: while the oven preheats (branch 1), you can chop vegetables (branch 2) and marinate meat (branch 3)—all happening concurrently.

Each branch runs its own sequence of states independently. The Parallel state waits for all branches to complete before moving forward, collecting each branch's output.

Use cases: Simultaneously query multiple databases, call different APIs, or perform independent validations that don't depend on each other.

Map State: Dynamic Batch Processing

A Map state iterates over an array and processes each item in parallel (within concurrency limits). Imagine processing 1,000 order confirmations—instead of handling them one-by-one sequentially, the Map state spawns parallel executions for each order.

You define one set of processing steps, and the Map state applies them to every item in your input array. You control the degree of parallelism with a MaxConcurrency setting to avoid overwhelming downstream systems.

Use cases: Bulk image resizing, batch data transformations, parallel API calls per customer ID, or any "for-each" operation on large datasets.

The Key Difference

Parallel runs different workflows simultaneously. Map runs the same workflow across multiple items simultaneously.

Key Takeaway: Use Parallel states for concurrent independent tasks and Map states for scalable batch processing—both dramatically reduce total execution time in serverless orchestrations.