You or your clients may want to deliver video using the RTMP protocol while ensuring a reliable architecture. For video delivery on the server side, the crtmpserver can be used for delivering videos over RTMP. A significant advantage of crtmpserver is its ability to run well on small systems. To build a reliable and scalable architecture, it's recommended to use HAProxy or the ALOHA appliance.

The Architecture

To make it simple, let’s consider we have a single load balancer that balances traffic to 3 media servers.
We’ll configure the load balancer in transparent proxy mode.

HAProxy Configuration for RTMP

By default, RTMP works over TCP 1935 port. So HAProxy configuration will be configured in TCP mode, like below. media03 has lower weight because it is used by clients to upload their videos, which are synchronized to other servers.

frontend ft_rtpm
 bind <public ip>:1935 name rtmp
 mode tcp
 maxconn 600
 default_backend bk_rtmp

backend bk_rtmp 
 mode tcp
 balance roundrobin
 stick store-request src
 stick-table type ip size 200k expire 20m
 stick on src
 source 0.0.0.0 usesrc clientip
 server media01 10.0.0.1:1935 check maxconn 200 weight 10
 server media02 10.0.0.2:1935 check maxconn 200 weight 10
 server media03 10.0.0.3:1935 check maxconn 200 weight 8

HAProxy Configuration for RTMP over HTTP

Some firewalls may not allow port 1935, so there is a failover solution: delivering RTMP over HTTP (or even HTTPS), on regular TCP port 80:

frontend rtmp-80
        bind <public ip>:80
        mode tcp
        maxconn 600
        default_backend rtmp-over-http

backend rtmp-over-http
        mode tcp
        balance roundrobin
        stick store-request src
        stick-table type ip size 200k expire 20m
        stick on src
        source 0.0.0.0 usesrc clientip
        server media01 10.0.0.1:1935 check maxconn 200 weight 10
        server media02 10.0.0.2:1935 check maxconn 200 weight 10
        server media03 10.0.0.3:1935 check maxconn 200 weight 8
Subscribe to our blog. Get the latest release updates, tutorials, and deep-dives from HAProxy experts.