Distributed Graph Orchestration: Combining Local and Remote Graphs
This article explains how distributed graph orchestration works by combining a local graph with a remote graph. Using a looping math engine as the example, it covers the motivation for splitting graphs, the division of responsibilities between the control plane and the compute plane, how to build a remote graph service with conditional routing, how to implement the local orchestrator, and the trade-offs between sequential and parallel remote calls. It also outlines authentication and production concerns such as observability, scaling, timeouts, and version compatibility. Readers will learn the core design points needed to build a clear, observable, and scalable distributed orchestration system.
Distributed Graph Orchestration: Combining Local and Remote Graphs
1. Why Split a Graph in the First Place
As an agent’s business logic keeps growing, cramming every node into a single graph quickly creates three problems. First, change coupling: even a small modification forces a full redeployment. Second, resource profile conflicts: lightweight flow-control nodes end up sharing the same runtime as compute-heavy nodes. Third, an oversized failure domain: a single misbehaving node can bring down the entire chain.
A common industry response is to split the logic by responsibility into multiple independent services, then schedule them through a lightweight orchestration layer. In the graph-based orchestration paradigm, this split maps to a combination of a “local graph + remote graph”: the local graph handles only flow control and state aggregation, while the remote graph carries the actual computation. The clearer the boundary between the two, the better the system’s maintainability and scalability.
This article uses a “looping math engine” as a complete demonstration of this combination mechanism: in each iteration, the local orchestration graph calls the remote graph twice, once to obtain a random operation type and once to obtain a random operand. It performs the operation and continues looping until the remote graph returns the termination marker end.
2. Architecture Overview and Responsibility Split
The system is divided into two deployment units:
- Remote graph service (math_service): exposes a graph externally and performs conditional routing based on the
actionfield in the input.pick_operationreturns a random math operation or a termination marker;generate_numberreturns a random integer. - Local orchestration graph (math_orchestrator): receives an initial number, calls the remote graph twice per iteration (each with a different
action), performs the operation, and terminates when it encountersend.
The orchestrator comes in two implementations for comparison:
- Sequential flow: the two remote calls happen one after another. This is more natural when the second round depends on the first round’s result; the chain is intuitive and easy to debug, but latency adds up.
- Parallel flow: uses a fan-out/fan-in pattern to issue both calls at the same time. When the branches are independent of each other, this significantly reduces total latency, at the cost of more complex state-merging logic.
It is worth emphasizing that both graphs run in the local development environment: the remote graph runs on a development server, and the local graph runs as an ordinary script. This is exactly the value of the remote graph mechanism: zero-cost integration during development, and in production you only need to swap in the remote address.
3. Step 1: Build the Remote Graph Service
The remote graph uses conditional routing to handle two kinds of operations within a single graph, avoiding a separate graph for each capability. The state is defined as follows:
from typing import TypedDictclass MathServiceState(TypedDict):action: str # "pick_operation" or "generate_number"operation: str # Result: add/subtract/multiply/divide/endnumber: int # Result: random integermanual_input_chance: float # Probability of requesting manual input (0.0-1.0)ask_user: bool # Result: True means the orchestrator should prompt the user
A suggested directory structure is:
math_service/├── auth.py├── graph.py├── langgraph.json└── .env
In graph.py, the flow enters a conditional routing node via START, branches to the corresponding compute node based on action, and then converges to END. This “single graph, multiple operations” design reduces the number of deployment objects while keeping the logic within each branch cohesive.
For the engineering environment, it is recommended to manage dependencies with uv, declare the three packages langgraph, langgraph-cli, and langgraph-sdk in pyproject.toml, and pin the Python version to 3.13. The reason is that some data validation libraries have not yet fully adapted to version 3.14 and above, and pinning the version avoids incompatibilities when resolving dependencies.
4. Step 2: Implement the Local Orchestration Graph
The core of the local graph is the “loop + termination condition”. The pseudocode is as follows:
from langgraph.graph import StateGraph, START, ENDdef loop(state):op = remote.invoke({"action": "pick_operation"})if op["operation"] == "end":return {"result": state["value"], "done": True}n = remote.invoke({"action": "generate_number"})value = apply(state["value"], op["operation"], n["number"])return {"value": value, "done": False}
Key design points:
- The remote side owns the termination condition: whether to stop depends on the
operationreturned by the remote graph; the orchestrator does not preset a maximum number of rounds (a fallback cap can be added in production to prevent infinite loops). - Separation of state responsibilities: the remote graph only answers “what to do and which number to use”, while the local graph holds the accumulated value and flow state.
- Human-in-the-loop hook: the remote graph can request manual input through
ask_userandmanual_input_chance, and the orchestrator pauses and prompts accordingly. This suits scenarios that require review or additional information.
5. Choosing Between Sequential and Parallel
| Dimension | Sequential Flow | Parallel Flow |
|---|---|---|
| Latency | Sum of the two calls | Maximum of the two |
| State Merging | Not needed | Merge required after fan-in |
| Debugging Difficulty | Low | Medium |
| Applicable Scenario | Branches have dependencies | Branches are independent |
Practical advice: use the sequential flow by default to ensure explainability; switch to parallel only when remote call latency becomes a bottleneck and the branches have no dependencies, and pair it with timeout and retry strategies.
6. Authentication and Production Readiness
A remote graph service usually needs token validation wired in through auth.py, with secrets kept in .env and never hardcoded. Production readiness also requires attention to:
- Observability: combine logging services with monitoring and alerting, and record metrics such as latency and failure rate for each remote call.
- Elasticity and scaling: the remote graph can be deployed on a container platform and scaled up or down by load, while the local orchestrator stays stateless for horizontal scaling.
- Timeouts and circuit breaking: set timeouts, retries, and circuit breakers for remote calls to prevent local failures from spreading.
- Version compatibility: changes to the remote graph interface must remain backward compatible, and version numbers of the orchestrator and the remote graph must be managed together.
7. Summary
Combining a local graph with a remote graph is essentially about decoupling the “control plane” from the “compute plane”. The control plane is lightweight and changes frequently, making it suitable for fast local iteration; the compute plane is heavy and resource-sensitive, making it suitable for independent deployment and scaling. Mastering these four things—conditional routing, division of state responsibilities, the sequential/parallel trade-off, and termination condition design—is enough to build a distributed orchestration system with clear boundaries that is observable and scalable.
