resonate-recursive-fan-out-pattern-java
Resonate Recursive Fan-Out Pattern — Java
Prerelease note.
resonate-sdk-javais published on Maven Central — pinio.resonatehq:resonate-sdk-java:0.1.1. The API mirrors the Python SDK and may change before a stable1.0. Requires Java 21+ (virtual threads, a feature generally available in Java 21). Every code block here is compile-verified against0.1.1and drawn from theexample-fan-out-fan-in-java/example-recursive-factorial-javarepos anddevelop/java.mdx(docs PR #230).
Overview
Recursive fan-out dispatches multiple child invocations in parallel, awaits them individually, and optionally recurses deeper. The Java expression is a two-loop pattern: a dispatch loop builds a List<ResonateFuture<T>>, then a separate await loop reads each result. Mixing dispatch and await serializes the children — the single most common mistake.
For the language-agnostic mental model (promise deduplication, load-balancing, detached vs. result-gathering), see resonate-recursive-fan-out-pattern-typescript.
When to use
- Batch processing where items are independent and each needs durability
- Map-reduce shaped workflows (fan out N workers, aggregate results)
- Recursive tree / graph traversal with dynamic depth
- Any case where a crash mid-fan-out must resume, not restart from zero