← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

TCP vs UDP

Networking Intermediate
debt(d9/e5/b3/t5)
d9 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'silent in production until users hit it' (d9). The detection_hints explicitly state 'automated: no' and describe confusion patterns (e.g., using UDP for reliable data transfer without ACK/retry where data loss is silent, or misunderstanding QUIC). No tools in detection_hints.tools can catch these protocol choice errors; they manifest only at runtime as dropped packets, failed DNS queries, or mysterious data loss under real network conditions.

e5 Effort Remediation debt — work required to fix once spotted

Closest to 'touches multiple files / significant refactor in one component' (e5). The quick_fix is conceptual rather than a single-line swap. Correcting a wrong protocol choice in PHP socket code (e.g., switching from TCP to UDP for DNS, or adding ACK/retry logic for UDP-based reliable transfer) requires changes across socket initialization, error handling, and potentially application-layer retry logic. It's not a single-line patch but not a full architectural rework either.

b3 Burden Structural debt — long-term weight of choosing wrong

Closest to 'localised tax' (b3). The applies_to scope is web and cli contexts, but the choice of TCP vs UDP is typically confined to specific socket-programming components (DNS resolver code, WebSocket setup, or real-time feature implementation) rather than permeating the entire codebase. Most PHP web app code never touches raw socket protocol selection.

t5 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'notable trap' (t5). The misconception field documents the canonical trap: 'UDP is always faster than TCP' — a widely believed but conditionally false claim. Additionally, the common_mistakes list the silent data loss when using UDP without ACK/retry and the non-obvious fact that QUIC (HTTP/3) is UDP with reimplemented reliability. These are documented gotchas that intermediate developers commonly encounter but aren't catastrophically counterintuitive.

About DEBT scoring →

Also Known As

TCP UDP connectionless reliable delivery

TL;DR

TCP provides reliable ordered delivery with connection setup overhead. UDP is connectionless and faster but unreliable — choose based on whether loss or latency is more acceptable.

Explanation

TCP (Transmission Control Protocol): connection-oriented (three-way handshake), guaranteed delivery (retransmission on loss), ordered packets, congestion control. Use for: HTTP/HTTPS, database connections, email, file transfers. UDP (User Datagram Protocol): connectionless, fire-and-forget, no guaranteed delivery, no ordering. Use for: DNS, video streaming, online games, VoIP, QUIC/HTTP3. The trade-off: TCP's reliability costs latency; UDP's speed costs reliability. Applications that can handle loss (real-time audio) prefer UDP; applications that cannot (banking) require TCP.

Common Misconception

UDP is always faster than TCP — UDP has less overhead per packet, but TCP's congestion control and flow control often make it more efficient on real networks; raw speed depends on the network conditions.

Why It Matters

Choosing TCP vs UDP matters for PHP socket programming, DNS resolvers, real-time features (WebRTC), and understanding why QUIC (HTTP/3) uses UDP but reimplements reliability at the application layer.

Common Mistakes

  • Using TCP for DNS queries — UDP is standard (less overhead for small queries).
  • Using UDP for reliable data transfer without implementing your own ACK/retry — data loss is silent.
  • Not understanding that QUIC is UDP with reliability — HTTP/3's UDP doesn't mean unreliable.
  • PHP stream sockets default to TCP — explicitly specify udp:// for UDP socket programming.

Code Examples

✗ Vulnerable
// UDP for order confirmation — data can be silently lost:
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_sendto($socket, $orderConfirmation, strlen($orderConfirmation), 0,
    '10.0.0.1', 9000);
// Fire and forget — confirmation may never arrive
// Customer never gets their order update
✓ Fixed
// TCP for reliable delivery of business data:
$socket = stream_socket_client('tcp://10.0.0.1:9000');
fwrite($socket, $orderConfirmation);
// TCP guarantees delivery — retransmits on loss

// UDP appropriate for real-time metrics:
$socket = socket_create(AF_INET, SOCK_DGRAM, SOL_UDP);
socket_sendto($socket, $metric, strlen($metric), 0, $statsd_host, 8125);
// StatsD: dropped metrics are fine — stream of data not individual records

Added 16 Mar 2026
Edited 22 Mar 2026
Views 37
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 1 ping T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 0 pings M 1 ping T 1 ping W 0 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 1 ping T 0 pings W
No pings yet today
Google 1
Amazonbot 9 Perplexity 4 Ahrefs 4 Google 3 ChatGPT 2 Scrapy 2 Claude 1 Meta AI 1 PetalBot 1
crawler 24 crawler_json 3
DEV INTEL Tools & Severity
🔵 Info ⚙ Fix effort: Low
⚡ Quick Fix
PHP web apps use TCP (HTTP) — understanding TCP vs UDP explains why HTTP/3 uses UDP (QUIC) for performance and why WebSockets are TCP while some real-time games use UDP
📦 Applies To
any web cli
🔗 Prerequisites
🔍 Detection Hints
Confusion about why HTTP/3 uses UDP; misunderstanding of connection state in PHP-FPM
Auto-detectable: ✗ No
⚠ Related Problems
🤖 AI Agent
Confidence: Low False Positives: High ✗ Manual fix Fix: Low Context: File


✓ schema.org compliant