」工欲善其事,必先利其器。「—孔子《論語.錄靈公》
首頁 > 程式設計 > 網路基礎知識

網路基礎知識

發佈於2024-11-08
瀏覽:222

Network fundamentals

In the world of system design, networks are the glue that binds different components together. Whether you're building a web application, a distributed system, or even a simple backend service, understanding how networks work is key to ensuring smooth communication, security, and performance. In this chapter, we will discuss some core aspects of networking that are crucial for building scalable and reliable systems.


1. Basics of Computer Networks

Let’s start with the foundation. A computer network is a collection of interconnected devices (computers, servers, routers, etc.) that communicate with each other. It’s like the postal system for data: it lets different devices send and receive information in the form of packets. When a user interacts with an online service (say, your food delivery app), these packets are constantly being sent back and forth between their device and the servers that power the app.

Types of Networks:
  1. Local Area Network (LAN): This is a network that connects devices in a limited area like a building or a campus. For example, an office network where computers and printers communicate over a wired or wireless connection. The key feature of a LAN is that it’s fast and usually confined to a small space.

Example: In a typical office, employees’ computers are connected to printers, file servers, and sometimes even phones over a LAN. This setup allows fast sharing of resources.

  1. Wide Area Network (WAN): This covers a broader area and connects multiple LANs. Think of the internet as the largest example of a WAN. It’s how different parts of the world can communicate with each other.

Example: Imagine a large corporation with offices in New York, London, and Tokyo. The offices have LANs internally, but to communicate with each other, they use a WAN, likely leveraging the internet or private connections.

Network Layers and the OSI Model:

To understand how networks operate, we use the OSI Model, which divides networking into seven layers:

  1. Physical Layer: This is the hardware aspect—cables, switches, and wireless transmission.
  2. Data Link Layer: Manages communication between devices on the same local network.
  3. Network Layer: Determines how data packets are sent from one device to another (e.g., routing).
  4. Transport Layer: Ensures reliable transmission of data, manages flow control, and handles errors (this is where TCP operates).
  5. Session Layer: Manages the connection between two devices, ensuring sessions stay open while needed.
  6. Presentation Layer: Translates data formats so that systems understand each other.
  7. Application Layer: Where applications like browsers and email clients operate. This is where the data you interact with comes into play.

Most of the time in system design, we focus on layers 3 to 7, especially when dealing with communication protocols, security, and data flow.


2. HTTP/HTTPS, TCP/IP, DNS, and Load Balancers

HTTP/HTTPS:

HTTP (Hypertext Transfer Protocol) and HTTPS (HTTP Secure) are the primary protocols used for communication on the web. They define how messages are formatted and transmitted between clients (like browsers) and servers.

  • HTTP is the protocol behind the requests you make to websites. For instance, when you load a webpage, your browser makes an HTTP request to the server hosting that webpage, and the server sends back an HTTP response with the page’s contents.

Example: You type "www.fooddelivery.com" in your browser, and it sends an HTTP request to fetch the home page.

  • HTTPS is the secure version of HTTP. It encrypts the data being transmitted, ensuring that sensitive information like passwords and credit card numbers isn’t intercepted by attackers.

Example: When a user places an order on your food delivery app, HTTPS ensures that their payment details are encrypted and secure as they travel from their device to your servers.

TCP/IP:

TCP (Transmission Control Protocol) and IP (Internet Protocol) are two of the fundamental protocols that power the internet.

  • TCP ensures reliable communication between devices. It breaks down messages into packets and ensures they are delivered correctly and in the right order. If packets get lost along the way, TCP retransmits them. This makes it great for applications where data integrity is crucial, like file transfers or web browsing.

Example: If your food delivery app is sending customer details to the server, TCP ensures that the entire message gets delivered without missing any parts.

  • IP is responsible for addressing and routing packets to the correct destination. Think of IP addresses as the addresses on envelopes; they tell the network where to send data.

Example: When you make a request from your phone, it uses your IP address to route data to the server. The server has its own IP address, allowing packets to return to you correctly.

TCP/IP together form the backbone of internet communication. It’s like a reliable postal service: TCP ensures the package contents are intact, and IP ensures it gets to the right place.

DNS (Domain Name System):

