Logo
Section 1 / 5

分布式系统中的核心网络协议

学习核心网络协议(如 TCP、UDP 和 HTTP)如何成为设计健壮且可扩展的分布式系统的基础。

导入

分布式系统中的核心网络协议

学习核心网络协议(如 TCP、UDP 和 HTTP)如何成为设计健壮且可扩展的分布式系统的基础。

...
Basic communication flow between a client and a server
...
An HTTP GET request and response

HTTP request format

1POST /articles/index.html HTTP/1.1 2Host: www.example.com 3Connection: Keep-Alive 4User-Agent: Mozilla/5.0 5Content-Type: application/json 6Content-Length: 80 7Accept-Language: en-us 8Accept-Encoding: gzip, deflate 9{ 10 "Id": 45321, 11 "Customer": "Mark Brown", 12 "Quantity": 10, 13 "Price": 199.0 14}

HTTP response format

1// Status code 2HTTP/1.1 200 OK 3//Headers 4Connection: close 5Date: Thu, 15 Sep 2025 13:22:33 GMT 6Server: Apache/2.2.3 (CentOS) 7Last-Modified: Thu, 15 Sep 2025 13:22:18 GMT 8Content-Length: <number of characters> 9Content-Type: application/json 10//Body 11{ 12 data... 13}

HTTP methods like GET, PUT, and DELETE are expected to be idempotent. This means making the same request multiple times has the same effect as making it once, a critical property for building fault-tolerant systems that may need to retry failed requests.

Table

VersionMethods SupportedSupport for headersConnection NatureOther Features
HTTP/0.9GET onlyNoClosed after responseOnly supports hypertext
HTTP/1.0HEAD, GET, POSTYesClosed after responseSupports hypertext, hypermedia, and files
HTTP/1.1HEAD, GET, POST, PUT, DELETE, TRACE, OPTIONSYesPersistentExtended methods, pipelining, encoding, virtual hosting, upgrade header, cache headers
HTTP/2.0HEAD, GET, POST, PUT, DELETE, TRACE, OPTIONSYesPersistentMultiplexing, header compression, backward compatibility
HTTP/3.0HEAD, GET, POST, PUT, DELETE, TRACE, OPTIONSYesPersistentBuilt on QUIC (over UDP), avoids head-of-line blocking, ~3× faster than HTTP/1.1
...
TCP’s reliable, connection-oriented flow vs. UDP’s best-effort, connectionless flow

Table

FeatureTransmission Control Protocol (TCP)User Datagram Protocol (UDP)
ReliabilityHigh, guaranteed deliveryLow, best-effort delivery
ConnectionConnection-oriented (three-way handshake)Connectionless
OrderingGuarantees that packets are delivered in orderNo ordering guarantees
SpeedSlower, due to overhead from acknowledgments and orderingFaster, with minimal overhead
Header size20 bytes minimum (can be larger with options)8 bytes (fixed)
Common use casesWeb (HTTPS), file transfers (FTP), email (SMTP)Streaming, online gaming, DNS, VoIP

The OSI Model is a conceptual framework that organizes network communication into seven layers. It provides a common language for understanding and troubleshooting networks, but it is rarely implemented directly in real-world systems. It consists of the following seven layers:

  1. Application: Defines how applications communicate (HTTP, FTP, SMTP).
  2. Presentation: Translates data formats, handles compression and encryption (SSL/TLS).
  3. Session: Manages sessions and dialog control between systems.
  4. Transport: Ensures reliable or fast delivery (TCP, UDP).
  5. Network: Handles addressing and routing (IP).
  6. Data Link: Transfers data on the same local network (Ethernet, Wi-Fi).
  7. Physical: The hardware signals and media (fiber, copper, radio).

The OSI Model is a conceptual framework that organizes network communication into seven layers. It provides a common language for understanding and troubleshooting networks, but it is rarely implemented directly in real-world systems. It consists of the following seven layers:

  1. Application: Defines how applications communicate (HTTP, FTP, SMTP).
  2. Presentation: Translates data formats, handles compression and encryption (SSL/TLS).
  3. Session: Manages sessions and dialog control between systems.
  4. Transport: Ensures reliable or fast delivery (TCP, UDP).
  5. Network: Handles addressing and routing (IP).
  6. Data Link: Transfers data on the same local network (Ethernet, Wi-Fi).
  7. Physical: The hardware signals and media (fiber, copper, radio).
...
End-to-end traffic flow, showing how protocols at different layers work together

Table

TCP/IP LayerCommon ProtocolsSystem Design Relevance
ApplicationHTTP, gRPC, WebSocketAPI design, service communication patterns
TransportTCP, UDPThe core trade-off between reliability and speed
InternetIP, ICMPUnderstanding network topology and routing
LinkEthernet, Wi-FiHandled by network infrastructure

Coming soon to support pageflux-note

分布式系统基础

分布式系统中的同步与异步通信