A service which ensures that events occur only once in a period of time (event-duration
).
A typical sliding window limiter, allowing only the first of duplicated events during the event-duration
.
Example
Event Duration: 3Times and Events: {1, ๐}, {2, ๐ฎ}, {3, ๐ฎ}, {4, ๐ฎ}, {7, ๐ฎ}
Allowed: {1, ๐}, {2, ๐ฎ}, {7, ๐ฎ}
A sliding window limiter, where if duplicate events occur during the event-duration
, the later event(s) are rejected and the conflicting earlier event is invalidated. In short, at least event-duration
time should separate events, otherwise no events are valid.
Example
Event Duration: 3Times and Events: {1, ๐}, {2, ๐ฎ}, {3, ๐ฎ}, {4, ๐ฎ}, {7, ๐ฎ}
Allowed: {1, ๐}, {7, ๐ฎ}
- Submitted - Potentially publishable at the time of receipt. An event will not be submitted if it conflicts with another, previously submitted event. This is the entry point into the event lifecycle.
- Invalidated - A submitted event is invalidated when a subsequently received event creates a conflict. This is a terminal state transition, an invalidated event can never be published.
- Published - No rate limit rules were violated, for a submitted event, throughout the event duration. This is a terminal state transition, a published event cannot be invalidated.
Event status updates are pushed using STOMP over Websocket. Snapshots of incubating events (events submitted but not yet published) are periodically pushed. Combined, these allow real time synchronization with other services.
All status updates and snapshots are sent with a scalar clock. It is guaranteed that clock values are unique and an event with a lesser clock value happened-before an event with a greater clock value. The state of incubating events can therefore be modeled. A parallel can be drawn to video compression: snapshots can be considered key-frames and status updates, delta-frames.
The synchronization is not partition tolerant.
Requirements: Docker, Docker compose and Java 19 (uses preview features)
Start RateLimiter and Redis: gradle bootRun
Stop Redis: gradle stopRedis