应用网络基础指南
ByteByteGo 文章以电商调用订单 API 为例,讲解 DNS、负载均衡、HTTP、TCP 与 TLS 握手等应用网络基础概念。
中文处理结果
设想一个简单场景:一个电商 Web 应用调用某个 API 端点,该端点返回客户订单信息。
在应用层面,这看起来是相当简单的操作。但底层其实发生了很多事情。首先,客户端向 DNS 查询与该 API 端点关联的 IP 地址。DNS 可能返回负载均衡器的地址,而不是某台具体应用服务器的地址。随后操作系统决定数据包应如何发送到该 IP 地址。它可能选择通过本地网络、互联网服务提供商(ISP)或若干其他路由器发送。最终目标是让数据包到达目的网络。
用于此目的的最常见协议是 HTTP。然而,在 HTTP 能够发送请求之前,客户端通常需要与目标服务器建立某种形式的连接。
在传统 HTTPS 中,这意味着建立 TCP 连接。在这种连接中,客户端与服务器通过交换一些初始数据包进行握手,使双方都知道连接已经建立。随后客户端与服务器执行 TLS 握手。只有在这之后,HTTP 请求才能被安全地发送。负载均衡器接收该请求,选择一个健康的应用程序实例,并转发请求。应用程序完成其工作,并沿同一路径把响应发回。
所有这些都属于网络领域。由于其无处不在的特性,网络成为开发者必须掌握的一门极其重要的学科。在本文中,我们将详细探讨网络的各个方面。
网络相关的基本词汇
阅读更多
原始正文摘录
A Guide to Application Networking Basics
Imagine a simple scenario where an e-commerce web application calls an API endpoint that returns information about a customer order.
At the application level, this looks like a pretty simple operation. But a lot is happening under the hood. First, the client queries the DNS for the IP address linked to the API endpoint. DNS might return the address of a load balancer rather than the address of a specific application server. The operating system then determines how packets should be sent to that IP address. It might choose to send them through the local network, an internet service provider (ISP), or several other routers. The ultimate goal is for the data packets to reach the destination network.
The most common protocol used for this is HTTP. However, before HTTP can send the request, the client usually needs to establish some form of connection with the destination server.
With traditional HTTPS, this means setting up a TCP connection. In this type of connection, the client and server perform a handshake by exchanging some initial packets so that both sides know a connection has been established. The client and server then perform a TLS handshake. Only after this can the HTTP request be sent securely. A load balancer receives it, selects a healthy application instance, and forwards the request. The application performs its work and sends the response back through the same path.
All of this falls under the realm of networking. Due to its ubiquitous nature, networking becomes an extremely important discipline for developers to master. In this article, we will look at the various aspects of networking in detail.
The Basic Vocabulary Around Networking
Read more