Skip to content

Commit 39d3a9b

Browse files
committed
Enhance migration path section
Signed-off-by: “Kevin” <[email protected]>
1 parent d790959 commit 39d3a9b

File tree

1 file changed

+37
-28
lines changed

1 file changed

+37
-28
lines changed

blog/2025-09-25-introducing-batch-future-faster-activity-execution.md

Lines changed: 37 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -179,36 +179,45 @@ go get github.com/uber/cadence-go-client@latest
179179
### 2. Try the Sample
180180
Check out our [Batch Future sample](https://github.com/cadence-workflow/cadence-samples/tree/master/cmd/samples/batch) to see it in action.
181181

182-
### 3. Migrate Your Workflows
183-
Identify workflows that process multiple items and convert them to use Batch Future:
182+
### 3. Migrate Your Workflows (With Caution)
184183

185-
```go
186-
// Before: Uncontrolled concurrency
187-
var futures []workflow.Future
188-
for _, item := range items {
189-
future := workflow.ExecuteActivity(ctx, ProcessItem, item)
190-
futures = append(futures, future)
191-
}
192-
for _, future := range futures {
193-
if err := future.Get(ctx, nil); err != nil {
194-
return err
195-
}
196-
}
184+
**This is not a simple code change**. Migrating to Batch Future requires workflow versioning and careful production planning.
197185

198-
// After: Controlled concurrency with Batch Future
199-
factories := make([]func(workflow.Context) workflow.Future, len(items))
200-
for i, item := range items {
201-
item := item // Capture loop variable
202-
factories[i] = func(ctx workflow.Context) workflow.Future {
203-
return workflow.ExecuteActivity(ctx, ProcessItem, item)
204-
}
205-
}
206-
batch, err := workflow.NewBatchFuture(ctx, 3, factories) // Limit to 3 concurrent
207-
if err != nil {
208-
return err
209-
}
210-
return batch.Get(ctx, nil)
211-
```
186+
#### The Challenge
187+
Batch Future changes your workflow's execution pattern from individual activities to controlled batching. This creates non-deterministic changes that will break existing running workflows without proper versioning.
188+
189+
#### Migration Approaches
190+
191+
**Option A: Versioned Migration (Recommended for Production)**
192+
- Use [workflow.GetVersion()](https://cadenceworkflow.io/docs/go-client/workflow-versioning) to support both old and new patterns
193+
- Deploy code that handles both execution patterns
194+
- Gradually transition new workflows to use Batch Future
195+
- Clean up old code after all workflows complete
196+
197+
**Option B: New Workflow Type (Simpler but Requires Coordination)**
198+
- Create a new workflow type specifically for Batch Future
199+
- Update callers to use the new workflow type
200+
- Deprecate the old workflow type after migration
201+
202+
**Option C: Gradual Migration (For Large Systems)**
203+
- Use workflow signals to trigger batch processing for new items
204+
- Keep existing workflows running with individual processing
205+
- Migrate callers incrementally
206+
207+
#### Testing Strategy
208+
Before deploying, use [Workflow Shadowing](https://cadenceworkflow.io/docs/go-client/workflow-replay-shadowing) to replay production workflow histories against your new code. This catches compatibility issues before they reach production.
209+
210+
#### Key Considerations
211+
- **Timeline**: Plan for weeks, not days
212+
- **Coordination**: Requires careful coordination between teams
213+
- **Monitoring**: Essential during transition period
214+
- **Rollback**: Always have a rollback plan ready
215+
- **Testing**: Extensive testing in staging environment required
216+
217+
#### When NOT to Migrate
218+
- If you have long-running workflows (weeks/months)
219+
- If you can't coordinate a proper versioning strategy
220+
- If the performance benefits don't justify the migration complexity
212221

213222
## Best Practices
214223

0 commit comments

Comments
 (0)