Overview
Ant Media Server supports clustering to handle thousands of concurrent streams by distributing the load across multiple server instances. The clustering architecture provides:- High Availability - Automatic failover if a node goes down
- Load Distribution - Streams distributed across available nodes
- Horizontal Scaling - Add more nodes to increase capacity
- Centralized Management - Manage all nodes from a single interface

Architecture
An Ant Media Server cluster consists of:Origin Nodes
Handle stream ingestion and processing:- Accept incoming streams (RTMP, WebRTC, etc.)
- Perform transcoding
- Generate HLS/DASH segments
- Store stream metadata in shared database
Edge Nodes
Deliver streams to viewers:- Serve HLS/DASH playlists and segments
- Handle WebRTC playback
- Fetch stream data from origin nodes
- Reduce load on origin servers
MongoDB Database
Centralized data store:- Stream metadata and status
- Application settings
- VoD records
- Analytics data
Load Balancer
Distributes traffic across nodes:- Routes incoming streams to available origins
- Directs viewers to edge nodes
- Performs health checks
- Handles SSL termination
Cluster Communication
Nodes communicate through the cluster interfaces:Node Health Monitoring
Each node updates its status every 5 seconds. A node is considered dead if it hasn’t updated in 20 seconds (4 × update period).Setup Guide
Prerequisites
Configure Origin Nodes
On each origin server, edit/usr/local/antmedia/conf/red5.properties:
Configure Edge Nodes
On each edge server:Stream Distribution
Publishing Flow
Stream Processing
Origin node:
- Accepts the stream
- Writes metadata to MongoDB
- Performs transcoding (if enabled)
- Generates HLS/DASH segments
Playback Flow
Monitoring the Cluster
REST API
Get cluster information:Web Dashboard
Access the cluster dashboard:- Navigate to http://your-server:5080
- Log in to the admin panel
- Go to Cluster section
- View node status, load, and stream distribution
Metrics to Monitor
| Metric | Description | Threshold |
|---|---|---|
| Node Status | alive/dead | Alert if any node is dead |
| CPU Usage | Per-node CPU utilization | Alert if >80% |
| Memory Usage | RAM consumption | Alert if >85% |
| Active Streams | Streams per node | Balance across nodes |
| DB Query Time | MongoDB response time | Alert if >100ms |
Scaling Strategies
Vertical Scaling (Single Node)
Increase server resources:- Add more CPU cores for transcoding
- Increase RAM for buffering
- Use faster storage (SSD/NVMe)
- Add GPU for hardware encoding
Horizontal Scaling (Cluster)
Add more nodes:
Benefits:
- Near-linear scaling (2x nodes ≈ 2x capacity)
- No downtime during expansion
- Redundancy and failover
High Availability
Automatic Failover
If an origin node fails:- Node heartbeat stops
- After 20 seconds, cluster marks node as dead
- Load balancer stops routing to failed node
- Existing streams on that node are lost
- New streams route to healthy nodes
Database Redundancy
Use MongoDB replica sets:Performance Tuning
Origin Node Optimization
Edge Node Optimization
Load Balancer Optimization
Troubleshooting
Node shows as 'dead' but server is running
Node shows as 'dead' but server is running
Causes:
- Network connectivity to MongoDB
- Firewall blocking cluster communication
- Time synchronization issues (NTP)
- Check MongoDB connection:
mongo --host <db-ip> - Verify firewall allows port 27017
- Sync time across all nodes:
sudo ntpdate -u pool.ntp.org
Streams not appearing on edge nodes
Streams not appearing on edge nodes
Causes:
- Edge can’t reach origin nodes
- Incorrect origin node configuration
- MongoDB sync delay
- Test connectivity:
curl http://<origin-ip>:5080/LiveApp/rest/v2/broadcasts/list/0/10 - Verify
cluster.origin.nodessetting on edge - Check MongoDB replication lag
Uneven load distribution
Uneven load distribution
Issue: All streams going to one nodeCauses:
- Load balancer algorithm (using
ip_hashinstead ofleast_conn) - Node reporting incorrect capacity
- Use
least_connorleast_timein Nginx upstream - Verify node metrics are updating correctly
Best Practices
Separate Origin/Edge
Don’t mix roles. Use dedicated origin nodes for encoding and edge nodes for delivery.
Monitor Database
MongoDB is critical. Use replica sets and monitor query performance closely.
Plan for Failure
Design for node failures. Use redundancy and monitoring with alerting.
Load Test
Test your cluster under realistic load before production deployment.