DNS is like the internet’s phone book. Instead of remembering IP addresses (which are like phone numbers for servers), we use domain names like "www.example.com." DNS resolves these names into IP addresses, so your device knows where to send the request.

  • Example: When a user types "www.fooddelivery.com" in their browser, their device queries a DNS server to find the IP address associated with that domain, then makes a request to that server.
Load Balancers:

A load balancer is crucial when scaling horizontally. It’s a tool that distributes incoming traffic across multiple servers to ensure no single server is overwhelmed. This makes your system more scalable and fault-tolerant.

  • Example: Imagine it’s lunchtime, and everyone’s trying to place orders on your food delivery app. You have 10 servers ready to handle requests, but instead of all traffic going to one server, the load balancer spreads the requests evenly. This ensures that no one server gets overloaded, preventing downtime and ensuring fast response times for users.

3. Content Delivery Networks (CDN)

CDNs are a brilliant way to reduce latency and improve performance for users spread across different locations. A CDN is a distributed network of servers placed across the globe that store cached versions of your content. When a user requests something from your website, the CDN serves that content from the server closest to them rather than from your main server, reducing the time it takes to load.

Example: Let’s say your food delivery app has customers in India and the U.S., but your main servers are located in Europe. Without a CDN, users in India might experience slow load times because their requests have to travel all the way to Europe. But with a CDN, a server in India can serve cached images, restaurant details, and static content, making the app feel faster.

Benefits of CDNs:
  • Reduced Latency: Since data is served from a server closer to the user, they experience faster load times.
  • Load Distribution: A CDN helps reduce the load on your main servers by offloading requests for static content like images, CSS files, and scripts.
  • Improved Availability: Even if your main servers go down, the CDN can continue serving cached versions of your site, improving availability.

4. SSL, TLS, and Security in Networking

Security is a major concern in any system, and the primary technologies to ensure secure communication over networks are SSL (Secure Sockets Layer) and TLS (Transport Layer Security). These protocols encrypt the data being sent between clients and servers, ensuring that sensitive information, like passwords and payment details, is protected from eavesdroppers.

SSL and TLS:
  • SSL was the original protocol for securing communication, but it has largely been replaced by the more secure TLS. When you see "https://" in the URL of a website, it means that the connection is secured using SSL/TLS.

Example: In your food delivery app, when a user submits their credit card information to make a payment, the data is encrypted using TLS before being sent to the server. This ensures that even if someone intercepts the data, they can’t read it because it’s encrypted.

  • Handshake Process: TLS uses a handshake process to establish a secure connection. The client (user’s browser) and the server exchange cryptographic keys to establish a secure connection. Once the connection is established, all subsequent communication is encrypted.

Example: When a user opens your app, their device and your servers go through this handshake to agree on how to encrypt the data before any sensitive information, like login details or payment info, is transmitted.

Importance of Security in Networking:

In any system where data travels across networks, security is paramount. Here are some key security practices for ensuring a secure system:

  • Encryption: Always encrypt sensitive data in transit using protocols like TLS to prevent man-in-the-middle attacks.
  • Firewall Protection: Use firewalls to restrict access to your servers. Only allow trusted traffic through predefined ports and block unauthorized attempts.
  • API Rate Limiting: Protect your system from DDoS (Distributed Denial of Service) attacks by limiting the number of requests each client can make within a certain time window.

Example: Let’s say a malicious actor tries to overwhelm your food delivery app by sending millions of fake requests. API rate limiting can throttle these requests and prevent the system from crashing.

  • Security Monitoring: Use monitoring tools to detect unusual traffic patterns or potential intrusions. Tools like **Intrusion Detection Systems (

IDS)** can help alert you when there’s an attempt to breach your network.

Certificates:

To enable SSL/TLS, you need an SSL certificate, which verifies the identity of your website or server. Certificates are issued by trusted entities called Certificate Authorities (CAs), which guarantee that your website is legitimate.

Example: When you purchase an SSL certificate for your food delivery app’s domain, it’s issued by a CA like Let’s Encrypt or DigiCert. This tells users that their data is safe and that they’re actually interacting with your app, not an imposter.

Two-Factor Authentication (2FA):

Implementing 2FA is an additional layer of security, requiring users to provide two forms of identification (typically something they know, like a password, and something they have, like a mobile device). This makes it much harder for attackers to compromise accounts.

