Previously in this series I showed you how to migrate a Matrix server to use Postgres, a database server designed for busy workloads, such as those of a busy chat server. This time around I'll demonstrate how to integrate Synapse with a STUN/TURN server to make the voice and video conferencing features of the Matrix network more reliable. It's remarkably easy to do but it does take a little planning. Here's why I recommend doing this:
If you are reading this, chances are you're behind a NATting firewall, which means that your device doesn't have a publically routable IP adresss. In addition to rewriting all of your network traffic so that it doesn't look like it's coming from a private network, the firewall is also doing port forwarding to pass inbound traffic to your device (least of all replies from web servers), again so it doesn't look like you're behind a firewall. This works just ducky with TCP traffic because TCP sets up bidirectional connections; TCP packets are acknowledged every time which has the additional effect of letting the firewall keep the connection together. VoIP traffic, on the other hand, tends to use UDP, which is not connection-oriented. One way to look at UDP is as a fire-and-forget protocol: The packet gets launched toward its destination, and it may or may not arrive depending upon network core weather patterns, luck, the phase of the moon... packets may also not necessarily arrive in the correct order. It's an inherently unreliable protocol. This is what makes it useful for streaming data traffic like audio or video, because it's inherently low latency. If you've ever been on a call and heard it break up or go into robot mode (or for that matter, seen a television program glitch out) this is probably what happened. The occasional glitchout is the price you pay for a relatively snappy data stream.