Skip to content

Count-Based Windows #466

@bolshakov

Description

@bolshakov

Currently, Stoplight only supports time-based windows (window_size: 60 evaluates errors within the last 60 seconds). This approach has limitations for certain traffic patterns:

  • High-traffic services: A service receiving 1000 requests/second cares more about "last 500 requests" than "last 5 seconds" - request volume could be a better signal than elapsed time.
  • Variable traffic: Services with uneven traffic (e.g., batch processing, cron jobs) need windows that adapt to actual request volume rather than wall-clock time.

Proposed Solution

Introduce count-based windows that track the last N requests instead of the last N seconds. This provides a volume-based alternative to time-based windowing. Something like:

Stoplight("api", window_count: 100, threshold: 5)

Count-based windows can be implemented using circular buffers, making them extremely memory and performance-efficient - O(1) writes and bounded memory regardless of traffic volume.

Value Proposition

  • Predictable memory usage: fixed-size buffer regardless of time or traffic
  • Performance: Circular buffer enables O(1) operations
  • Better signal for variable traffic

Open Questions

  • API design: How should count-based and time-based windows coexist? Mutually exclusive or combinable?
  • Should there be recommended/enforced maximum window counts?
  • How do count-based windows interact with different traffic control strategies?
  • Data store compatibility: Memory vs Redis implementation differences?
  • Migration: how to switch between window types?
  • Admin Panel: How to visualize count-based vs time-based windows?

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions