By Abhijith N M · Reviewed 24 October 2026 · Editorial standards
One of LangGraph's best features is also the one that surprises people first: if two nodes run in the same superstep and both write the same state key, the runtime does not guess. With the default channel it raises InvalidUpdateError. That is deliberate — a silent winner would make a race condition look like a feature. When parallel writers are legitimate, you say so with a reducer.
A reducer is a function attached to a state key with Annotated. It receives the current value and the incoming update and returns the new value. add_messages is a reducer; operator.add is a reducer; any pure (left, right) -> merged function can be one. Assign the reducer to the key once, and every writer in the graph gets the same merge rule.
The classic pattern is fan-out/fan-in. One node fans work out to several independent branches, each branch writes its own piece of the answer into a shared reduced list, and a single merge node runs once after every branch finishes — the fan-in barrier. The merge node sees the combined list because of the reducer, and it does not care which branch finished first.
from operator import add
from typing import Annotated, TypedDict
from langgraph.graph import END, START, StateGraph
class ResearchState(TypedDict):
topic: str
findings: Annotated[list[str], add]
summary: str | None
def research_a(state: ResearchState) -> dict:
return {"findings": [f"a:{state['topic']}"]}
def research_b(state: ResearchState) -> dict:
return {"findings": [f"b:{state['topic']}"]}
def synthesize(state: ResearchState) -> dict:
return {"summary": f"{len(state['findings'])} findings merged"}
builder = StateGraph(ResearchState)
builder.add_node("research_a", research_a)
builder.add_node("research_b", research_b)
builder.add_node("synthesize", synthesize)
builder.add_edge(START, "research_a")
builder.add_edge(START, "research_b")
builder.add_edge("research_a", "synthesize")
builder.add_edge("research_b", "synthesize")
builder.add_edge("synthesize", END)
graph = builder.compile()
result = graph.invoke({"topic": "refunds", "findings": [], "summary": None})
print(sorted(result["findings"]))
print(result["summary"])A custom reducer is an ordinary function. It must be pure and it should merge, not mutate. This one adds counts per key instead of letting a second writer replace the whole dictionary:
from typing import Annotated, TypedDict
def merge_counts(left: dict[str, int], right: dict[str, int]) -> dict[str, int]:
"""A reducer that adds counts instead of replacing the whole dict."""
merged = dict(left)
for key, value in right.items():
merged[key] = merged.get(key, 0) + value
return merged
class MetricsState(TypedDict):
counts: Annotated[dict[str, int], merge_counts]Key takeaways
Parallel writes to one plain key raise InvalidUpdateError; reducers are how you opt into merging.
Attach a reducer to a key with Annotated, e.g. Annotated[list[str], add] or add_messages for messages.
Fan-out is two edges out of one node; fan-in is edges converging on a node that runs once after all branches.
Do not depend on parallel write order — sort or aggregate in the merge node, and keep writes idempotent.
Written and edited by the nexGenCoders team. Spotted a mistake? Tell us and we will fix it.
Don't lose this lesson
Create a free account to save your progress, keep your streak, and work toward a shareable certificate.