Skip to content

witomlin/real-time-sliding-window

Repository files navigation

real-time-sliding-window

License

Real-time sliding window implementations for Kotlin. Supports adding data defined by one or more arbitrary classes and offers various methods for data retrieval.

Features

  • Customizable window settings.
  • Supports adding data from multiple arbitrary classes per window.
  • Allows adding and retrieving data through various methods, including event-based.
  • Fully thread-safe operation.
  • Easy integration through SLF4J for logging and Micrometer for metrics.

Implementations

Two window implementations are available:

Both implementations operate upon a bucketed approach whereby data is grouped into fixed-length time-based buckets, although entire window data can be acted upon if desired.

Comparison Point Fixed Tumbling On Demand
Window length Configurable Configurable
Bucket length Fixed Configurable
Bucket types Tumbling Tumbling1
Multiple data class support Yes Yes
Precision Approximate Precise
Availability of added window data When current bucket ends Immediately after adding
Data retrieval methods Arbitrary, event-based Arbitrary
Data retrieval cost Trivial Non-trivial2

1 Support for additional types will be added in the future.
2 Depending on several factors.

Fixed Tumbling Bucketed Window

Usage

The window comprises a number of fixed-length time buckets, which are designated either current or non-current. Data is only added to the current bucket, and the data is timestamped when added. When the current bucket ends, it is then reclassified as non-current and a new current bucket takes its place in front of it.

As each current bucket ends, the window will increase in length until it reaches its configured length. After this point, the oldest non-current bucket is removed from the window to maintain its configured length.

The window length is the collection of all non-current buckets and does not include the current bucket.

Current buckets (only) allow adding data to the window. Non-current buckets are immutable.

On Demand Bucketed Window

Usage

The window comprises a timestamp-ordered collection of data items. Data is appended to the end of collection when added. Maintenance occurs at regular intervals to remove data items older than the window length.

A tumbling bucketed view of the data in the window is available on demand. The view's start point within the window, length and bucket length are configurable.

Getting Started

Requires:

  • Kotlin 1.8+
  • Java 11+

Add a dependency to your build tool configuration. See CHANGELOG.md for available versions.

Gradle

implementation 'io.github.witomlin:real-time-sliding-window:${realTimeSlidingWindowVersion}'

Gradle (Kotlin DSL)

implementation("io.github.witomlin:real-time-sliding-window:${realTimeSlidingWindowVersion}")

Maven

<dependency>
  <groupId>io.github.witomlin</groupId>
  <artifactId>real-time-sliding-window</artifactId>
  <version>${realTimeSlidingWindowVersion}</version>
</dependency>

About

Real-time sliding window implementations for Kotlin.

Resources

License

Code of conduct

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages