DEV Community

Cover image for Networking 101 #4. TCP vs UDP
Himanshu Bhatt
Himanshu Bhatt

Posted on

Networking 101 #4. TCP vs UDP

๐Ÿ‘‹ Short Intro (Why Iโ€™m Writing This)

Iโ€™m currently learning Networking for DevOps and decided to learn in public by documenting my journey.

This blog is part of my Networking 101 series, where Iโ€™m learning Networking for DevOps step by step from scratch.

This series is not written by an expert โ€” itโ€™s a beginner learning out loud, sharing:

  • what I understand,
  • what confuses me,
  • and what I learn along the way.

The goal is to build consistency, clarity, and invite discussion.


๐Ÿ“Œ What This Blog Covers

In this post, Iโ€™ll cover:

  • What is TCP
  • Advantages of TCP
  • What is UDP
  • Advantages of UDP
  • When to use TCP vs UDP
  • Basic commands related to TCP & UDP

๐Ÿ“‚ GitHub Repository

All my notes, diagrams, and learning resources for this series live here:

๐Ÿ‘‰ GitHub Repo:

https://github.com/dmz-v-x/networking-for-devops-101

This repo is updated as I continue learning.


๐Ÿ“š Learning Notes

1. First, the big question

When one computer sends data to another, how do we make sure:

  • The data arrives?
  • The data arrives in the correct order?
  • Missing data is re-sent?

There are two different answers to this problem.

They are called:

  • TCP
  • UDP

2.Before we start: where TCP & UDP sit

From earlier blogs, our stack looks like this:

Application (HTTP, SSH, DB)
        โ†“
Transport Layer (TCP or UDP)
        โ†“
IP (IP Address)
        โ†“
Network
Enter fullscreen mode Exit fullscreen mode

TCP and UDP live in the transport layer.

They decide how data moves, not where it goes.


3. TCP โ€” Transmission Control Protocol

TCP is the most important protocol for DevOps engineers.

3.1 What TCP guarantees

TCP guarantees:

  • Data arrives
  • Data arrives in order
  • Lost data is re-sent
  • Duplicate data is removed

This makes TCP reliable.


4. What โ€œconnection-basedโ€ actually means

Before sending data, TCP does something crucial.

It creates a connection.

Conceptually:

  1. Client: โ€œCan we talk?โ€
  2. Server: โ€œYesโ€
  3. Client: โ€œGreatโ€

This is called the TCP handshake.

If this handshake fails, nothing else happens.


5. Common DevOps errors caused by TCP failure

If TCP connection fails, youโ€™ll see errors like:

  • Connection refused
  • Connection timed out
  • No route to host

These errors mean:

  • The app may be running
  • But TCP cannot establish a connection

Usually due to:

  • Firewall rules
  • Closed ports
  • App not listening
  • Wrong IP or port

6. What uses TCP? (Very important list)

Almost everything you use daily:

Protocol Uses TCP?
HTTP โœ…
HTTPS โœ…
SSH โœ…
FTP โœ…
Databases โœ…

If reliability matters โ†’ TCP is used.


7. UDP โ€” User Datagram Protocol

UDP solves a different problem.

7.1 What UDP does (and doesnโ€™t do)

UDP:

  • Sends data
  • Does not guarantee delivery
  • Does not guarantee order
  • Does not create a connection

UDP is fast, but unreliable.


8. UDP analogy (simple)

TCP is like:

Making a phone call and talking step by step.

UDP is like:

Shouting messages across a room and hoping theyโ€™re heard.


9. Why does UDP even exist?

Because sometimes:

  • Speed matters more than perfection
  • Losing some data is okay

Examples:

  • DNS queries
  • Video streaming
  • Online gaming
  • Metrics & monitoring systems

Retrying TCP connections would be too slow here.


10. What uses UDP? (DevOps-relevant)

Use Case Protocol
DNS (mostly) UDP
Metrics UDP
Service discovery UDP
Streaming UDP

DNS often uses UDP first, and TCP only if needed.


11. Side-by-side comparison (important)

Feature TCP UDP
Connection Yes No
Reliable Yes No
Ordered Yes No
Speed Slower Faster
DevOps usage Very High Medium

12. How this affects DevOps debugging

When something breaks, ask:

  • Is this TCP-based or UDP-based?
  • Does it expect reliability?

Examples:

  • HTTP API failing โ†’ TCP issue
  • DNS sometimes failing โ†’ UDP + network issue
  • Metrics missing โ†’ UDP packet loss

Understanding this changes how you debug.


13. Commands mapped to TCP & UDP

13.1 TCP testing

Checks if TCP port 443 is open and reachable

nc -vz example.com 443
Enter fullscreen mode Exit fullscreen mode

13.2 UDP testing

Sends a UDP packet to port 53 to see if itโ€™s reachable (best-effort check)

nc -vu example.com 53
Enter fullscreen mode Exit fullscreen mode

Notice:

  • TCP checks for connection
  • UDP just sends data

14. Real DevOps scenario

Problem:

Your app can resolve DNS, but sometimes fails to connect.

Why this happens:

  • DNS uses UDP
  • UDP packets can be dropped
  • Retry logic may be missing

This is why DNS caching and retries matter (next blogs!).


โœ… Key takeaways

  • TCP = reliable, connection-based
  • UDP = fast, connectionless
  • Most DevOps tools rely on TCP
  • DNS and metrics often use UDP
  • Error messages tell you which layer is failing

๐Ÿ’ฌ Feedback & Discussion

๐Ÿ’ก Iโ€™d love your feedback!

If you notice:

  • missing tool categories,
  • incorrect assumptions,
  • or better learning paths,

please comment below. Iโ€™m here to learn.


โญ Support the Learning Journey

If you found this blog useful:

โญ Consider giving the GitHub repo a star โ€”

it really motivates me to keep learning and sharing publicly.


๐Ÿฆ Stay Updated (Twitter / X)

I share learning updates, notes, and progress regularly.

๐Ÿ‘‰ Follow me on Twitter/X:

https://x.com/_himanshubhatt1


๐Ÿ”œ Whatโ€™s Next

In the next post, Iโ€™ll be covering:

๐Ÿ‘‰ DNS Explained

Iโ€™ll also continue updating the GitHub repo as I progress.


๐Ÿ“˜ Learning in public

๐Ÿ“‚ Repo: https://github.com/dmz-v-x/networking-for-devops-101
๐Ÿฆ Twitter/X: https://x.com/_himanshubhatt1
๐Ÿ’ฌ Feedback welcome โ€” please comment if anything feels off
โญ Star the repo if you find it useful

Top comments (0)