DEV Community

Cover image for Almost Real-Time Github Events and Top Scoring Contributors For Today
Trang Le
Trang Le

Posted on

Almost Real-Time Github Events and Top Scoring Contributors For Today

Redis AI Challenge: Beyond the Cache

This is a submission for the Redis AI Challenge: Beyond the Cache.

What I Built

Sometimes cool things happen behind the frontend. This is a suite tool of scheduled tasks and API server.

The scheduled tasks update Github's latest public events to Redis streams every minute and compute Github contributors' score every hour.

The API server exposes the event stream and a list of top 20 highest scoring contributors. The client can consume it while making minimum number of requests to Redis server, thereby reducing latency.

Demo

Public API server endpoints for event stream and top scoring contributors.

API server endpoint for event stream

Requesting event stream through endpoint /event-stream.

API server endpoint for top scoring Github contributors

Request the top 20 highest scoring Github contributors through endpoint /active-contributors?since=today

How I Used Redis 8

The first job is to create a stream of most recent Github events. This is achieved through a scheduled task that fetches Github events from the official Github API. This API is not designed to serve real-time use cases as stated by Github. However, using the low-latency Redis stream and setting the task to run every minute creates a lightweight event log that act almost like real-time stream.

The second task is to rank users by scores since today. You are probably familiar with using Redis's sorted set for ranking. But how do you get the top scores within today?

Create a sorted set for each hour of today, starting from 0 hour to the last hour. For example, if the current time is 2am 2025-08-11, then you will have three sorted sets whose keys are 2025-08-11:00, 2025-08-11:01. Then call ZUNIONSTORE command on these sorted sets, with the destination being 2025-08-11:sum. The hourly data is aggregated from GhArchive so nothing slips through the cracks.

Compute scores since today using sorted set)

This feature is especially extensible thanks to how versatile ZRANGE is. You can add more query parameters to finetune this command to return X lowest scoring contributors or contributors who place 10th to 20th since this week, this month etc.

Further links

Repo for scheduled tasks
Repo for api server

Top comments (0)