Skip to content

Performance: Stream review results via SSE instead of polling #84

Description

@tailorgunjan93

Performance: Replace Polling with Streaming (SSE)

Problem

The current review flow uses ReviewPoll() — a polling loop that repeatedly
hits the LiveReview backend until results are ready. This creates:

  • Perceived latency (user stares at a spinner)
  • Unnecessary HTTP round-trips
  • Delayed inline comments (all arrive at once)

Proposed Solution

Switch to Server-Sent Events (SSE) for streaming inline comments
as the AI generates them — similar to how ChatGPT streams responses.

User Experience Difference

Current:  [spinner 8 seconds] → all 5 comments appear at once
Streaming: comment 1 appears → comment 2 → comment 3 → (feels instant)

Implementation Approach

Backend — LiveReview API adds an SSE endpoint:

GET /api/v1/diff-review/stream?review_id=xyz
Content-Type: text/event-stream

data: {"line": 12, "file": "main.go", "comment": "Possible nil dereference"}
data: {"line": 34, "file": "auth.go", "comment": "Leaked credential pattern"}
data: {"status": "complete", "coverage": 85}

CLI — Replace ReviewPoll() loop with SSE client:

// net/http SSE reader in Go is straightforward
resp, _ := http.Get(streamURL)
scanner := bufio.NewScanner(resp.Body)
for scanner.Scan() {
    line := scanner.Text()
    // parse and forward to UI
}

Browser UI — Already JS-based, EventSource API is native:

const es = new EventSource(streamURL);
es.onmessage = (e) => renderComment(JSON.parse(e.data));

Benefits

  • Feels 3-5x faster to the user (same total time, better perceived speed)
  • Reduces server load (one connection vs. N polls)
  • Comments render progressively — user can start reading while AI continues

Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions