Transport Layer: Data Transfer Methods
The Transport Layer handles how data is transmitted between devices. It supports two main protocols:
-
UDP (User Datagram Protocol)
- Fastest transmission
- No guarantee of delivery
- No error checking or correction
- Suitable for speed-critical applications (e.g., video streaming, online games)
-
TCP (Transmission Control Protocol)
- Reliable and secure transmission
- Ensures data delivery with error checking and re-transmission
- Used for applications where accuracy matters (e.g., file transfers, emails)
π‘ Protocol Requirementβ
- Protocols define the rules for communication between devices(Ensures end-to-end data delivery).
- Communication always needs a protocol to standardize the interaction (like TCP or UDP).
Protocols:
- TCP: Reliable, ensures ordered and error-checked data transmission.
- UDP: Fast but less reliable, suitable for applications needing quick data transfer.
π TCP β Transmission Control Protocolβ
π 1. Connection Establishmentβ
- TCP uses a Three-Way Handshake to establish a reliable connection.
- Client β SYN β Server
- Server β SYN-ACK β Client
- Client β ACK β Server
π This process ensures both sides are ready to send and receive data.
(Three-Way Handshake):
2. Reliable Data Transferβ
- TCP ensures reliable and ordered delivery of data:
- Data is guaranteed to be delivered.
- Order of delivery is preserved.
- No data is lost.
- Secure, reliable, and maintains data integrity.
π§© Segmentationβ
- Large data is split into smaller chunks called packets or segments.
- This process is known as segmentation.
Segmentation
π Retransmissionβ
- If a packet fails to reach the destination or gets corrupted, TCP will retransmit it.
- This ensures reliability.
Retransmission
π₯ Acknowledgment and Flow Controlβ
- Instead of acknowledging every packet, TCP uses algorithms to manage ACKs more efficiently (e.g., delayed ACK, cumulative ACK).
- Helps with performance and congestion control.
β Checksum β Error Detectionβ
- A checksum is used to detect errors in the data during transmission.
- Process:
- Sender generates a checksum and sends it along with the data.
- Receiver recalculates the checksum.
- If both checksums match β data is valid.
- If they differ β retransmission occurs.
β Checksum is essential for error handling in TCP.
3. Graceful Connection Terminationβ
- TCP connection is closed using a Four-Way Handshake.
- Either the client or server can initiate termination.
β Summary β TCP Has 3 Main Stepsβ
- Connection Establishment β 3-way handshake
- Data Transfer β Sequencing, segmentation, flow control, checksums
- Connection Termination β 4-way handshake (graceful close)
UDP β User Datagram Protocolβ
- Focuses on speed and low latency
- "Fire and forget" mechanism β no connection is established
- No guarantee of delivery or order
- No retransmission or error correction
- Stateless protocol β no session is maintained between sender and receiver
Comparison table between TCP and UDPβ
Feature | TCP (Transmission Control Protocol) | UDP (User Datagram Protocol) |
---|---|---|
Reliability | Reliable β Guarantees delivery of data | Unreliable β No guarantee of delivery |
Connection Type | Connection-oriented | Connectionless |
Speed | Slower (due to connection and reliability overhead) | Faster |
Overhead | High β Establish, maintain, and terminate the connection | Low β No connection setup needed |
Error Handling | Advanced error handling (e.g., checksums, retransmission) | Basic error handling |
Data Ordering | Maintains sequencing and correct order of data | No sequencing or ordering |
Retransmission | Retransmits lost or corrupted packets | No retransmission |
Security & Reliability | Safe, secure, and reliable | Lightweight and fast, but less reliable |
Use Cases | Emails, web browsing (HTTP/HTTPS), file transfers (FTP) | Online gaming, video/audio streaming (Zoom, VoIP) |
Broadcasting Support | Not supported | Supported (one-to-many communication) |
info
High-Level System Design is all about trade-offs. What does a trade-off mean? β If I want something, I have to give up something else.
What is a Trade-off in System Design?β
- A trade-off means giving up one thing to gain another.
- In system design, you often can't optimize everything at once β improving one aspect may come at the cost of another.
π Example:
-
If you want high availability, you might have to sacrifice consistency (as in the CAP theorem).
-
If you want faster performance, you might need to use more memory or computing power, increasing cost.
Why Trade-offs Matter in High-Level Design:β
When designing a system, youβll need to balance between:
- Performance vs Scalability
- Consistency vs Availability
- Latency vs Throughput
- Cost vs Reliability
- Simplicity vs Flexibility
info
π§ Golden Rule:β
- Thereβs no perfect system β only systems that are optimized for specific goals based on the use case.
- Every choice in system design comes with a cost, and thatβs the trade-off you decide to accept.