You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This sample demonstrates how to process large batches of activities with controlled concurrency using Cadence's `workflow.NewBatchFuture` functionality, while respecting the 1024 pending activities limit per workflow.
4
+
5
+
## The problem it solves
6
+
7
+
**The Problem**: When processing large datasets (thousands of records, files, or API calls), you face a dilemma:
8
+
-**Sequential processing**: Too slow, poor user experience
9
+
-**Unlimited concurrency**: Overwhelms databases, APIs, or downstream services
10
+
-**Manual concurrency control**: Complex error handling and resource management
11
+
-**Cadence limits**: Max 1024 pending activities per workflow
12
+
13
+
**Real-world scenarios**:
14
+
- Processing 10,000 user records for a migration
15
+
- Sending emails to 50,000 subscribers
16
+
- Generating reports for 1,000 customers
17
+
- Processing files in a data pipeline
18
+
19
+
### The Solution
20
+
`workflow.NewBatchFuture` provides a robust solution:
21
+
22
+
**Controlled Concurrency**: Process items in parallel while respecting system limits
23
+
**Automatic Error Handling**: Failed activities don't crash the entire batch
24
+
**Resource Efficiency**: Optimal throughput without overwhelming downstream services
25
+
**Built-in Observability**: Monitoring, retries, and failure tracking
26
+
**Workflow Integration**: Seamless integration with Cadence's workflow engine
27
+
28
+
This eliminates the need to build custom concurrency control, error handling, and monitoring systems.
29
+
30
+
## Sample behavior
31
+
32
+
- Creates a configurable number of activities (default: 10)
33
+
- Executes them with controlled concurrency (default: 3)
34
+
- Simulates work with random delays (900-999ms per activity)
35
+
- Handles cancellation gracefully
36
+
37
+
## Technical considerations
38
+
39
+
-**Cadence limit**: Maximum 1024 pending activities per workflow
40
+
-**Resource management**: Controlled concurrency prevents system overload
41
+
-**Error handling**: Failed activities don't crash the entire batch
0 commit comments