When people talk about UDP, we often hear the standard textbook thing, but let’s dig a level deeper and explore something more practical and interesting.
One super interesting feature of UDP is that it natively supports multicast and broadcast, i.e., one-to-many message delivery. Doing this with TCP is painful, as you would need to create connections with every node and then send the messages separately.
With UDP, you can simply send a message to a broadcast IP, and all nodes listening on the same UDP port will receive it. This reduces network overhead and latency for one-to-many communication. Such broadcasts are used in:
- multiplayer games to discover available local matches
- home devices where sensors announce themselves
- home automation systems where devices receive commands
- DNS, which uses UDP for its queries
Games are where UDP really shines. It’s okay if a few packets are lost; it’s usually better to just send the next update rather than wait for retransmission.
To see this in action and understand it better, I highly recommend building a quick prototype that sends a UDP broadcast and writing a receiver for it. It’ll take barely 15 minutes, but you’ll learn a lot in the process.
Hope this helps.
btw, enrollments open for sys design June cohort for sde2+, ~8 seats left - arpitbhayani.me/course