Skip to content

feat: Add WebSocket support for real-time TUI updates #679

Description

@stormcat24

Summary

Add WebSocket support to enable real-time updates in the TUI, eliminating delays when resources are created, updated, or deleted.

Current Problem

Currently, the TUI polls for updates every 5 seconds, which causes noticeable delays:

  • When a cluster is created, it takes up to 10-30 seconds to appear in the TUI
  • Task status changes are not reflected immediately
  • Service deployments don't show up right away

This creates a poor user experience where users have to wait or manually refresh to see their changes.

Root Causes of Delays

  1. TUI polling interval: 5 seconds (in internal/tui/model.go)
  2. Batch update delay: 2 seconds (sync controller's BatchUpdater)
  3. Initial pod processing delay: 3 seconds (processExistingPods sleep)

Proposed Solution

Implement WebSocket-based real-time notifications:

Architecture

  1. WebSocket Server

    • Add WebSocket endpoint to the admin server (port 5374)
    • Path: /ws/events or similar
    • Broadcast events for resource changes (clusters, services, tasks, etc.)
  2. Event Types

    type Event struct {
        Type      string    // "cluster.created", "task.updated", etc.
        Resource  string    // Resource ARN
        Data      interface{} // Resource data
        Timestamp time.Time
    }
  3. TUI WebSocket Client

    • Connect to WebSocket on startup
    • Handle reconnection logic
    • Update local state immediately when events are received
    • Fall back to polling if WebSocket is unavailable

Implementation Areas

  • Add WebSocket handler to admin server (internal/controlplane/admin/)
  • Create event broadcaster/hub for managing connections
  • Emit events from API handlers (CreateCluster, CreateService, etc.)
  • Add WebSocket client to TUI (internal/tui/)
  • Handle WebSocket messages in TUI update loop
  • Implement reconnection logic with exponential backoff
  • Add feature flag to enable/disable WebSocket mode

Benefits

  • Immediate feedback: Resources appear instantly after creation
  • Reduced server load: Less frequent polling required
  • Better UX: Real-time updates for all resource changes
  • Foundation for future features: Live logs, metrics, etc.

Alternative Short-term Solutions

While this is being implemented, we can:

  1. Reduce TUI polling interval from 5s to 2s
  2. Add immediate refresh after create/update operations in TUI
  3. Add manual refresh command (e.g., Ctrl+R)

Related Issues

  • Could also benefit from GraphQL subscriptions as an alternative
  • Would enable real-time log streaming in the future

Technical Considerations

  • Use gorilla/websocket (already in dependencies)
  • Consider using a message queue for reliability
  • Implement proper connection pooling and cleanup
  • Add metrics for WebSocket connections

Acceptance Criteria

  • TUI connects to WebSocket on startup
  • Resources appear in TUI within 100ms of creation
  • Graceful fallback to polling if WebSocket fails
  • No memory leaks from connection management
  • Works across all supported platforms

Priority

Medium - This is a quality of life improvement that would significantly enhance the user experience, but the current polling mechanism is functional.

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions