Real-Time Sync
How MCintelligentplus uses SSE and Redis Pub/Sub for instant real-time updates
Real-Time Sync
MCintelligentplus uses Server-Sent Events (SSE) backed by Redis Pub/Sub for real-time data updates. When data changes in the backend (new notification, document processed, chat message, connector sync completed), the backend publishes to Redis and the SSE broker pushes the event to all connected browser clients instantly.
How It Works
- A backend service (FastAPI route or Celery task) writes to PostgreSQL and publishes
an event to a Redis channel (
sse:<user_id>). - The SSE broker (running inside the backend process) receives the Redis message.
- The browser's persistent
EventSourceconnection to/api/v1/sse/eventsreceives the pushed event. - React state updates — no polling, no page refresh.
Architecture
| Component | Role |
|---|---|
| PostgreSQL | Source of truth |
| Redis | Pub/Sub message bus (channel per user) |
| Backend (FastAPI SSE) | Subscribes to Redis; streams events to browser |
| Browser | Persistent EventSource to /api/v1/sse/events |
Configuration
No additional configuration is required. SSE uses the existing REDIS_URL already
configured for Celery. The endpoint is served by the backend container at /api/v1/sse/events
and routed through the same Caddy reverse proxy as all other API calls.
Synced Entities
| Entity | Used By |
|---|---|
notifications | Inbox (comments, document processing, connector status) |
documents | Document list, processing status indicators |
folders | Nested folder tree |
search_source_connectors | Connector status, indexing progress |
new_chat_messages | Live chat message sync for shared chats |
chat_comments | Real-time comment threads on AI responses |
chat_session_state | Collaboration indicators (who is typing) |
automation_runs | Live run status and per-step progress |
Troubleshooting
- Real-time updates not arriving: Open DevTools → Network → Filter by "eventsource"
and verify the connection to
/api/v1/sse/eventsis open (status200, typeeventsource). If the connection is closed, check browser console for errors. - SSE endpoint returns 500: Check backend logs for Redis connection errors.
Verify
REDIS_URLin your.envand that the Redis container is healthy (docker compose ps redis). - Events delivered to wrong user: SSE channels are scoped per
user_idderived from the bearer token. Verify the correct PAT or session token is in use. - High latency on first event: The
EventSourcereconnect delay is 3 seconds by default. A brief disconnect/reconnect is normal; persistent delays indicate Redis Pub/Sub backpressure or a blocked backend worker.