Overview
The event stream system consists of:- WebSocket Server - Socket.IO server for real-time connections
- Redis Message Queue - Distributes events across multiple servers
- 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 connections0.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).
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
Production with Gunicorn
Docker Compose
WebSocket Events
The event stream server emits various events. Fromzou/event_stream.py:587:
Connection Events
Connect to event stream:Playlist Review Room Events
Open playlist:Annotation Events
Add annotation:Playback Control Events
Room updated (playback state):Room State Management
The server maintains room state in memory:Server Statistics
Get server stats:Event Handlers
Create custom scripts that run when specific events occur.Event Handler Structure
Available Events
Common events fromzou/app/services/events_service.py:587:
task:new- New task createdtask:update- Task updatedtask:assign- Task assignedcomment:new- New comment postedpreview-file:add-file- Preview file uploadedperson:update- Person updatedproject:update- Project updated
Handler Naming Convention
Name handlers after events:: with _ in event names.
Redis Configuration
Redis Connection URL
The connection URL is built from configuration inzou/app/utils/redis.py:587:
Redis Setup
Install Redis:Clear Redis Cache
Multiple Server Setup
For high availability, run multiple event stream servers with Redis:Load Balancer Configuration
Nginx
Monitoring
Connection Count
Redis Monitoring
Logs
The event stream server logs connections and errors:Troubleshooting
Clients Can’t Connect
Check server is running:EVENT_STREAM_HOST=0.0.0.0 for remote connections.
Events Not Received
Check Redis connection:High Memory Usage
Clear Redis cache:Disconnections
Increase timeouts:Security
- JWT Authentication - All connections require valid JWT token
- CORS - Configure allowed origins
- SSL/TLS - Use HTTPS/WSS in production
- Redis Password - Set
KV_PASSWORDfor Redis authentication - Firewall - Restrict port 5001 to trusted networks
Performance Tips
- Use Redis - Required for multi-server setups
- Single Worker - Event stream requires only 1 worker
- Gevent - Uses gevent for async I/O
- Sticky Sessions - Required for load balancing
- Monitor Connections - Watch connection count for capacity planning