Skip to main content
The Cosmo Router includes two layers of request deduplication to avoid redundant work when multiple concurrent requests resolve to identical subgraph fetches.

Layer 1: Subgraph Request Deduplication

Deduplicates identical fetches to the same subgraph across concurrent operations. The deduplication key is:
  • DataSourceID: identifies the target subgraph
  • requestBody: the complete JSON payload (query + variables)
  • preComputedHeaderHash: xxhash64 of all headers that will be forwarded to this subgraph, as determined by your header forwarding rules
Only Query operations are eligible. Mutations and subscriptions are never deduplicated.

Layer 2: Inbound Request Deduplication

Deduplicates identical client requests before the engine even starts resolving. The key is:
If two concurrent clients send the same query with the same variables and the same forwarded headers, only one resolution is performed and the result is shared.

How Header Hashes Are Computed

The header hashes for both layers are computed by SubgraphHeadersBuilder, which:
  1. Iterates over every subgraph involved in the execution plan
  2. Applies all configured header forwarding rules (global + per-subgraph) against the current inbound request headers
  3. Produces a deterministic uint64 hash per subgraph
  4. Combines all per-subgraph hashes into a single allHash
This happens after RouterOnRequestHandler and RouterMiddlewareHandler hooks run, but before EnginePreOriginHandler.OnOriginRequest hooks run.

Request Pipeline and Hook Ordering

Configuration Reference

Environment variable equivalents:
  • ENGINE_ENABLE_SINGLE_FLIGHT
  • ENGINE_FORCE_ENABLE_SINGLE_FLIGHT
  • ENGINE_ENABLE_INBOUND_REQUEST_DEDUPLICATION
  • ENGINE_FORCE_ENABLE_INBOUND_REQUEST_DEDUPLICATION