---
title: "Advanced: Multiple Parents with Partitioning"
description: "Spread requests across several parent Flow IDs, so the total number of running SubFlows can exceed one parent's concurrency limit."
canonical_url: "https://docs.superdurable.io/design-patterns/subflows/partitioning/"
source: "docs/content/design-patterns/subflows/partitioning.mdx"
locale: "en"
language: "python"
---

> Index of every page for AI agents: https://docs.superdurable.io/llms.txt

# Advanced: Multiple Parents with Partitioning

Code on this page is in Python. Other languages: [Go](https://docs.superdurable.io/design-patterns/subflows/partitioning.go.md) · [Java](https://docs.superdurable.io/design-patterns/subflows/partitioning.java.md) · [TypeScript](https://docs.superdurable.io/design-patterns/subflows/partitioning.typescript.md) · [Rust](https://docs.superdurable.io/design-patterns/subflows/partitioning.rust.md)

Spread requests across several parent Flow IDs, so the total number of running SubFlows can exceed one parent's concurrency limit.

**Flow graph: SubmitRequestFlow**

**Steps**

1. `SubmitStep` (start Step): Pick a parent Flow by partition and queue the request on it. Next: the Flow completes.

Example: [examples/python/dex_examples/patterns/parallel-subflows/submit_request_flow.py](https://github.com/superdurable/dex/tree/main/examples/python/dex_examples/patterns/parallel-subflows/submit_request_flow.py)

Use a stable partition key, such as a request ID hash modulo the number of parents. Every request with the same key reaches the same parent. Each parent applies its own Channel buffer limit and SubFlow concurrency limit. Adding parents adds total capacity, and no single Flow grows without limit.

Changing the number or order of parents sends some keys to a different parent. If each key must keep reaching the same parent while you scale, use a versioned parent set or consistent hashing.

## Core implementation

`SubmitStep` first invokes the RPC of the selected parent. If that parent does not exist or is no longer running, `SubmitStep` starts it with the request as its initial input. The parent's **Init** publishes that input to `RequestChannel`, so the request is not lost. If another submitter starts the parent first, the start fails with `FlowAlreadyStarted` and `SubmitStep` retries. Its next execution invokes the RPC on the running parent.

**Python**

```python
async def enqueue_request(client, parent_flow, parent_id: str, request: str) -> bool:
    try:
        return await client.invoke_rpc(parent_flow.send_request, parent_id, request)
    except FlowNotActiveOrNotFoundError:
        await client.start_flow(
            parent_flow,
            parent_id,
            ParentInput([request], DEFAULT_CONCURRENCY),
            StartFlowOptions(id_reuse_policy=IdReusePolicy.ALLOW_IF_NOT_RUNNING),
        )
        return True


def partition(request: str, partitions: int) -> int:
    hash_value = 2_166_136_261
    for byte in request.encode():
        hash_value ^= byte
        hash_value = hash_value * 16_777_619 & 0xFFFFFFFF
    return hash_value % partitions
```

Example: [examples/python/dex_examples/patterns/parallel-subflows/submit_request_flow.py](https://github.com/superdurable/dex/tree/main/examples/python/dex_examples/patterns/parallel-subflows/submit_request_flow.py)

## Next

- [Back pressure for high availability](https://docs.superdurable.io/design-patterns/subflows/back-pressure.md)
- [Short-lived parent](https://docs.superdurable.io/design-patterns/subflows/short-lived-parent.md)
