โ๏ธ TCP vs. UDP: Understanding the Differences ๐
TCP (Transmission Control Protocol) and UDP (User Datagram Protocol) are the two main transport layer protocols in networking.
They define how data is sent between devices over the internet.
1๏ธโฃ TCP (Transmission Control Protocol) ๐
TCP is a connection-oriented protocol, meaning it establishes a connection before sending data and ensures reliable delivery.
โ Key Features of TCP
- โ Reliable โ Ensures all data packets arrive in the correct order.
- โ Error-checking โ Detects and resends lost or corrupted data.
- โ Connection-oriented โ Requires a three-way handshake before data transfer.
- โ Slower but accurate โ Suitable for applications where data integrity is crucial.
๐ How TCP Works? (3-Way Handshake)
Imagine you are visiting Google.com in your browser.
1๏ธโฃ SYN โ Your browser sends a SYN request to Googleโs server.
2๏ธโฃ SYN-ACK โ Googleโs server replies with a SYN-ACK confirming readiness.
3๏ธโฃ ACK โ Your browser sends an ACK, and the connection is now established!
Now your browser can request the webpage, and Googleโs server will send the data.
๐ก Visual: TCP 3-Way Handshake
Step 1: SYN (Client โ Server)
โโโโโโโโโโโโโโโโโ SYN Request โโโโโโโโโโโโโโโโโ
โ Browser โ โโโโโโโโโโโโโโโโถ โ Google Server โ
โ (Client) โ โ (Server) โ
โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ
Step 2: SYN-ACK (Server โ Client)
โโโโโโโโโโโโโโโโโ SYN-ACK Reply โโโโโโโโโโโโโโโโโ
โ Browser โ โโโโโโโโโโโโโโโ โ Google Server โ
โ (Client) โ โ (Server) โ
โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ
Step 3: ACK (Client โ Server)
โโโโโโโโโโโโโโโโโ ACK Response โโโโโโโโโโโโโโโโโ
โ Browser โ โโโโโโโโโโโโโโโโถ โ Google Server โ
โ (Client) โ โ (Server) โ
โโโโโโโโโโโโโโโโโ โโโโโโโโโโโโโโโโโ
โ Connection Established! ๐
๐ ๏ธ Examples of TCP Usage
- ๐ Web Browsing (HTTP, HTTPS)
- ๐ง Email (SMTP, IMAP, POP3)
- ๐ File Transfers (FTP, SFTP)
- ๐ฅ๏ธ Remote Access (SSH, Telnet)
2๏ธโฃ UDP (User Datagram Protocol) โก
UDP is a connectionless protocol, meaning it sends data without establishing a connection.
Itโs faster but less reliable than TCP.
โ Key Features of UDP
- โ Fast โ No need to establish a connection, reducing latency.
- โ Unreliable โ No error-checking or retransmission of lost packets.
- โ Connectionless โ Sends data without verifying receipt.
- โ Best for real-time apps where speed matters more than accuracy.
๐ ๏ธ Examples of UDP Usage
- ๐ฅ Video Streaming (YouTube, Netflix, Twitch)
- ๐ฎ Online Gaming (PUBG, CS:GO, Fortnite)
- ๐ VoIP Calls (Skype, Zoom, WhatsApp Calls)
- ๐ DNS Requests (Domain Name Resolution)
๐ TCP vs. UDP: Key Differences
| Feature | TCP ๐ | UDP โก |
|---|---|---|
| Connection Type | Connection-oriented | Connectionless |
| Reliability | High (ensures all packets arrive) | Low (no guarantee of delivery) |
| Speed | Slower (due to error checking) | Faster (no error checking) |
| Use Case | Web browsing, emails, file transfers | Streaming, gaming, VoIP |
| Error Handling | Yes (resends lost packets) | No (lost packets are ignored) |
| When to Use | Use TCP when reliability > speed (e.g., emails, banking, downloads). | Use UDP when speed > reliability (e.g., streaming, gaming, VoIP). |
โ AWS Use Cases for TCP ๐ (Reliable, Connection-Oriented Protocol)
| AWS Service | Protocol (TCP Port) | Use Case |
|---|---|---|
| Amazon EC2 | TCP 22 (SSH) | Securely connect to a Linux instance using SSH |
| Amazon EC2 | TCP 3389 (RDP) | Connect to a Windows instance using Remote Desktop |
| Amazon S3 | TCP 443 (HTTPS) | Secure file transfers to/from S3 buckets |
| Elastic Load Balancer (ELB) | TCP 80 (HTTP) / 443 (HTTPS) | Distributes web traffic across EC2 instances |
| AWS RDS (MySQL, PostgreSQL, etc.) | TCP 3306 (MySQL), 5432 (PostgreSQL) | Database connections from applications |
| AWS Lambda (API Gateway trigger) | TCP 443 (HTTPS) | API Gateway invokes Lambda securely |
| Amazon WorkSpaces | TCP 4172 | Remote desktop connection for AWS WorkSpaces |