Back to articles
Technology Insight

Building a Sub-Second Latency WebRTC Live Streaming System Using MediaMTX and Docker on a Budget VPS

May 30, 2026

Introduction to Ultra-Low Latency Streaming

In the modern digital landscape, real-time interaction has become the gold standard for live streaming. Traditional streaming protocols like HLS (HTTP Live Streaming) and DASH (Dynamic Adaptive Streaming over HTTP) are highly reliable but introduce inherent delays ranging from 2 to 30 seconds. For use cases such as live auctions, interactive gaming, real-time sports betting, and instant Q&A sessions, this latency is unacceptable.

Enter WebRTC (Web Real-Time Communication). Originally designed for peer-to-peer video conferencing, WebRTC has evolved into a powerhouse for one-to-many broadcasting, delivering content with sub-second latency (typically under 500 milliseconds). However, setting up a WebRTC infrastructure has historically been complex and resource-intensive.

This comprehensive guide demonstrates how to break down these barriers. By leveraging MediaMTX (formerly rtsp-simple-server)—a zero-dependency, highly efficient media server—and packaging it inside Docker, you can deploy a robust WebRTC streaming system even on a low-spec, budget Virtual Private Server (VPS), affectionately known in the tech community as a "VPS cỏ" (budget VPS).

Why MediaMTX and WebRTC on a Budget VPS?

When working with constrained hardware (e.g., 1 vCPU, 1GB-2GB RAM), software efficiency is paramount. Heavy enterprise media servers can easily overwhelm a budget VPS. MediaMTX stands out for several key reasons:

  • Written in Go: It compiles to a single, highly optimized binary with a remarkably low memory footprint and minimal CPU overhead.
  • Protocol Versatility: MediaMTX natively converts between RTSP, RTMP, WebRTC, HLS, and SRT. You can ingest via RTMP or WHIP and egress instantly via WHEP (WebRTC).
  • Docker Compatibility: Deployment is unified, reproducible, and takes less than five minutes.

By pairing MediaMTX with WebRTC, you eliminate the need for heavy transcoding if your source codec is already WebRTC-compatible (such as H264 for video and Opus or AAC for audio). This allows the budget VPS to act as a pure, high-speed routing switch rather than a heavy computing engine.

Prerequisites and System Architecture

Before proceeding with the deployment, ensure you have the following prerequisites ready:

  1. A Linux-based VPS (Ubuntu 22.04 LTS or 24.04 LTS recommended) with at least 1 vCPU and 1GB RAM.
  2. A registered domain name pointing to your VPS IP address (essential for generating SSL certificates, as WebRTC requires HTTPS).
  3. Docker and Docker Compose installed on your server.
  4. Ports 80/tcp and 443/tcp open for HTTP/HTTPS, 1935/tcp for RTMP (optional ingest), and 8554/tcp, 8889/tcp, 8189/udp for MediaMTX operations.

The Streaming Workflow Architecture

Understanding the data flow is essential for troubleshooting. The system operates on a seamless ingest-to-egress pipeline:

Streamer (OBS Studio/Browser via WHIP) → Ingest (RTMP/WebRTC) → MediaMTX Server (Docker on VPS) → Egress (WHEP/WebRTC) → End Users (Web Browser)

Step-by-Step Deployment Guide

Step 1: Setting up SSL Certificates via Certbot

WebRTC enforces strict security standards; browsers will refuse to initiate WebRTC connections over unencrypted HTTP. We will use Let's Encrypt to obtain a free, valid SSL certificate.

sudo apt update && sudo apt install -y certbot
sudo certbot certonly --standalone -d stream.yourdomain.com

