Skip to content

Issue 4: High-Throughput Tokenized Meter Event Streaming Backpressure Filter #4

Description

@elizabetheonoja-art

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:

  1. src/gateway/stream.rs:14BackpressureFilter::new — fixed buffer_capacity is the limitation
  2. src/gateway/stream.rs:28push — silent drop on channel full

Resolution Blueprint:

  1. Implement a multi-level priority queue (critical/high/normal/low) using a custom binary heap with priority ordering
  2. Add adaptive buffer sizing: dynamically grow buffer up to 512MB during spikes, shrink during quiescence
  3. Implement spill-to-disk using a memory-mapped ring buffer for overflow events when memory budget exceeded
  4. Add a DrainTask that asynchronously flushes spilled events back into the processing pipeline
  5. Expose GET /api/v1/gateway/backpressure returning current buffer utilization, spill count, and priority distribution

Acceptance Criteria:

  • Zero critical events dropped under 500K/sec spike
  • Adaptive buffer grows/shrinks within 512MB budget
  • Spill-to-disk recovers all overflow events within 5 seconds of spike subsiding
  • Integration test validates priority delivery during saturation

Metadata

Metadata

Assignees

Labels

GrantFox OSSIssue tracked in GrantFox OSSMaybe RewardedIssue may be eligible for a GrantFox rewardOfficial CampaignCampaign: Official CampaignenhancementNew feature or requesthardcoreHardcore structural/system-level challengestructuralArchitectural or structural concern

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions