📘 System Design - Concepts

TCP vs UDP in System Design

TCP and UDP are two important transport layer protocols used for this purpose. Understanding the difference is important when designing APIs, real-time systems, video streaming, gaming systems, messaging platforms, and distributed applications.

S

Site Administrator

📅 Sep 26, 2026 🕒 7 min read 👁 34 views
☆ Save 𝕏 in f ✆
TCP vs UDP in System Design

When applications communicate over a network, they need a way to transport data between two machines.

TCP and UDP are two important transport layer protocols used for this purpose.

Understanding the difference is important when designing APIs, real-time systems, video streaming, gaming systems, messaging platforms, and distributed applications.

1. Where TCP and UDP Fit

A simplified networking stack looks like this:

flowchart TD
Application --> TCP
Application --> UDP
TCP --> IP
UDP --> IP

HTTP, HTTPS and many application protocols use a transport protocol underneath them.

2. What is TCP?

TCP stands for Transmission Control Protocol.

TCP provides reliable, ordered communication between two endpoints.

If an application sends:

A B C D

TCP is designed to ensure that the receiving application gets the data correctly and in order.

3. Important Characteristics of TCP

  • Connection-oriented
  • Reliable delivery
  • Ordered delivery
  • Error detection
  • Retransmission of lost data
  • Flow control
  • Congestion control

Because TCP provides these features, it has additional communication overhead compared with UDP.

4. TCP Connection

TCP establishes a connection before application data is exchanged.

A simplified representation is:

sequenceDiagram
Client->>Server: Connect
Server->>Client: Accept
Client->>Server: Data
Server->>Client: Response
Client->>Server: Close

The actual TCP connection establishment uses the well-known three-way handshake.

5. TCP Three-Way Handshake

The three-way handshake establishes the initial TCP connection.

sequenceDiagram
Client->>Server: SYN
Server->>Client: SYN ACK
Client->>Server: ACK

After the handshake, the connection can carry application data.

6. What is UDP?

UDP stands for User Datagram Protocol.

UDP is connectionless and provides a lightweight way to send data.

Unlike TCP, UDP does not guarantee that every packet will arrive, arrive only once, or arrive in the same order.

For example:

flowchart LR
Client --> Server
Client --> Server
Client --> Server

The sender sends datagrams without establishing a TCP-style connection first.

7. Important Characteristics of UDP

  • Connectionless
  • Low protocol overhead
  • No guaranteed delivery
  • No guaranteed ordering
  • No built-in retransmission
  • No built-in congestion control like TCP

This makes UDP useful when speed and low latency are more important than guaranteed delivery of every packet.

8. TCP vs UDP

Feature TCP UDP
Connection Connection-oriented Connectionless
Reliable delivery Yes No guarantee
Ordering Maintained Not guaranteed
Retransmission Supported Not built in
Overhead Higher Lower
Latency Can have additional overhead Generally lower protocol overhead
Typical use Web, APIs, databases Real-time media, DNS, gaming

9. Real-World Example: Banking API

Imagine transferring ₹10,000 from one bank account to another.

We do not want a payment request to disappear because of packet loss.

A simplified architecture could be:

flowchart LR
Client --> HTTPS
HTTPS --> PaymentAPI
PaymentAPI --> Database

HTTPS commonly runs over TCP-based transport in traditional HTTP deployments, providing reliable communication for the request and response.

For operations such as payments, reliable delivery and correct ordering are extremely important.

10. Real-World Example: Online Gaming

Consider a multiplayer game where a player's position is updated many times per second.

Suppose the client sends:

Player position X
Player position Y
Player position Z

If one position update is lost, the next update may make the old update irrelevant.

For this type of traffic, low latency can be more important than retransmitting every lost update.

UDP can therefore be useful for certain real-time communication scenarios.

11. Video and Audio Streaming

Real-time audio and video applications have similar requirements.

Consider a live video call:

flowchart LR
Camera --> Network
Network --> Receiver
Receiver --> Screen

If a single video packet is lost, retransmitting it several seconds later may not be useful because the conversation has already moved forward.

Real-time communication systems can therefore use UDP-based protocols or technologies built on UDP when appropriate.

12. DNS and UDP

DNS commonly uses UDP for normal queries because DNS requests are usually small and UDP has low overhead.

For example:

Client --> DNS
DNS --> Client

DNS can also use TCP in situations where TCP is required, such as certain large responses or protocol operations.

13. Can HTTP Use UDP?

Traditional HTTP/1.1 and HTTP/2 deployments commonly use TCP.

HTTP/3 uses QUIC, and QUIC runs over UDP.

This does not mean HTTP/3 simply gives up reliability.

QUIC implements reliability, ordering mechanisms, encryption, and other transport features at the QUIC layer while using UDP underneath.

flowchart TD
HTTP3 --> QUIC
QUIC --> UDP
UDP --> IP

14. TCP Reliability

Suppose TCP sends several pieces of data:

Packet 1
Packet 2
Packet 3
Packet 4

If a packet is lost, TCP can detect the loss and retransmit the required data.

This reliability is useful for applications where losing data is unacceptable.

15. UDP Does Not Mean Unreliable Application

An important interview point is that UDP itself does not provide reliable delivery.

However, an application or protocol built on UDP can implement additional mechanisms when required.

QUIC is a major example.

So avoid saying:

UDP = Always unreliable

A better statement is:

UDP provides no built-in guarantee of delivery or ordering. Higher-level protocols can add their own reliability mechanisms.

16. TCP in ASP.NET Core Applications

When you build an ASP.NET Core Web API and expose an HTTPS endpoint, you generally do not manually implement TCP communication.

The networking stack handles the lower-level transport details.

[ApiController]
[Route("api/orders")]
public class OrdersController : ControllerBase
{
    [HttpGet("{id}")]
    public IActionResult GetOrder(int id)
    {
        return Ok(new
        {
            Id = id,
            Status = "Completed"
        });
    }
}

The application focuses on HTTP while the underlying networking stack handles transport communication.

17. Connection Pooling

TCP connections have a cost.

Creating a new connection repeatedly can increase latency and resource usage.

Modern applications therefore use connection reuse and pooling where appropriate.

For example, database clients and HTTP clients can maintain reusable connections.

In ASP.NET Core, HttpClientFactory helps manage HTTP client instances and connection lifetime correctly.

builder.Services.AddHttpClient<PaymentClient>(client =>
{
    client.BaseAddress = new Uri("https://payment.example.com");
});

18. Choosing TCP or UDP

Do not choose TCP or UDP simply because one is faster.

First understand the application requirements.

Requirement Possible Choice
Reliable API request TCP based HTTP
Database communication TCP
File transfer TCP
Traditional web application TCP based HTTP
DNS query Often UDP
Real-time gaming traffic UDP may be suitable
Real-time audio or video UDP based protocols may be suitable
HTTP/3 QUIC over UDP

19. Interview Scenario

Interviewer: Why would you choose UDP for a real-time application?

Answer: Real-time applications often prioritize low latency. Some data becomes less useful as time passes, so retransmitting every lost packet may introduce unwanted delay. UDP provides low protocol overhead, while the application or a higher-level protocol can decide how to handle loss, ordering, and recovery.

20. Key Takeaways

  • TCP provides reliable and ordered communication.
  • UDP provides lightweight connectionless datagram delivery.
  • TCP has more protocol overhead than UDP.
  • TCP is commonly used for web applications, APIs, databases, and file transfers.
  • UDP can be useful for real-time communication where latency is critical.
  • UDP does not guarantee delivery or ordering.
  • Higher-level protocols can build reliability on top of UDP.
  • HTTP/3 uses QUIC over UDP.
  • Choose the transport based on application requirements, not simply on speed.

Conclusion

TCP and UDP solve different networking problems. TCP focuses on reliable, ordered communication, while UDP provides lightweight datagram transport with fewer built-in guarantees.

In system design interviews, the important question is not just “TCP or UDP?” but “What does this system require from its network communication?”

The next networking concept is DNS, which explains how a domain such as api.example.com is translated into the server address that the client needs to communicate with.

Comments & Ratings (0)

Log in or create a student account to comment and rate this article.

Be the first to comment on this article.

Never miss a new post 📬

Get an email whenever a new article, project, cheatsheet or video drops.

✅

ℹ️