Skip to main content
Zou includes a real-time event stream server using WebSockets for live updates. This powers features like collaborative playlist reviews, real-time notifications, and live data updates.

Overview

The event stream system consists of:
  1. WebSocket Server - Socket.IO server for real-time connections
  2. Redis Message Queue - Distributes events across multiple servers
  3. Event Handlers - Custom scripts triggered by events

Architecture

Configuration

Event Stream Server

string
default:"localhost"
Host address for the WebSocket server.
  • localhost - Only accept local connections
  • 0.0.0.0 - Accept connections from any network interface
  • Specific IP - Bind to specific network interface
string
default:"5001"
Port for the WebSocket server.Default: 5001 (main API typically runs on 5000)
string
default:"./event_handlers"
Folder containing custom event handler scripts.Handlers are Python scripts executed when specific events occur.

Redis Configuration

Redis is used as a message queue to distribute events across multiple Zou instances.
string
default:"localhost"
Redis server host address.
string
default:"6379"
Redis server port.
string
default:"None"
Redis password for authentication (if required).
The event stream uses Redis database index 2 (defined as KV_EVENTS_DB_INDEX in config).

Redis Databases

Zou uses multiple Redis databases for different purposes:

Starting the Event Stream Server

Standalone Mode

Or with custom host/port:

Production with Gunicorn

Only use 1 worker (-w 1) for event stream. Multiple workers require sticky sessions.

Docker Compose

WebSocket Events

The event stream server emits various events. From zou/event_stream.py:587:

Connection Events

Connect to event stream:
The server requires JWT authentication:

Playlist Review Room Events

Open playlist:
Join review room:
Leave review room:
Room updated:
People updated:

Annotation Events

Add annotation:
Remove annotation:
Update annotation:

Playback Control Events

Room updated (playback state):
Change version:

Room State Management

The server maintains room state in memory:

Server Statistics

Get server stats:
Response:

Event Handlers

Create custom scripts that run when specific events occur.

Event Handler Structure

Available Events

Common events from zou/app/services/events_service.py:587:
  • task:new - New task created
  • task:update - Task updated
  • task:assign - Task assigned
  • comment:new - New comment posted
  • preview-file:add-file - Preview file uploaded
  • person:update - Person updated
  • project:update - Project updated

Handler Naming Convention

Name handlers after events:
Replace : with _ in event names.

Redis Configuration

Redis Connection URL

The connection URL is built from configuration in zou/app/utils/redis.py:587:
Example URLs:

Redis Setup

Install Redis:
Configure Redis (optional):
Start Redis:

Clear Redis Cache

Multiple Server Setup

For high availability, run multiple event stream servers with Redis:
Redis distributes events to all servers automatically.

Load Balancer Configuration

Nginx

Use ip_hash or sticky sessions to ensure clients connect to the same server.

Monitoring

Connection Count

Redis Monitoring

Logs

The event stream server logs connections and errors:

Troubleshooting

Clients Can’t Connect

Check server is running:
Check firewall:
Check host binding: Ensure EVENT_STREAM_HOST=0.0.0.0 for remote connections.

Events Not Received

Check Redis connection:
Check JWT token: Ensure clients send valid JWT token in connection auth. Check rooms: Users must join rooms to receive room-specific events.

High Memory Usage

Clear Redis cache:
Limit Redis memory:

Disconnections

Increase timeouts:

Security

  1. JWT Authentication - All connections require valid JWT token
  2. CORS - Configure allowed origins
  3. SSL/TLS - Use HTTPS/WSS in production
  4. Redis Password - Set KV_PASSWORD for Redis authentication
  5. Firewall - Restrict port 5001 to trusted networks

Performance Tips

  1. Use Redis - Required for multi-server setups
  2. Single Worker - Event stream requires only 1 worker
  3. Gevent - Uses gevent for async I/O
  4. Sticky Sessions - Required for load balancing
  5. Monitor Connections - Watch connection count for capacity planning