Add FetchStreamStatePlan + FetchStreamPlan: raw event stream fetches as batchable query plans - #5043
Merged
jeremydmiller merged 1 commit intoJul 26, 2026
Conversation
…as batchable query plans Concrete IQueryPlan<T>/IBatchQueryPlan<T> implementations wrapping Events.FetchStreamState and Events.FetchStream, supporting both Guid and string stream identity and FetchStream's optional version/timestamp/ fromVersion filters, so stream fetches can participate in batched queries without hand-rolled adapter plans. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
jeremydmiller
force-pushed
the
fetch-stream-query-plans
branch
from
July 26, 2026 12:15
4010fbe to
6a26157
Compare
This was referenced Jul 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What this adds
Two concrete query plan types in the
Martennamespace — the event-side siblings ofQueryListPlan<T>:FetchStreamStatePlan— fetches a stream'sStreamState?by stream identity (null when the stream does not exist).FetchStreamPlan— fetches a stream's rawIReadOnlyList<IEvent>by stream identity (empty list when the stream does not exist), carryingFetchStream's optionalversion/timestamp/fromVersionarguments through both paths.Both types implement both
IQueryPlan<T>andIBatchQueryPlan<T>, and both support the two stream identity styles (Guid streamId/string streamKey) via constructor overloads, mirroring the overload pairs onIBatchEvents.Why
Wolverine's fetch-specification feature batches any
IBatchQueryPlanreturned from a handler'sLoadinto a single database round trip, andIBatchedQuery.Eventsalready exposesFetchStreamState/FetchStream— but no shipped plan connects the two, so users hand-roll adapter plans per project. There is also a footgun in doing that: a hand-rolled plan implementing onlyIBatchQueryPlan<T>(withoutIQueryPlan<T>) produces uncompilable generated code through Wolverine. Shipping the pair with both interfaces implemented removes both the boilerplate and the trap.Downstream we measured the batching at −38% latency / +27% throughput on an endpoint that fetches a stream state plus a second query in one round trip instead of two.
API
String-keyed streams use the
string streamKeyconstructors identically.Test coverage
src/EventSourcingTests/fetching_stream_query_plans.cs(8 tests, all passing, plus the 2 existingDocumentDbTests.Reading.query_planstests re-run green):QueryByPlanAsyncfor both plansCreateBatchQuery+QueryByPlan+ExecuteFetchStreamPlanwith aversioncapThe exemplary tests carry
#region sample_using_fetch_stream_plan/#region sample_fetch_stream_plans_in_batchmarkers.Docs
docs/documents/querying/compiled-queries.md— new "Query Plans for Event Streams" subsection under Query Plans, with both samples (expanded viamdsnippets).docs/events/querying.md— new "Stream Query Plans" section linking the stream fetches to the query plan concept.docs/cSpell.json— addedbatchable.Note to maintainers
If you'd rather not grow the shipped API surface, we're happy to convert this to a documentation-only sample (the two classes moved into the test project and shown in the docs the way
LonghandColorTargetsis today) — say the word and we'll rework the PR.🤖 Generated with Claude Code