Skip to content

Example 5 Fan Out with MultiPipe

Fernando Koch edited this page Mar 30, 2026 · 3 revisions

Example 5: Fan Out With MultiPipe

Goal

Understand how GraphK executes several matching branches instead of only one.

Scenario

Sometimes routing should not be exclusive. Instead of selecting one path, you want all matching paths to run.

Example

import graphk


multi = graphk.MultiPipe(
    nodes=[
        (graphk.Matcher(group="alpha"), graphk.SequencePipe(nodes=[graphk.demo.IncrementNode("A", target_key="counter", order_key="executed", response=True, response_key="response")])),
        (graphk.Matcher(group="alpha"), graphk.SequencePipe(nodes=[graphk.demo.IncrementNode("B", target_key="counter", order_key="executed", response=True, response_key="response")])),
        (graphk.Matcher(group="beta"), graphk.SequencePipe(nodes=[graphk.demo.IncrementNode("C", target_key="counter", order_key="executed", response=True, response_key="response")])),
    ],
)

program = graphk.Program(
    {"fanout": graphk.SequencePipe(nodes=[multi])}
)
emitter = graphk.Emitter(program)

emitter.request("fanout", graphk.Session(group="alpha"))
print(emitter.response())

What Happens?

  • GraphK resolves the fanout pipeline from the program
  • GraphK resolves all matching branches
  • the selected branches are ordered
  • every selected branch executes

Why This Example Matters

This is GraphK’s cumulative-routing or fan-out pattern.

Run The Full Example

Clone this wiki locally