개발일지/ETC

[AWS] Protocol & Load Balancer

은기조아 2025. 3. 3. 15:31

Load Balancer

Load Balancer에 대해 공부하면서, 이를 더욱 잘 이해하기 위해 HTTP Protocol 및 Network Layer에 대한 개념을 한 번 정리해야겠다는 생각이 들었다. AI Researcher로 몇년 간 근무하면서, 최근 들어 더더욱 컴공 기초 지식, 하드웨어, 네트워크 지식 등이 매우 부족하다는 점을 깨닫는다. 학습 메모리 효율화를 위한 대표적인 방법으로 Mixed Precision이란 개념이 있는데, 아마 이 개념을 접하기 시작하면서부터 점점 커져왔던 마음 속 불편함이 있었다. LLM을 학습하면서도 분산학습을 진행하게 되는데, GPU 간 통신 (NCCL backend 등) 기법 등과 같이 네트워크에 대한 정밀한 이해 없이는 알 수 없는 개념을 접하게 되면서 이제는 무시할 수 없을 정도로 그 불편함이 매일 밤 악몽으로 찾아온다. 

악몽을 퇴치하기 위해 먼저 프로토콜에 대한 기초 개념부터 공부해보자.

 

(요즘은 직접 개념을 찾아서 공부하는 것보다, 소크라테스 문답법처럼 ChatGPT를 활용하여 모르는 부분에 대해 그때 그때 질문하면서 답을 얻는 방식을 더욱 선호하게 되었다. Hallucination 등에 대한 우려는 여전히 존재하지만, Hallucination 비율이 점차 줄어드는 요즘 꽤 신뢰할 만한 콘텐츠를 출력해주는 것 같아 아주 잘 사용하고 있다.)

 

(나중에는 Hallucination을 감지하는 모델을 한 번 만들어보는 시도를 해보아야겠다. 참으로 하고 싶은 게 많은 요즘인데 시간이 부족하여 TO-DO-LIST만 늘어나는 느낌이다.)


HTTP Protocol & AWS Load Balancer

 

1. HTTP, HTTPS, TCP, SSL, Secure TCP

These are different protocols used for communication between clients and servers.

HTTP (HyperText Transfer Protocol)

  • A protocol used for communication between a client (e.g., a web browser) and a web server.
  • It is stateless, meaning each request is independent.
  • Example: When you visit http://example.com, your browser sends an HTTP request to the server, which responds with an HTML page.

HTTPS (HTTP Secure)

  • The secure version of HTTP that uses SSL/TLS to encrypt data.
  • Prevents eavesdropping and MITM (Man-In-The-Middle) attacks.
  • Example: Online banking websites like https://bank.com encrypt your login credentials so attackers can't intercept them.

TCP (Transmission Control Protocol)

  • A connection-oriented protocol that ensures reliable, ordered, and error-checked delivery of data.
  • Used in applications that require guaranteed data transmission.
  • Example: When you send an email via SMTP or access a website via HTTPS, TCP ensures all packets arrive correctly and in order.
더보기

What Are Packets?

A packet is a small unit of data sent over a network. When you send information over the internet (like loading a webpage or streaming a video), your data is broken into smaller chunks called packets. These packets travel independently and are reassembled at their destination.


🔹 How Packets Work

  1. Data is Split:
    • If you send a 5MB file, it doesn’t go as one big chunk. Instead, it’s broken into thousands of small packets (each usually 1,500 bytes or less).
  2. Each Packet Contains:
    • Header → Contains metadata (source/destination IP, sequence number).
    • Payload → The actual data (e.g., part of an email or video frame).
    • Trailer → Used for error checking.
  3. Packets Take Different Paths:
    • Each packet can take a different route across the network.
    • Routers guide them toward the destination.
  4. Reassembly at Destination:
    • The receiving computer collects all packets and reassembles them in the correct order.

🔹 Real-World Example

Scenario: Watching a YouTube Video

  • The video file is broken into packets and sent over the internet.
  • Some packets take different paths to avoid congestion.
  • Your device receives and reassembles them to play the video smoothly.

🔹 Packet Transport Protocols

  • TCP (Transmission Control Protocol) → Reliable, ensures packets arrive in order.
  • UDP (User Datagram Protocol) → Faster but doesn’t guarantee all packets arrive (used for gaming & streaming).

Conclusion

Packets are the fundamental building blocks of data transmission on the internet. They allow efficient, fast, and reliable communication, even across long distances. 🚀

SSL (Secure Sockets Layer) / TLS (Transport Layer Security)

  • Cryptographic protocols that encrypt TCP traffic for security.
  • TLS is the modern replacement for SSL.
  • Example: A secured connection between a browser and https://amazon.com uses TLS to encrypt sensitive data like passwords.

Secure TCP

  • Often refers to TCP connections secured by TLS/SSL.
  • Ensures confidentiality, integrity, and authentication of data.
  • Example: When a user accesses an AWS Elastic Load Balancer (ELB) with HTTPS, the communication is encrypted via Secure TCP.

2. WebSocket

  • A full-duplex protocol that allows continuous two-way communication between a client and a server over a single TCP connection.
  • Unlike HTTP, it keeps the connection open, reducing latency.
  • Example: A real-time chat application like WhatsApp Web uses WebSockets to update messages instantly.

AWS Load Balancer & WebSockets

  • Application Load Balancer (ALB) supports WebSockets, allowing real-time applications to function smoothly.
  • Example: A stock trading dashboard uses WebSockets through ALB to stream real-time price updates.

