What is datagram?
A datagram is a small packet of data that travels across a network on its own, without needing a dedicated connection. Think of it like a postcard: it contains the message, the sender’s address, and the receiver’s address, and it’s sent independently of any other postcards.
Let's break it down
- Packet: The basic unit of data that moves through a network.
- Self‑contained: All the information needed (source, destination, and the data) is inside the packet.
- Connection‑less: The network does not set up a permanent link between sender and receiver; each datagram is handled separately.
- Best‑effort delivery: The network tries to deliver it, but it doesn’t guarantee arrival, order, or error‑free transmission.
Why does it matter?
Datagrams let computers send information quickly and efficiently, especially when speed is more important than perfect reliability. They are the foundation of protocols like UDP, which power real‑time applications such as video calls, online gaming, and live streaming where a few lost packets are better than a delay.
Where is it used?
- Streaming media (YouTube, Twitch) - to keep video flowing smoothly.
- Online gaming - for fast, low‑latency updates.
- Voice over IP (VoIP) - like Zoom or Skype calls.
- DNS queries - looking up website addresses.
- IoT devices - sensors sending quick status updates.
Good things about it
- Low latency: No handshake or connection setup, so data is sent instantly.
- Simple design: Easier to implement in hardware and software.
- Scalable: Works well for millions of tiny messages across large networks.
- Flexibility: Applications can decide how to handle loss, ordering, or errors.
Not-so-good things
- No delivery guarantee: Packets can be lost, duplicated, or arrive out of order.
- No built‑in error correction: The application must handle any needed checksums or retransmissions.
- Potential for congestion: Without flow control, many datagrams can overwhelm a network.
- Security concerns: Because they’re connection‑less, they can be spoofed more easily if not protected.