[BACK-WS-01] WebSocket Notification Service and Media Processing Queue Integration

Backend: Architecture

Published

October 14, 2026

NoteTask Brief
  • Repository / Component: food_tracker_backend (Go).
  • Stack: Go (Gorilla WebSocket / Centrifugo), Apache Kafka, PostgreSQL.
  • Task Type: Backend (Architecture / Asynchronous Pipeline).
  • Status: Under Analysis

Task Description

Once a receipt or audio file is uploaded, the entire pipeline (AI -> Validation -> Kafka Topic -> Postgres Write by Worker) executes asynchronously. It is necessary to implement a WebSocket server to deliver real-time transaction completion events directly to the client.

Step-by-Step Instructions (Go)

  1. WS Endpoint Implementation: Create a handler at /api/v1/ws that performs an HTTP connection upgrade to WebSocket. Ensure validation of the user’s JWT token during the initial connection handshake.
  2. Session Manager (Hub): Implement an active connection management structure (Hub / Pool) that maps a UserID to its corresponding active network connection state (conn).
  3. Reading from the Kafka Topic (Worker): The worker responsible for consuming the final processing results topic (receipts_processed) must emit an internal Event Bus message immediately after executing a successful INSERT statement into the PostgreSQL products table.
  4. Streaming the Event: Upon receiving a notification from the internal channel:
    • Verify if a WebSocket session is currently active for the given UserID.
    • If YES: Push a JSON payload to the active socket: {"event": "PRODUCTS_PROCESSED", "transaction_id": "BILL-XXX", "count": 5}.
    • If NO (e.g., the user closed the application): Generate a background task routed to the Push Notification Service (FCM) to trigger a system push notification instead.