NelworksNelworks

Tech / Season 1 / EP06

Discord Architecture

Tweet coming soon
Shez

My internet connection is a potato held together with string. How is Discord not lagging?

Kurumi

Because Discord not a phone call. It's a radio broadcast.

Shez

Kurumi! Do you live in my walls?

Shez

Anyway, how is Discord able to do all of these without lagging? On a Zoom call with 10 people, someone always sounds like a walkie talkie.

Kurumi

Because Zoom wants to be perfect. Discord just wants to be fast.

Kurumi

Discord uses **UDP**.

Shez

UDP??

Kurumi

A phone call uses TCP. It guarantees every packet of your voice arrives. If one gets lost, the whole system waits for it to be resent.

Kurumi

That's why calls freeze and then suddenly speed up. The truck was waiting for a signature.

Shez

So... the UDP truck is faster?

Kurumi

Much faster. It doesn't care if a package gets dropped. For voice, a dropped millisecond of audio is better than a 2-second delay. It prioritizes speed over perfection.

Shez

Okay, so it's a fast truck. But how do 50 people send packages to each other at once?

Kurumi

That's the second trick. You aren't sending your voice to 49 people.

Kurumi

You are sending it to **one**.

Kurumi

This is Discord. It is built with WebRTC and comes with a **Selective Forwarding Unit (SFU)**.

Kurumi

You send one clean stream to the Discord server. The server acts as a giant copy machine and broadcasts it to everyone else.

Kurumi

It's a copy machine. Upload once, download many. That saves your bandwidth.

Shez

Okay, but what about the noise? My friend is typing like a woodpecker on speed, but I can barely hear it. Just his voice.

Kurumi

Ah. It's called **Krisp**. It's an integrated AI.

Kurumi

It's a machine learning model that was trained to know the difference between a human voice and... everything else.

Kurumi

It cleans your audio *before* it even gets sent to the UDP truck.

Shez

The AI runs on Discord's servers?

Kurumi

No. It runs on your computer. Discord offloads the expensive work of noise filtering to your CPU.

Kurumi

They save millions in server processing costs by making your PC do the labor.

Shez

Alright, now the messages. How do these GIFs and memes show up instantly for everyone in the server?

Kurumi

Every online user has a persistent connection to a Gateway server. It's a WebSocket, a live tunnel for real-time events.

Shez

So my own personal mailman?

Kurumi

Exactly. The channel itself is managed by a Guild Server, written in Elixir. Elixir is built for millions of cheap, concurrent processes. Perfect for a chat room with 100,000 members.

Shez

Okay. UDP, SFUs, client-side AI, Elixir...

Shez

But I am currently sending a high-definition video stream across the planet for free along with my server members.

Shez

How is Discord still not bankrupted?

Kurumi

They would be if they weren't smart. But they are ruthless about not sending packets.

Shez

But... they have to send packets. That's what streaming is!

Kurumi

First, your voice. When you paused just now to take a breath, what did your PC send?

Shez

My... voice?

Kurumi

Nothing.

Kurumi

Voice Activity Detection (VAD). The client is smart enough to know when you're not talking. It just stops sending audio. That alone cuts bandwidth by half.

Kurumi

Now the video. You think you're sending one 720p stream. You're not. You're sending three.

Kurumi

It's called Simulcast.

Kurumi

All three go to the Discord SFU. The SFU acts as an operator.

Kurumi

It looks at your five friends.

Kurumi

'Friend A' is watching full-screen on a fiber connection? He gets the 720p stream.

Kurumi

'Friend B' is on her phone with two bars of signal? She gets the 240p stream so it doesn't buffer.

Kurumi

And 'Friend C', who has your stream minimized while he plays his own game?

Shez

It just... cuts him off?

Kurumi

Until he maximizes the window again. Why waste bandwidth sending video to a screen that isn't even looking at it?

Kurumi

TLDR. They offload noise filtering to you. They don't send your audio when you're quiet. They don't send video to people who aren't watching.

Kurumi

They took a process that should be expensive and, through a thousand tiny cuts, bled the cost dry.

Shez

So my 'free' stream isn't free. It's just ultra-light?

Kurumi

They engineered the cost down from dollars to fractions of a penny. The OpEx for a free user is so low that a Nitro subscription pays for thousands of them.