Portal Community

EdgeStream Topic Architecture

Each user has a dedicated EdgeStream topic for notifications: notifications.{userId}. When WorkDesk's NotificationService creates a notification for a user, it publishes the event payload to this topic. The user's connected browser session receives it immediately.

// Topic naming pattern
notifications.usr-001     // user usr-001's notification topic
notifications.usr-002     // user usr-002's notification topic
// ... fully isolated per user

Subscription Lifecycle

1

User Logs In

WorkDesk authenticates via Passport and receives a JWT. The JWT contains the user's userId.

2

WorkDesk Shell Subscribes

The WorkDeskShell component subscribes to notifications.{userId} and tasks.{userId} EdgeStream topics on mount.

3

Connection Maintained

EdgeStream maintains a persistent WebSocket or SSE connection. If the connection drops, the EdgeStream client reconnects automatically and re-subscribes.

4

Events Received in Real Time

Notifications published to the topic arrive via the subscription callback. The Zustand notification store is updated, triggering a React re-render of the bell badge and notification panel.

React Subscription Code

import { useSubscription } from '@bizfirstai/edge-stream-react';
import { useNotificationStore } from '../stores/notificationStore';

// WorkDeskShell — subscribes once on mount
export function WorkDeskShell({ children }: { children: React.ReactNode }) {
  const userId = useCurrentUser().id;
  const { addNotification, incrementUnread } = useNotificationStore();

  // Subscribe to user's notification topic
  useSubscription(`notifications.${userId}`, (event: EdgeStreamEvent) => {
    const notification: Notification = {
      id: event.payload.notificationId,
      type: event.payload.type,
      title: event.payload.title,
      body: event.payload.body,
      priority: event.payload.priority,
      linkedUrl: event.payload.linkedUrl,
      createdAt: event.payload.createdAt,
      isRead: false,
    };
    addNotification(notification);
    incrementUnread();

    // Show browser toast for high-priority notifications
    if (event.payload.priority === 'urgent' || event.payload.priority === 'high') {
      showToast(notification);
    }
  });

  return <div className="workdesk-shell">{children}</div>;
}

EdgeStream Event Payload

// Full notification event payload from EdgeStream
interface NotificationEvent {
  notificationId: string;        // unique notification ID
  type: 'hil_task_assigned'
      | 'workflow_completed'
      | 'hil_task_overdue'
      | 'system_alert';
  title: string;                 // short notification title
  body: string;                  // full notification body text
  priority: 'low' | 'normal' | 'high' | 'urgent';
  linkedUrl: string;             // deep-link to the relevant resource
  createdAt: string;             // ISO 8601 UTC
  metadata: {
    taskId?: string;
    executionId?: string;
    workflowName?: string;
    workflowId?: string;
  };
}

Reconnection and Missed Events

If the browser session is closed and reopened (e.g., employee shuts laptop and returns the next day), EdgeStream's reconnection window may not replay missed events. WorkDesk handles this by loading recent unread notifications from the REST API on every session start, ensuring no notifications are missed even after a disconnection.

// On session start — load recent unread notifications from API
// (in case EdgeStream missed events while offline)
GET /api/workdesk/notifications?isRead=false&limit=50&sortBy=createdAt&sortDir=desc
Zero Polling Guarantee

Once the EdgeStream subscription is established, WorkDesk never polls for notifications. All subsequent updates arrive via push. The initial REST load on session start is the only non-push operation in the notification system.