3. UDP (User Datagram Protocol)

  • A connectionless, lightweight alternative to TCP.
  • Faster but unreliable (no retransmissions if packets are lost).
  • Used in real-time applications where speed matters more than reliability.
  • Example: Online gaming (e.g., Fortnite) and VoIP calls (e.g., Zoom) use UDP to ensure low-latency communication.

AWS Load Balancer & UDP

  • AWS Network Load Balancer (NLB) supports UDP-based services.
  • Example: If you host a VoIP server on AWS, NLB distributes UDP traffic efficiently to backend servers.

4. Layer 3 - Network Layer

  • This is the third layer in the OSI model, responsible for routing and forwarding packets.
  • Uses IP addresses to determine the best path for data.
  • Example: When you send a request from your home Wi-Fi to google.com, the packet is routed through multiple network devices (routers) at Layer 3.
더보기

The network layer is part of the OSI model, which is a conceptual framework that describes how data moves across a network. The OSI model has 7 layers, each handling different aspects of communication.


🖥️ OSI Model: The 7 Layers

LayerNameFunctionExample Protocols/Technologies
7 Application Layer User interaction & application-level services HTTP, HTTPS, FTP, SMTP, WebSockets
6 Presentation Layer Data translation, encryption, compression SSL/TLS, JPEG, ASCII, MPEG
5 Session Layer Manages connections (start, maintain, end) WebSockets, NetBIOS, RPC
4 Transport Layer Ensures data delivery (error checking, retransmission) TCP, UDP
3 Network Layer Routing & forwarding, IP addressing IP, ICMP (ping), OSPF, BGP
2 Data Link Layer MAC addressing, error detection, direct device-to-device communication Ethernet, Wi-Fi, ARP, PPP
1 Physical Layer Physical transmission of data (bits) via cables/wireless Fiber optics, Copper cables, Radio waves

📌 Breakdown of Each Layer

1️⃣ Physical Layer (Layer 1)

  • Deals with raw data transmission over cables, fiber optics, or radio waves.
  • Converts bits (0s & 1s) into electrical signals, light pulses, or radio waves.
  • Example: Ethernet cables, Wi-Fi signals, Bluetooth.

2️⃣ Data Link Layer (Layer 2)

  • Transfers data between directly connected devices.
  • Uses MAC (Media Access Control) addresses for device identification.
  • Detects and corrects basic transmission errors.
  • Example: Ethernet (LAN), Wi-Fi (802.11), MAC addresses.

3️⃣ Network Layer (Layer 3)

  • Handles routing & forwarding of packets across networks.
  • Uses IP addresses (not MAC addresses) to identify devices across the internet.
  • Determines the best path for packets using routers.
  • Example: The Internet Protocol (IP), routers, ICMP (ping).

🛠 Real-World Example:

  • If you access google.com, your request is broken into packets.
  • The packets travel through multiple routers to reach Google’s server.
  • Google’s response packets follow the best route back to you.

4️⃣ Transport Layer (Layer 4)

  • Ensures reliable or fast delivery of packets.
  • TCP (Transmission Control Protocol): Reliable, error-checked (e.g., HTTPS, Email).
  • UDP (User Datagram Protocol): Fast, but no guarantee of delivery (e.g., Gaming, Video Streaming).

🛠 Real-World Example:

  • TCP ensures an entire webpage is received correctly.
  • UDP is used in live video streaming, where some data loss is acceptable.

5️⃣ Session Layer (Layer 5)

  • Manages sessions (start, maintain, close connections) between applications.
  • Used for WebSockets, Remote Procedure Calls (RPC).
  • Example: If you open multiple tabs of youtube.com, sessions manage them separately.

6️⃣ Presentation Layer (Layer 6)

  • Converts data into a format applications understand.
  • Handles encryption & decryption (SSL/TLS).
  • Example: HTTPS uses TLS encryption (Layer 6) before transmitting data over TCP (Layer 4).

7️⃣ Application Layer (Layer 7)

  • Direct interaction with the user.
  • Defines protocols for web, email, file transfer, etc..
  • Example: HTTP, WebSockets, FTP, SMTP (email).

📌 How AWS Load Balancers Fit into the OSI Model

  1. Application Load Balancer (ALB) → Layer 7 (HTTP, HTTPS, WebSockets).
  2. Network Load Balancer (NLB) → Layer 4 (TCP, UDP).
  3. Classic Load Balancer (CLB) → Can work at Layer 4 & Layer 7.

🔹 Summary

  • The OSI Model has 7 layers, with Layer 3 (Network Layer) handling IP routing.
  • Layer 3 (Network Layer) ensures packets reach the right destination.
  • AWS ALB (Layer 7) is for HTTP/HTTPS, and AWS NLB (Layer 4) is for TCP/UDP.

AWS Load Balancer & Layer 3

  • AWS Network Load Balancer (NLB) operates at Layer 3, routing TCP and UDP traffic based on IP addresses.
  • Example: A company uses NLB to balance requests to a fleet of VPN servers handling secure remote access.

Conclusion

AWS provides different load balancers for various protocols:

  • Application Load Balancer (ALB) → HTTP, HTTPS, WebSockets (Layer 7)
  • Network Load Balancer (NLB) → TCP, Secure TCP, UDP (Layer 3 & 4)
  • Classic Load Balancer (CLB) → Legacy support for HTTP, HTTPS, TCP, SSL