Example: In your food delivery app, enabling 2FA for users can help prevent unauthorized access even if their password is stolen.

版本聲明 本文轉載於:https://dev.to/jayaprasanna_roddam/network-fundamentals-2c87?1如有侵犯,請聯絡[email protected]刪除
最新教學 更多>
  • ## 如何在 PHP 中即時執行匿名函數?
    ## 如何在 PHP 中即時執行匿名函數?
    在PHP 中立即執行匿名函數在JavaScript 中,使用語法立即定義和執行匿名函數非常簡單:(function () { /* do something */ })()PHP 中是否有類似的機制? PHP 7 在PHP 7 及更高版本中,可以即時、方便地執行匿名函數:(function() {...
    程式設計 發佈於2024-11-08
  • 如何在Go中高效率讀寫CSV檔?
    如何在Go中高效率讀寫CSV檔?
    Go 中高效讀寫 CSV 檔案資料處理中的一個常見任務是以高效能方式讀寫 CSV 檔案。問題中提供的程式碼片段演示了一種讀取 CSV 檔案、處理資料並將其寫回的緩慢方法。潛在的低效率在於在處理之前將整個文件載入到記憶體中的方法。 為了優化程式碼,建議透過呼叫 .Read() 增量讀取檔案並一次處理一...
    程式設計 發佈於2024-11-08
  • 如何處理 Java 中的「無法將給定物件格式化為日期」錯誤?
    如何處理 Java 中的「無法將給定物件格式化為日期」錯誤?
    處理Java 中的「無法將給定物件格式化為日期」錯誤當嘗試將給定日期轉換為特定格式時,Java 開發人員可能會遇到異常: “java.lang.IllegalArgumentException:無法將給定物件格式化為日期。”當嘗試將不受支援的物件格式化為日期時,會出現此錯誤。 要解決此問題,我們需要...
    程式設計 發佈於2024-11-08
  • RPC 操作 EPU 使用 Protobuf 並建立自訂插件
    RPC 操作 EPU 使用 Protobuf 並建立自訂插件
    上一篇文章中,我使用net/rpc包实现了一个简单的RPC接口,并尝试了net/rpc自带的Gob编码和JSON编码,学习了Golang的一些基础知识远程过程调用。在这篇文章中,我将结合 net/rpc 和 protobuf 并创建我的 protobuf 插件来帮助我们生成代码,所以让我们开始吧。 ...
    程式設計 發佈於2024-11-08
  • 無需媒體查詢的響應式佈局
    無需媒體查詢的響應式佈局
    How often do you use media queries when building web layouts? I’ve spent too much time on them! First you spent quite a lot of time trying to make the...
    程式設計 發佈於2024-11-08
  • 使用 JavaScript 更改錨標記 href 屬性時如何防止頁面重新載入?
    使用 JavaScript 更改錨標記 href 屬性時如何防止頁面重新載入?
    點擊按鈕時使用JavaScript更改錨標籤的href屬性在web開發中,需要動態修改錨標籤的href屬性按鈕點擊時常出現錨標籤。以下是使用 JavaScript 實現此目的的方法。 在提供的程式碼片段中,f1() 函數將 ID 為「abc」的元素的 href 屬性變更為「xyz.php」。但是,提...
    程式設計 發佈於2024-11-08
  • 使用 Sheepy 在 Python 中進行單元測試
    使用 Sheepy 在 Python 中進行單元測試
    大家好,今天我来给大家介绍一个新的单元测试库,叫做sheepy,不过首先我们来说说单元测试的重要性。这个库不适合初学者,要使用它进行单元测试,您需要额外注意。它仅具有用于使用端点和 http 错误检查模块进行 API 测试的断言。 Github链接:github PyPi 链接:pypi 生产中所有...
    程式設計 發佈於2024-11-08
  • 為什麼「pch.h」應該成為 C/C++ 專案中的第一個頭檔?
    為什麼「pch.h」應該成為 C/C++ 專案中的第一個頭檔?
    預編譯頭:理解「pch.h」在C和C語言開發中,「pch.h」代表預編譯頭文件。將其作為第一個頭檔包含在編譯速度方面具有顯著的優勢。 什麼是預編譯頭? 預編譯頭是頭的中間形式編譯器產生的檔案。它包含優化編譯過程的編譯訊息,特別是對於大型或大量包含的頭檔。 為什麼包含「pch.h」作為第一個頭檔? 在...
    程式設計 發佈於2024-11-08
  • 探索 JVM 虛擬執行緒機制中的固定
    探索 JVM 虛擬執行緒機制中的固定
    Java 的虚拟线程提供了传统操作系统线程的轻量级替代方案,从而实现了高效的并发管理。但了解他们的行为对于获得最佳表现至关重要。这篇博文深入探讨了固定(一种可能影响虚拟线程执行的场景),并探讨了监控和解决该问题的技术。 虚拟线程:一种轻量级并发方法 Java 的虚拟线程是运行在底层操...
    程式設計 發佈於2024-11-08
  • 如何在不使用分析函數的情況下有效率地選擇 MySQL 中每個類別的前幾行?
    如何在不使用分析函數的情況下有效率地選擇 MySQL 中每個類別的前幾行?
    在MySQL 中選擇每個類別的前幾行要從表中的每個類別中檢索有限數量的行,您可以使用分析函數。然而,MySQL 並不會直接提供這些功能。不過,可以使用變數來模擬它們。 模擬分析函數以下MySQL 查詢模擬分析函數的功能,以選擇每個類別的前3 行:SELECT x.* FROM ( SELEC...
    程式設計 發佈於2024-11-08
  • 了解 JavaScript 中的非同步程式設計:事件循環初學者指南
    了解 JavaScript 中的非同步程式設計:事件循環初學者指南
    Have you ever wondered why some pieces of JavaScript code seem to run out of order? The key to understanding this is the event loop. JavaScript's even...
    程式設計 發佈於2024-11-08
  • 如何使用 multiprocessing.Manager 在多個進程之間共用結果佇列?
    如何使用 multiprocessing.Manager 在多個進程之間共用結果佇列?
    使用multiprocessing.Manager 在多個進程之間共享結果隊列在多處理中,父子進程之間共享隊列對於通訊和結果檢索至關重要。然而,使用 apply_async 啟動非同步工作進程在共享佇列方面提出了挑戰。 為了克服「佇列物件只能透過繼承在進程之間共享」錯誤,我們可以利用 multipr...
    程式設計 發佈於2024-11-08
  • 如何在Visual Studio Code中設定Python調試的工作目錄?
    如何在Visual Studio Code中設定Python調試的工作目錄?
    如何設定使用 VS Code 的調試器調試 Python 程式的工作目錄? 使用 Visual Studio Code 偵錯 Python 程式時 ( VS Code),指定工作目錄對於確保腳本正確運作至關重要。 要在啟動設定檔(launch.json) 中設定工作目錄,請依照下列步驟操作: 開啟l...
    程式設計 發佈於2024-11-08
  • 為什麼 Matplotlib 的動畫程式碼要使用尾隨逗號?
    為什麼 Matplotlib 的動畫程式碼要使用尾隨逗號?
    揭開Matplotlib動畫中的尾隨逗號:它是逗號運算子嗎? 在使用Matplotlib創建簡單動畫的程式碼片段中,變數行後面可以觀察到逗號:line, = ax.plot(x, np.sin(x))這個逗號讓一些開發者感到困惑,導致有人質疑它是否代表逗號運算子。 消除逗號運算子神話此上下文中的尾隨...
    程式設計 發佈於2024-11-08
  • 在 Laravel 中將花式文本標準化為普通文本
    在 Laravel 中將花式文本標準化為普通文本
    文章源自https://medium.com/@hafiqiqmal93/normalizing-fancy-text-to-normal-text-in-laravel-7d9ed56d5a78 使用者輸入的文字一點也不有趣。隨著 Unicode 在智慧型手機中的出現,用戶現在可以奢侈地(有時甚...
    程式設計 發佈於2024-11-08

免責聲明: 提供的所有資源部分來自互聯網,如果有侵犯您的版權或其他權益,請說明詳細緣由並提供版權或權益證明然後發到郵箱:[email protected] 我們會在第一時間內為您處理。

Copyright© 2022 湘ICP备2022001581号-3