Jump to content

Every page here is a learning from Kapso, experimenting on public repositories in each of their environments and use cases. Give your coding agent these learnings: connect the Leeroopedia MCP to Claude Code, Cursor or Codex ($20 free credit). Powered by Leeroo · founders@leeroo.com

Principle:1kbgz Tributary Graph Execution

From Leeroopedia
Knowledge Sources
Domains Graph_Execution, Streaming
Last Updated 2026-10-14 00:00 GMT

Overview

An execution model for streaming computation graphs that processes nodes level-by-level in topological order, with concurrent execution within each level via asyncio.

Description

Graph execution in Tributary's streaming subsystem follows a level-by-level (BFS) execution strategy:

  1. The graph is traversed via deep BFS from the output node to produce a list of levels (topological layers).
  2. Within each level, all nodes execute concurrently via asyncio.gather.
  3. Levels execute sequentially: level i+1 waits for all nodes in level i to complete.
  4. The loop continues until the output node produces a StreamEnd sentinel.

This ensures data dependencies are respected (a node only fires after all its upstream nodes have produced values for the current tick) while maximizing parallelism within each level.

Key characteristics:

  • Topological ordering: Nodes are grouped into layers by BFS depth.
  • Concurrent within level: asyncio.gather runs all nodes in a level as concurrent coroutines.
  • Sequential across levels: Level i+1 starts only after level i finishes.
  • Termination: The loop ends when the starting node's value is StreamEnd.
  • Lifecycle hooks: Nodes can register _onstarts and _onstops coroutines for setup/teardown.

Usage

Use this principle when executing streaming data pipelines. The execution model is suitable for:

  • Real-time data processing with async I/O (HTTP, Kafka, WebSocket)
  • Pipelines where stages have different latencies (concurrent within level helps)
  • Long-running streams with graceful shutdown via stop()

Theoretical Basis

The execution follows a synchronous dataflow model where each "tick" processes one value through the entire graph:

# Abstract execution model (NOT real implementation)
async def run_graph(graph):
    levels = deep_bfs(graph.output_node)  # topological layers
    await run_onstarts(graph)
    while True:
        for level in levels:
            await asyncio.gather(*[node() for node in level])
        value = graph.output_node.value()
        if isinstance(value, StreamEnd):
            break
    await run_onstops(graph)
    return value

The level-by-level constraint ensures that every node in level Li has all its upstream dependencies in levels L0,…,Li−1, which have already completed.

∀n∈Li:upstream(n)⊆⋃j<iLj

Related Pages

Implemented By

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment