Skip to content

Write the CQRS Projection Engine for Health Scores #25

Description

@SHAURYASANYAL3

🛑 The Problem

Currently, we calculate the complex mathematical Health Score (variance, standard deviations, time decay) on-the-fly when the user loads the dashboard. This is incredibly slow and CPU intensive. We need to separate the Write operations (ingesting commits) from the Read operations (viewing the score) using the CQRS pattern.

💡 The Solution

Build an offline Projection Engine. When commits are ingested, a background worker should calculate the score once and save it to a flat, highly-optimized read table.

🛠️ Implementation Details

  1. Create a new Inngest event: analytics.calculate_health.
  2. Create a worker that listens for this event.
  3. When triggered, the worker fetches all necessary raw data from the DB, runs the heavy math algorithms, and generates the final JSON payload.
  4. Upsert this payload into the health_snapshots table.
  5. The frontend Next.js app should ONLY ever read from health_snapshots with a simple SELECT * WHERE repo_id = X limit 1.

✅ Acceptance Criteria

  • Dashboard load time drops to < 50ms.
  • Heavy math is executed asynchronously in the background, never blocking the main web thread.

Ready to tackle this? Comment .take below to get automatically assigned!

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions