Infrastructure

Self-hosted LiveKit is four services, and the three nobody mentions are where outages come from

When people say they self-host LiveKit, they usually mean one binary. A production stack is actually four co-located containerised services: the SFU, the SIP service, Redis, and a TLS terminator on port 443. Because the media and SIP services require over ten thousand UDP ports, they must run in the host network namespace. This removes container isolation, exposes Redis to the host, and binds the stack to host-level constraints. The processes will exhaust the stock open-file limit before reaching CPU limits, and a dirty restart leaves stale containers holding exclusive host ports while new containers fail to bind.

Symptoms

A self-hosted realtime deployment often demos perfectly and then fails in ways that look completely unrelated to one another. The stack encounters three distinct failure modes:

  • After a host reboot, the stack comes back up, the media server is healthy, and browser calls work perfectly, but phone calls quietly stop routing until somebody intervenes.
  • The server drops new connections as it hits the stock open-file limit, even though CPU capacity is not the binding constraint.
  • A restart leaves a half-old, half-new set of containers fighting over host ports, causing silent routing failures for specific protocols.
  • Media relay sockets and client connections fail silently once the stock file-descriptor ceiling is reached.

What is actually happening

When people say they self-host LiveKit, they usually mean they run one binary. Production is actually four co-located containerised services: the SFU, the SIP service, Redis, and a TLS terminator on port 443. TURN is not a fifth process. It is a capability enabled inside the media server, exposed on its own ports and reached through the layer-4 TLS route, which is exactly why people forget to think about it.

These four services fail independently, but usually, only the SFU has a health check that anyone bothers to probe. This leads to situations where the SIP service goes down, phone calls stop routing, and the SFU health check still reports a healthy stack.

Two host-level constraints bind all of these services together. First, the media services need roughly ten thousand UDP ports for RTC traffic, plus the TURN ports and the SIP RTP ports. Publishing ten thousand ports through standard container port mapping is not workable at this scale. To handle the traffic efficiently, the stack must run in the host network namespace. This immediately strips away container network isolation. Redis and the SIP service are suddenly sitting directly on the host interface, exposed to exactly the same network as the public-facing services.

Second, a realtime process holds several sockets per participant, plus relay sockets for media routing. When running in a host network namespace, the system walks right past the default open-file limit long before it runs out of CPU capacity. The operating system refuses to open new file descriptors, which means the process cannot accept new sockets, establish new WebRTC connections, or handle new participants. The server looks idle on CPU monitors but silently drops every incoming call because it cannot allocate the file descriptors to handle the network handshakes.

Finally, host ports are exclusive. If a restart command does not fully clear the old containers before starting the new ones, a stale container will hold onto the SIP signaling port or a critical UDP range. The new container boots, fails to bind to the required port, and either crashes immediately or silently fails to route traffic while the old container processes packets with completely stale application state.

How to confirm it

  1. Check the open file descriptors for the media server process using lsof -p <pid> | wc -l and compare it to the system default limit. Expect the realtime process to be near the operating system’s stock open-file limit on a failing system. A count bumping against the ceiling confirms FD exhaustion.
  2. Inspect the restart counts of the individual containers using docker ps. Expect to see the SIP service or Redis restarting repeatedly, while the supervising systemd unit remains active. This confirms independent service failure masked by project-level supervision.
  3. Verify the network mode of the containers using docker inspect. Expect the network mode to return as host, confirming that they share the host network namespace and are subject to host-level exclusive port bindings.
  4. Attempt to bind to the SIP signaling port using netstat -tulpn | grep 5060 during a restart phase. Expect to see an older container PID holding the port if a dirty restart just occurred, confirming the exclusive port conflict.

How it works

I build the production topology as one Compose project entirely in the host network namespace, owned by a single systemd unit. This binds the lifecycle of all four services to a single supervisor and prevents split-brain restarts.

The network layout maps directly to the host interfaces. The TLS terminator listens on port 443. The SFU uses its documented default ports: 7880 for the websocket connection, 7881 for TCP fallback, and the 50000 to 60000 range for RTC UDP traffic. The SIP signaling service listens on port 5060, with its RTP range occupying 10000 to 20000. TURN is exposed on its documented ports: 5349 for TLS and 3478 for UDP.

