File: /src/gateway/stream.rs
Category: Gateway / Streaming
Description: The BackpressureFilter uses a fixed-capacity mpsc channel. When a utility infrastructure event causes a sudden spike (e.g., 500K meters reporting simultaneously after a brownout recovery), the channel saturates and begins dropping events silently. There is no adaptive backpressure mechanism, no priority queuing for critical events (over-voltage alerts vs routine readings), and no spill-to-disk strategy.
Parameters:
- Normal throughput: 10,000 events/sec
- Spike throughput: 500,000 events/sec
- Critical event priority: alerts delivered within 100ms regardless of queue depth
- Memory budget: 512MB max for event buffers
Codebase Navigation:
src/gateway/stream.rs:14 — BackpressureFilter::new — fixed buffer_capacity is the limitation
src/gateway/stream.rs:28 — push — silent drop on channel full
Resolution Blueprint:
- Implement a multi-level priority queue (critical/high/normal/low) using a custom binary heap with priority ordering
- Add adaptive buffer sizing: dynamically grow buffer up to 512MB during spikes, shrink during quiescence
- Implement spill-to-disk using a memory-mapped ring buffer for overflow events when memory budget exceeded
- Add a
DrainTask that asynchronously flushes spilled events back into the processing pipeline
- Expose
GET /api/v1/gateway/backpressure returning current buffer utilization, spill count, and priority distribution
Acceptance Criteria:
File:
/src/gateway/stream.rsCategory: Gateway / Streaming
Description: The
BackpressureFilteruses a fixed-capacity mpsc channel. When a utility infrastructure event causes a sudden spike (e.g., 500K meters reporting simultaneously after a brownout recovery), the channel saturates and begins dropping events silently. There is no adaptive backpressure mechanism, no priority queuing for critical events (over-voltage alerts vs routine readings), and no spill-to-disk strategy.Parameters:
Codebase Navigation:
src/gateway/stream.rs:14—BackpressureFilter::new— fixedbuffer_capacityis the limitationsrc/gateway/stream.rs:28—push— silent drop on channel fullResolution Blueprint:
DrainTaskthat asynchronously flushes spilled events back into the processing pipelineGET /api/v1/gateway/backpressurereturning current buffer utilization, spill count, and priority distributionAcceptance Criteria: