Why does composing two LCEL Runnables with `|` give you batch and streaming for free?
Every LCEL Runnable implements four execution methods; piping them produces a Runnable whose four methods derive from the underlying steps. No magic, just interface composition.
Picture a relay race where every runner trains to do four things: walk, sprint, batch-sprint with a teammate, and stream messages while running. When you string four such runners together as a team, the team also walks, sprints, batch-sprints, and streams messages, because each member knows how. Nobody had to invent a new kind of running for the team. That is how LCEL chains work: each step promises four execution shapes, and the chain inherits them for free by handing the work step by step.
Detailed answer & concept explanation~5 min readEverything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example. Click to expand.
Everything you need to truly understand this topic: intuition, mechanics, step by step explanation, code, formulas, and worked example.
Everything important, quickly.
Name the four Runnable methods, explain that `|` returns a RunnableSequence whose methods delegate per-step, debunk the magic (no compile, no cache, no JIT), call out the weakest-link consequence, mention per-step batch concurrency, and finish with where to apply retry/fallback.
Real products, models, and research that use this idea.
- The default LangChain chat-completion chain `prompt | ChatAnthropic() | StrOutputParser()` streams Claude Sonnet 4.6 tokens through the parser because all three steps implement `.stream` faithfully.
- Vercel AI SDK's React `useChat` hook consumes the chain's `.astream` to drive a token by token UI, the same chain serves `.invoke` from a server-side handler.
- LangChain's `RunnableParallel` shows the same contract for fan-out: `{"a": chain_a, "b": chain_b}` is a Runnable whose `.invoke` invokes both in parallel and returns a dict.
- Open-source production deployments commonly wrap third-party tools as Runnables (`RunnableLambda(fn)`), the wrapping adds the four-method interface so the tool plugs cleanly into the chain.
What an interviewer would ask next. Try answering before peeking at the approach.
QWalk through what happens when one step in a chain implements only `.invoke` and the user calls `chain.stream(x)`.
QHow does `RunnableParallel` differ from `RunnableSequence`, and what's the interface contract for each?
Don't say thisRed flags and common mistakes that signal junior thinking. Click to expand.
Red flags and common mistakes that signal junior thinking. Click to expand.
Believing LCEL does compilation, caching, or implicit parallelism. The pipe operator is plain interface composition: methods on the chain call methods on each step.
The night-before-the-interview bullets. Scan these on the way to the call.
Primary sources. Skim if you want the original framing.
Same topic, related formats. Practice these next.