Because host networking provides no isolated container network to hide behind, Redis must be explicitly bound to the loopback interface with protected mode turned on. Failing to do this exposes the datastore to the public internet, which is a common mistake when migrating from bridge networks to host networking.

The systemd unit carries a Restart=always directive, but more importantly, it has an open-file limit raised well past the stock default. Realtime systems are IO-bound at the socket level. Raising the file descriptor limit in the systemd configuration ensures the process can actually utilize the available CPU rather than starving on basic socket allocations.

To prevent port conflicts during a restart, the systemd unit uses an ExecStartPre directive that forcefully brings the Compose project down before bringing it up. This strict down-before-up ordering guarantees that a restart can never leave a stale container holding an exclusive host port. Runtime secrets are injected at container start rather than baked into a configuration file that lives on disk, preventing stale credentials from lingering across dirty state transitions.

What I would check first

  1. Check the configured open-file limit on the supervising systemd unit. If it is still set to the OS default, you will hit a hard ceiling on concurrent connections regardless of your hardware. Comparing the stack’s active open file descriptors against the configured limit confirms or rules out socket exhaustion.
  2. Check if the SIP service is answering independently of the SFU. Run a direct health check against the SIP container. If it fails while the SFU is healthy, it rules out a full stack crash and points to an isolated service failure.
  3. Check the host port bindings during a restart. Monitor the ports with a network utility as the service restarts. If you see overlapping PIDs holding the ports, it rules out application-level crashes and confirms a container lifecycle ordering issue.
  4. Check which individual container is restarting using docker ps. Because Compose restarts individual services while systemd only monitors the project unit, an individual container failure will not trip systemd. Observing high restart counts on a single container isolates an independent service crash from a host-level port conflict.

Hardening the SIP boundary

Running the SIP service in this co-located topology introduces another specific failure mode. If the stack restarts cleanly, the SIP service still loses its trunk state. Redis might persist some session data, but the cached IDs become stale. Outbound SIP calls fail because the trunk literally does not exist in the new process memory, even though the configuration file is completely correct. I wrote about this failure mode in /blog/livekit-sip-trunk-does-not-exist-after-a-container-recreate-or-host-reboot/.

Instrumentation and monitoring gaps

The standard approach to monitoring a realtime stack is to ping the SFU health endpoint. In a four-service topology, this is a dangerous gap. The SFU can be perfectly healthy while the SIP service is completely down, or while TURN fallback is broken because the TLS terminator misroutes port 443 traffic.

The instrumentation you actually need to watch is the number of open file descriptors held by the stack against the unit configured limit. You also need to track which individual container is restarting. Docker Compose restarts individual services automatically, and systemd only sees the project as a whole. A container in a crash loop will not trip the systemd unit failure state, leaving you blind to the degraded service until a user complains.

Finally, SIP signaling answering must be its own independent check rather than folded into the overall stack health. An unprobed SIP failure is what caused phone calls to quietly stop routing after a host reboot in production while browser calls continued to work.

Common questions

Do I need host networking for LiveKit?

Yes. The media server and SIP service require over ten thousand UDP ports. Publishing ten thousand ports plus TURN and SIP ranges cannot sensibly be done through container port mapping.

Why do SIP calls fail while browser video works?

The SIP service runs as an independent container alongside the SFU. It can crash or lose trunk state during a restart while the media server remains completely healthy.

Is TURN a separate container in LiveKit?

No. TURN is a capability enabled directly inside the media server. It uses its own TLS and UDP ports but runs within the exact same process.

Why does my LiveKit server drop new connections?

Realtime processes hold multiple sockets per participant and hit the default OS open-file limit very quickly. You must raise this limit on the supervising systemd unit.

Infrastructure

LiveKit SIP Trunk Does Not Exist After A Container Recreate Or Host Reboot

After a reboot or container recreate, outbound dialling fails silently. How to persist Redis state, configure systemd, and self-heal stale trunk identifiers.