Skip to content

Conversation

@vchurbanov
Copy link
Contributor

Summary

This PR adds cursor-based pagination for events, designed for a dynamic event stream where new events may continuously appear.

The API is intended for practical frontend usage with infinite scrolling and avoids issues typical for offset-based pagination (duplicates, gaps, unstable ordering).


Pagination approach

Instead of offsets, the API uses a composite cursor based on the last item of the previous page.

Each page response returns:

{
  "limit": 25,
  "has_more": true,
  "next_cursor": "base64(...)"
}

The next_cursor encodes a (timestamp, uuid) pair.
On the next request, the server returns events strictly after this pair, ordered by:

(timestamp, uuid)

This guarantees stable ordering and deterministic pagination, even when timestamps are equal.

The cursor is transferred as Base64 for simplicity and to prevent client-side modification.


Server-side changes

  • Extended /api/events and /api/events/preview with cursor-based pagination
    (backward compatibility preserved)
  • Added /api/events/type-counts endpoint to return the current number of events per type
  • Implemented ordering by timestamp; since the column is stored as string, casting is used:
    CAST(timestamp AS DECIMAL(20,6))
  • Added API documentation and tests for new and updated endpoints
  • Removed the previous hard limit of 100 events — events can now be loaded dynamically

Result

The server now provides a stable and scalable pagination mechanism suitable for infinite scrolling and large, continuously growing event streams.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant