high-available RTMP platform with HAProxy and crtmpserver

Greetings to Olanis, HAProxy Technologies partner in Germany, for the idea and the content of this article.

Synopsis

You (or your clients) want to deliver video using the RTMP protocol, and of course you want a reliable architecture!
On the server side, you can use crtmpserver to deliver videos over rtmp.
One of the advantage of crtmpserver is that it runs well on small systems.
And to build the reliable and scalable part of the architecture, why not using HAProxy or the ALOHA appliance?

The architecture

To make it simple, let’s consider we have a single load-balancer which balance traffic to 3 media servers.
We’ll configure the load-balancer in transparent proxy mode.
No need to draw a diagram to understand how things are connected together 😉

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 a 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 firewall 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

Links

6 thoughts on “high-available RTMP platform with HAProxy and crtmpserver”

    1. there is a way to do this with content inspection.
      I’ll update the article later tonight.

      UPDATE: no need content inspection, just use the URL path to know wether the request is for your website or to download videos.

      cheers

  1. Hi ,
    If using haproxy, how about maximum bandwidth that user can get ? As an example haproxy get internet bandwidth 10Mbps, and have 2 backend with 10Mbps each for connection bandwidth.
    Is this system only can serve maximum 10MBps or this system can serve 20Mbps of maximum bandwidth?
    Thanks

  2. Hi, sorry for replying old post, But I want to ask some important question; let say we have three rtmp server which are A,B,C. We installed Haproxy to machine A and set backend servers as machine B and C as below diagram:

    A(Installed HAProxy)——->B
    |____________>C

    We start stream to A. Also our B and C machines configured to copy A’s stream which means same stream available for A,B and C machines.

    We only provide public ip of A machine to our viewers. As I understand from your post, When a viewer connect to A machine, If A machine is full, Instead of redirecting our viewers to B machine, Haproxy tries to connect B machine from A machine itself and serving it’s data to viewers from A’s bandwidth.

    I mean we balances our rtmp servers to reduce bandwidth usage of specific machines instead of computational usage. But this diagram lie heavily to A’s bandwidth instead of spread of different machines. Am I right or is there any other proxy methods to achieve that?

    1. Hi,

      We don’t lie heavily on bandwidth, since the article focus on High Availability.
      That said, your point is right, bandwidth is a concern and HAProxy server must have enough bandwidth capacity to handle all the traffic.
      We could explain all of this in a next article.

      Baptiste

Leave a Reply

Your email address will not be published. Required fields are marked *