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

網路基礎知識

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

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陣列鍵值異常:了解07和08的好奇情況
    PHP陣列鍵值異常:了解07和08的好奇情況
    PHP數組鍵值問題,使用07&08 在給定數月的數組中,鍵值07和08呈現令人困惑的行為時,就會出現一個不尋常的問題。運行print_r($月)返回意外結果:鍵“ 07”丟失,而鍵“ 08”分配給了9月的值。 此問題源於PHP對領先零的解釋。當一個數字帶有0(例如07或08)的前綴時,PHP將...
    程式設計 發佈於2025-07-13
  • 版本5.6.5之前,使用current_timestamp與時間戳列的current_timestamp與時間戳列有什麼限制?
    版本5.6.5之前,使用current_timestamp與時間戳列的current_timestamp與時間戳列有什麼限制?
    在時間戳列上使用current_timestamp或MySQL版本中的current_timestamp或在5.6.5 此限制源於遺留實現的關注,這些限制需要對當前的_timestamp功能進行特定的實現。 創建表`foo`( `Productid` int(10)unsigned not ...
    程式設計 發佈於2025-07-13
  • 如何使用不同數量列的聯合數據庫表?
    如何使用不同數量列的聯合數據庫表?
    合併列數不同的表 當嘗試合併列數不同的數據庫表時,可能會遇到挑戰。一種直接的方法是在列數較少的表中,為缺失的列追加空值。 例如,考慮兩個表,表 A 和表 B,其中表 A 的列數多於表 B。為了合併這些表,同時處理表 B 中缺失的列,請按照以下步驟操作: 確定表 B 中缺失的列,並將它們添加到表的...
    程式設計 發佈於2025-07-13
  • Go web應用何時關閉數據庫連接?
    Go web應用何時關閉數據庫連接?
    在GO Web Applications中管理數據庫連接很少,考慮以下簡化的web應用程序代碼:出現的問題:何時應在DB連接上調用Close()方法? ,該特定方案將自動關閉程序時,該程序將在EXITS EXITS EXITS出現時自動關閉。但是,其他考慮因素可能保證手動處理。 選項1:隱式關閉終...
    程式設計 發佈於2025-07-13
  • 在UTF8 MySQL表中正確將Latin1字符轉換為UTF8的方法
    在UTF8 MySQL表中正確將Latin1字符轉換為UTF8的方法
    在UTF8表中將latin1字符轉換為utf8 ,您遇到了一個問題,其中含義的字符(例如,“jáuòiñe”)在utf8 table tabled tablesset中被extect(例如,“致電。為了解決此問題,您正在嘗試使用“ mb_convert_encoding”和“ iconv”轉換受...
    程式設計 發佈於2025-07-13
  • 編譯器報錯“usr/bin/ld: cannot find -l”解決方法
    編譯器報錯“usr/bin/ld: cannot find -l”解決方法
    錯誤:“ usr/bin/ld:找不到-l “ 此錯誤表明鏈接器在鏈接您的可執行文件時無法找到指定的庫。為了解決此問題,我們將深入研究如何指定庫路徑並將鏈接引導到正確位置的詳細信息。 添加庫搜索路徑的一個可能的原因是,此錯誤是您的makefile中缺少庫搜索路徑。要解決它,您可以在鏈接器命令中添...
    程式設計 發佈於2025-07-13
  • 圖片在Chrome中為何仍有邊框? `border: none;`無效解決方案
    圖片在Chrome中為何仍有邊框? `border: none;`無效解決方案
    在chrome 在使用Chrome and IE9中的圖像時遇到的一個頻繁的問題是圍繞圖像的持續薄薄邊框,儘管指定了圖像,儘管指定了;和“邊境:無;”在CSS中。要解決此問題,請考慮以下方法: Chrome具有忽略“ border:none; none;”的已知錯誤,風格。要解決此問題,請使用以下...
    程式設計 發佈於2025-07-13
  • 如何使用Python理解有效地創建字典?
    如何使用Python理解有效地創建字典?
    在python中,詞典綜合提供了一種生成新詞典的簡潔方法。儘管它們與列表綜合相似,但存在一些顯著差異。 與問題所暗示的不同,您無法為鑰匙創建字典理解。您必須明確指定鍵和值。 For example:d = {n: n**2 for n in range(5)}This creates a dict...
    程式設計 發佈於2025-07-13
  • 為什麼不````''{margin:0; }`始終刪除CSS中的最高邊距?
    為什麼不````''{margin:0; }`始終刪除CSS中的最高邊距?
    在CSS 問題:不正確的代碼: 全球範圍將所有餘量重置為零,如提供的代碼所建議的,可能會導致意外的副作用。解決特定的保證金問題是更建議的。 例如,在提供的示例中,將以下代碼添加到CSS中,將解決餘量問題: body H1 { 保證金頂:-40px; } 此方法更精確,避免了由全局保證金重置...
    程式設計 發佈於2025-07-13
  • 為什麼PHP的DateTime :: Modify('+1個月')會產生意外的結果?
    為什麼PHP的DateTime :: Modify('+1個月')會產生意外的結果?
    使用php dateTime修改月份:發現預期的行為在使用PHP的DateTime類時,添加或減去幾個月可能並不總是會產生預期的結果。正如文檔所警告的那樣,“當心”這些操作的“不像看起來那樣直觀。 ; $ date->修改('1個月'); //前進1個月 echo $ date->...
    程式設計 發佈於2025-07-13
  • 我可以將加密從McRypt遷移到OpenSSL,並使用OpenSSL遷移MCRYPT加密數據?
    我可以將加密從McRypt遷移到OpenSSL,並使用OpenSSL遷移MCRYPT加密數據?
    將我的加密庫從mcrypt升級到openssl 問題:是否可以將我的加密庫從McRypt升級到OpenSSL?如果是這樣,如何? 答案:是的,可以將您的Encryption庫從McRypt升級到OpenSSL。 可以使用openssl。 附加說明: [openssl_decrypt()函數要求...
    程式設計 發佈於2025-07-13
  • 如何在無序集合中為元組實現通用哈希功能?
    如何在無序集合中為元組實現通用哈希功能?
    在未訂購的集合中的元素要糾正此問題,一種方法是手動為特定元組類型定義哈希函數,例如: template template template 。 struct std :: hash { size_t operator()(std :: tuple const&tuple)const {...
    程式設計 發佈於2025-07-13
  • Java數組中元素位置查找技巧
    Java數組中元素位置查找技巧
    在Java數組中檢索元素的位置 利用Java的反射API將數組轉換為列表中,允許您使用indexof方法。 (primitives)(鏈接到Mishax的解決方案) 用於排序陣列的數組此方法此方法返回元素的索引,如果發現了元素的索引,或一個負值,指示應放置元素的插入點。
    程式設計 發佈於2025-07-13
  • 如何修復\“常規錯誤:2006 MySQL Server在插入數據時已經消失\”?
    如何修復\“常規錯誤:2006 MySQL Server在插入數據時已經消失\”?
    How to Resolve "General error: 2006 MySQL server has gone away" While Inserting RecordsIntroduction:Inserting data into a MySQL database can...
    程式設計 發佈於2025-07-13
  • Spark DataFrame添加常量列的妙招
    Spark DataFrame添加常量列的妙招
    在Spark Dataframe ,將常數列添加到Spark DataFrame,該列具有適用於所有行的任意值的Spark DataFrame,可以通過多種方式實現。使用文字值(SPARK 1.3)在嘗試提供直接值時,用於此問題時,旨在為此目的的column方法可能會導致錯誤。 df.withCo...
    程式設計 發佈於2025-07-13

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

Copyright© 2022 湘ICP备2022001581号-3