[Feature]: Partition-Based Event Processing for Enhanced Subgraph Performance
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 30/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Necesita aclaración
- Estado de actividad
- Estancado
- Stack tecnológico
- rust
- Área
- backend, distributed-systems
Línea de trabajo
Comienza leyendo la ruta existente de procesamiento de eventos de Graph Node y el manejo de los manifiestos de subgraph, centrándote en cómo se programan los controladores de eventos de mapping y cómo se impone el orden. Define las interfaces requeridas de manifiesto y de handler, el comportamiento de concurrencia y consistencia de entidades, y las pruebas que demuestren un procesamiento ordenado dentro de una partición y resultados deterministas entre particiones.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
Description
Summary
Add support for partition-based parallel event processing in Graph Node, allowing events from the same contract to be processed in parallel based on a developer-defined partition key, while maintaining sequential ordering for events with the same partition key.
Motivation
Currently, Graph Node processes events from a single contract sequentially, even when those events are logically independent. This creates significant performance bottlenecks for singleton contracts that manage multiple independent entities - a pattern becoming increasingly common in modern protocols.
The shift from factory patterns to singleton architectures (like Uniswap V4's PoolManager) exacerbates this issue. Where Uniswap V3 could parallelize across different pool contracts, V4 forces sequential processing of all events from all pools because they originate from a single address.
Real-World Example: Uniswap V4
Uniswap V4 uses a singleton PoolManager contract that manages all pools. Every swap, liquidity change, and pool creation flows through this single contract:
eventHandlers:
- event: Initialize(indexed bytes32,indexed address,indexed address,uint24,int24,address,uint160,int24)
handler: handleInitialize
- event: ModifyLiquidity(indexed bytes32,indexed address,int24,int24,int256,bytes32)
handler: handleModifyLiquidity
- event: Swap(indexed bytes32,indexed address,int128,int128,uint160,uint128,int24,uint24)
handler: handleSwap
The first parameter in each event is the PoolId (bytes32). Events for different pools are completely independent - a swap in the ETH/USDC pool has no relationship to a swap in the WBTC/DAI pool. Yet Graph Node must process them sequentially, creating a severe bottleneck as V4 adoption grows.
A single Ethereum block might contain hundreds of swaps across dozens of pools, all waiting in line for sequential processing.
Proposed Solution
Core Feature
Allow subgraph developers to specify a partition key function in their mappings. Events with different partition keys can be processed in parallel, while events with the same partition key maintain sequential ordering.
Configuration Approach
Add partition configuration to the subgraph manifest:
dataSources:
- kind: ethereum/contract
name: PoolManager
source:
address: "0x8C4BcBE6b9eF47855f97E675296FA3F6fafa5F1A"
abi: PoolManager
mapping:
kind: ethereum/events
# NEW: Partition configuration
partitioning:
enabled: true
maxConcurrency: 10 # Optional: limit concurrent partitions
eventHandlers:
- event: Swap(indexed bytes32,indexed address,int128,int128,uint160,uint128,int24,uint24)
handler: handleSwap
# NEW: Partition by the first parameter (PoolId)
partitionBy: event.params.id
- event: ModifyLiquidity(indexed bytes32,indexed address,int24,int24,int256,bytes32)
handler: handleModifyLiquidity
partitionBy: event.params.id
Alternative: Define partition key in the handler code:
export function handleSwap(event: Swap): void {
// Declare partition key at the start of handler
setPartitionKey(event.params.id.toHexString())
// Rest of handler logic remains unchanged
let pool = Pool.load(event.params.id)
// ...
}
Key Requirements
-
Event Ordering Within Partitions
- Events with the same partition key MUST be processed in block order
- Maintains data integrity for entity updates
-
Cross-Partition Independence
- Events with different partition keys can process in parallel
- No shared state between partitions during event processing
-
Backwards Compatibility
- Feature is opt-in with zero breaking changes
- Existing subgraphs continue working exactly as before
-
Deterministic Results
- Parallel processing must produce identical results to sequential processing
- Same inputs always produce same indexed state
Implementation Considerations
Entity Store Consistency
The entity store must handle concurrent updates safely:
- Entities with different IDs can be updated in parallel
- Global aggregations may need atomic operations or partition-aware accumulation
- Consider read-write locks per entity ID
Handler Guidelines
Developers must ensure handlers are partition-safe:
- Avoid global variables that could race
- Entity updates should only affect entities within the partition scope
- Cross-partition queries should be read-only during event processing
Performance Monitoring
Expose metrics for:
- Events processed per second by partition
- Partition distribution (to identify hot partitions)
- Queue depths per partition
- Lock contention statistics
Benefits
1. Massive Performance Improvements
- Linear scalability with number of independent entities
2. Better Resource Utilization
- Utilize multiple CPU cores effectively
- Reduce indexing lag during high activity periods
3. Improved Developer Experience
- Simple configuration without restructuring handler logic
- Maintains the same mental model for entity updates
4. Future-Proof Architecture
- Supports the trend toward singleton patterns
- Scales with blockchain activity growth
Use Cases
DeFi Protocols
- Uniswap V4: Partition by PoolId
- Lending Protocols: Partition by market/asset
- Vault Managers: Partition by vault address
NFT/Gaming
- Marketplace Singletons: Partition by collection
- Game State Managers: Partition by game ID or player
Cross-Chain Bridges
- Message Processors: Partition by chain ID or message ID
Generic Registries
- ENS-style Systems: Partition by domain/namespace
- Token Registries: Partition by token address
Example: Uniswap V4 with Partitioning
dataSources:
- kind: ethereum/contract
name: PoolManager
network: mainnet
source:
address: "0x..."
abi: PoolManager
mapping:
kind: ethereum/events
partitioning:
enabled: true
maxConcurrency: 20
eventHandlers:
- event: Initialize(indexed bytes32,indexed address,indexed address,uint24,int24,address,uint160,int24)
handler: handleInitialize
partitionBy: event.params.id
- event: ModifyLiquidity(indexed bytes32,indexed address,int24,int24,int256,bytes32)
handler: handleModifyLiquidity
partitionBy: event.params.id
- event: Swap(indexed bytes32,indexed address,int128,int128,uint160,uint128,int24,uint24)
handler: handleSwap
partitionBy: event.params.id
- event: Donate(indexed bytes32,indexed address,uint256,uint256)
handler: handleDonate
partitionBy: event.params.id
No changes needed to handler implementations - just configuration enables parallel processing!
Technical Considerations
Partition Key Requirements
- Must be deterministic from event data
- Should distribute events evenly to avoid hot partitions
- Typically corresponds to the primary entity ID being updated
Edge Cases
- New entity creation can safely happen in any partition
- Global statistics may need special handling (atomic counters or post-processing aggregation)
- Time-based calculations within a partition remain correct due to ordered processing
Are you aware of any blockers that must be resolved before implementing this feature? If so, which? Link to any relevant GitHub issues.
No response
Some information to help us out
- Tick this box if you plan on implementing this feature yourself.
- I have searched the issue tracker to make sure this issue is not a duplicate.
- Lenguaje dominante
- Rust
- Estrellas
- 3.2k
- Forks
- 1.1k
- Merge medio
- 4 d 1 h
- PR fusionados (30 d)
- 1
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de graphprotocol/graph-node
-
current: include emits an all-null bucket for dimensionless aggregations, nulling the whole response Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
graphprotocol/graph-node#6719 ·
-
RUSTSEC-2026-0194: Quadratic run time when checking a start tag for duplicate attribute names Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 68/100
graphprotocol/graph-node#6673 ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 70/100
graphprotocol/graph-node#6650 · 1 comentario ·
-
Dificultad 4/5 3-5 días Aptitud para principiantes 48/100
graphprotocol/graph-node#6722 ·
-
Dificultad 3/5 1-2 días Aptitud para principiantes 68/100
graphprotocol/graph-node#6721 ·
Todos los issues de graphprotocol/graph-node
Issues similares
-
risk:low runtime status:in-progress type:test
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
zeroclaw-labs/zeroclaw#11023 ·
-
good first issue refactor
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 84/100
EricSpencer00/Resilient#4835 · 1 comentario ·
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
bisq-network/bisq-musig#204 ·
-
agent:ready documentation
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
cesarferreira/stax#890 ·