Once completed, your certificate files will be available in /etc/letsencrypt/live/[stream.yourdomain.com/](https://stream.yourdomain.com/).

Step 2: Configuring MediaMTX via Docker Compose

Create a dedicated directory for your streaming infrastructure and set up the configuration files. This setup ensures that your configuration is persisted and properly mapped inside the Docker container.

mkdir -p ~/mediamtx && cd ~/mediamtx

Create a docker-compose.yml file with the following configuration:

version: '3.8'

services:
  mediamtx:
    image: bluenviron/mediamtx:latest
    container_name: mediamtx
    restart: unless-stopped
    ports:
      - "1935:1935" # RTMP Ingest
      - "8554:8554" # RTSP
      - "8889:8889" # WebRTC Signalling (HTTP)
      - "8189:8189/udp" # WebRTC Media (UDP)
    volumes:
      - ./mediamtx.yml:/mediamtx.yml
      - /etc/letsencrypt:/etc/letsencrypt:ro

Step 3: Optimizing mediamtx.yml for Low Latency

Download the default configuration template or create a streamlined mediamtx.yml file. To achieve ultra-low latency on a budget VPS, apply the following optimized parameters:

# mediamtx.yml optimization
paths:
  all:
    # Disable transcoding to save CPU
    sourceOnDemand: no

# Enable WebRTC Server
webrtc: yes
webrtcAddress: :8889
webrtcEncryption: yes
webrtcServerCert: /etc/letsencrypt/live/[stream.yourdomain.com/fullchain.pem](https://stream.yourdomain.com/fullchain.pem)
webrtcServerKey: /etc/letsencrypt/live/[stream.yourdomain.com/privkey.pem](https://stream.yourdomain.com/privkey.pem)

# ICE servers configuration for NAT traversal
webrtcICEServers2:
  - url: stun:stun.l.google.com:19302

# Bind the UDP port for media transfer
webrtcLocalUDPAddress: :8189

Launch the media server by running docker-compose up -d. Verify the logs with docker logs mediamtx to ensure the SSL certificates are loaded correctly and the WebRTC service is active.

Ingesting Video into your WebRTC Server

You have two main paths to push video to your newly configured MediaMTX server: via traditional RTMP using OBS Studio, or natively via WHIP (WebRTC HTTP Ingestion Protocol) for absolute lowest ingestion latency.

Method A: RTMP Ingest via OBS Studio

Open OBS Studio, navigate to Settings -> Stream, and configure the following:

  • Service: Custom...
  • Server: rtmp://[stream.yourdomain.com/live](https://stream.yourdomain.com/live)
  • Stream Key: mystream

Crucial Encoding Settings for Low Latency: Set your Rate Control to CBR, Bitrate to 2500 Kbps (ideal for 720p/1080p at 30fps on low-tier servers), Keyframe Interval to 1s or 2s, and CPU Usage Preset to veryfast or superfast. Ensure your audio codec is set to AAC.

Method B: WHIP Ingest

Modern versions of OBS Studio support WHIP natively. Change your stream service to WHIP, use the URL [https://stream.yourdomain.com:8889/live/mystream](https://stream.yourdomain.com:8889/live/mystream), and experience real-time publishing directly through WebRTC protocols.

Building the Ultra-Low Latency Web Player

MediaMTX includes a built-in web viewer, but for production environments, you will want to embed a custom HTML5 player into your web application. Here is a clean, dependency-free implementation using standard JavaScript and the browser's native WebRTC API:




    
    Ultra-Low Latency Live Stream
    


    

Live WebRTC Stream

Performance Tuning and Cost Optimization

Running real-time operations on a budget VPS requires aggressive resource management. Observe these practices to ensure server stability:

  • Avoid Server-Side Transcoding: Ensure the incoming video codec is strictly H264 and audio is Opus or AAC. MediaMTX will passthrough the packets with zero CPU usage. If MediaMTX has to transcode, a budget 1-vCPU server will instantly crash.
  • Monitor Network Bandwidth: WebRTC uses UDP. If your viewers have unstable connections, consider implementing a TURN server (like Coturn) alongside your STUN configuration to handle firewalls safely.
  • Concurrence Management: A typical $5/month VPS can easily support 50 to 100 concurrent viewers on a pure WebRTC passthrough model, provided the network port bandwidth is at least 100 Mbps.

Conclusion

Building a sub-second latency live streaming system no longer requires thousands of dollars in infrastructure or complex cloud setups. By combining the efficiency of MediaMTX, the isolation of Docker, and the ultra-low latency characteristics of WebRTC, you can deploy a production-ready streaming solution on a budget VPS. Implement this architecture today to elevate your real-time web applications to a professional standard.

Building a Sub-Second Latency WebRTC Live Streaming System Using MediaMTX and Docker on a Budget VPS | DPTCloud