”工欲善其事,必先利其器。“—孔子《论语.录灵公》
首页 > 编程 > 网络基础知识

网络基础知识

发布于2024-11-08
浏览:391

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]删除
最新教程 更多>
  • 如何使用“ JSON”软件包解析JSON阵列?
    如何使用“ JSON”软件包解析JSON阵列?
    parsing JSON与JSON软件包 QUALDALS:考虑以下go代码:字符串 } func main(){ datajson:=`[“ 1”,“ 2”,“ 3”]`` arr:= jsontype {} 摘要:= = json.unmarshal([] byte(...
    编程 发布于2025-07-21
  • 如何将多种用户类型(学生,老师和管理员)重定向到Firebase应用中的各自活动?
    如何将多种用户类型(学生,老师和管理员)重定向到Firebase应用中的各自活动?
    Red: How to Redirect Multiple User Types to Respective ActivitiesUnderstanding the ProblemIn a Firebase-based voting app with three distinct user type...
    编程 发布于2025-07-21
  • 如何从PHP中的Unicode字符串中有效地产生对URL友好的sl。
    如何从PHP中的Unicode字符串中有效地产生对URL友好的sl。
    为有效的slug生成首先,该函数用指定的分隔符替换所有非字母或数字字符。此步骤可确保slug遵守URL惯例。随后,它采用ICONV函数将文本简化为us-ascii兼容格式,从而允许更广泛的字符集合兼容性。接下来,该函数使用正则表达式删除了不需要的字符,例如特殊字符和空格。此步骤可确保slug仅包含...
    编程 发布于2025-07-21
  • 如何克服PHP的功能重新定义限制?
    如何克服PHP的功能重新定义限制?
    克服PHP的函数重新定义限制在PHP中,多次定义一个相同名称的函数是一个no-no。尝试这样做,如提供的代码段所示,将导致可怕的“不能重新列出”错误。 但是,PHP工具腰带中有一个隐藏的宝石:runkit扩展。它使您能够灵活地重新定义函数。 runkit_function_renction_re...
    编程 发布于2025-07-21
  • C++成员函数指针正确传递方法
    C++成员函数指针正确传递方法
    如何将成员函数置于c [&& && && && && && && && && && &&&&&&&&&&&&&&&&&&&&&&&华仪的函数时,在接受成员函数指针的函数时,要在函数上既要提供指针又可以提供指针和指针到函数的函数。需要具有一定签名的功能指针。要通过成员函数,您需要同时提供对象指针(此...
    编程 发布于2025-07-21
  • Java中Lambda表达式为何需要“final”或“有效final”变量?
    Java中Lambda表达式为何需要“final”或“有效final”变量?
    Lambda Expressions Require "Final" or "Effectively Final" VariablesThe error message "Variable used in lambda expression shou...
    编程 发布于2025-07-21
  • Python中何时用"try"而非"if"检测变量值?
    Python中何时用"try"而非"if"检测变量值?
    使用“ try“ vs.” if”来测试python 在python中的变量值,在某些情况下,您可能需要在处理之前检查变量是否具有值。在使用“如果”或“ try”构建体之间决定。“ if” constructs result = function() 如果结果: 对于结果: ...
    编程 发布于2025-07-21
  • MySQL中如何高效地根据两个条件INSERT或UPDATE行?
    MySQL中如何高效地根据两个条件INSERT或UPDATE行?
    在两个条件下插入或更新或更新 solution:的答案在于mysql的插入中...在重复键更新语法上。如果不存在匹配行或更新现有行,则此功能强大的功能可以通过插入新行来进行有效的数据操作。如果违反了唯一的密钥约束。实现所需的行为,该表必须具有唯一的键定义(在这种情况下为'名称'...
    编程 发布于2025-07-21
  • 如何高效地在一个事务中插入数据到多个MySQL表?
    如何高效地在一个事务中插入数据到多个MySQL表?
    mySQL插入到多个表中,该数据可能会产生意外的结果。虽然似乎有多个查询可以解决问题,但将从用户表的自动信息ID与配置文件表的手动用户ID相关联提出了挑战。使用Transactions和last_insert_id() 插入用户(用户名,密码)值('test','test...
    编程 发布于2025-07-21
  • 如何为PostgreSQL中的每个唯一标识符有效地检索最后一行?
    如何为PostgreSQL中的每个唯一标识符有效地检索最后一行?
    postgresql:为每个唯一标识符提取最后一行,在Postgresql中,您可能需要遇到与在数据库中的每个不同标识相关的信息中提取信息的情况。考虑以下数据:[ 1 2014-02-01 kjkj 在数据集中的每个唯一ID中检索最后一行的信息,您可以在操作员上使用Postgres的有效效率: ...
    编程 发布于2025-07-21
  • Async Void vs. Async Task在ASP.NET中:为什么Async Void方法有时会抛出异常?
    Async Void vs. Async Task在ASP.NET中:为什么Async Void方法有时会抛出异常?
    在ASP.NET async void void async void void void void void的设计无需返回asynchroncon而无需返回任务对象。他们在执行过程中增加未偿还操作的计数,并在完成后减少。在某些情况下,这种行为可能是有益的,例如未期望或明确预期操作结果的火灾和...
    编程 发布于2025-07-21
  • 编译器报错“usr/bin/ld: cannot find -l”解决方法
    编译器报错“usr/bin/ld: cannot find -l”解决方法
    错误:“ usr/bin/ld:找不到-l “ 此错误表明链接器在链接您的可执行文件时无法找到指定的库。为了解决此问题,我们将深入研究如何指定库路径并将链接引导到正确位置的详细信息。添加库搜索路径的一个可能的原因是,此错误是您的makefile中缺少库搜索路径。要解决它,您可以在链接器命令中添加...
    编程 发布于2025-07-21
  • 在JavaScript中如何并发运行异步操作并正确处理错误?
    在JavaScript中如何并发运行异步操作并正确处理错误?
    同意操作execution 在执行asynchronous操作时,相关的代码段落会遇到一个问题,当执行asynchronous操作:此实现在启动下一个操作之前依次等待每个操作的完成。要启用并发执行,需要进行修改的方法。 第一个解决方案试图通过获得每个操作的承诺来解决此问题,然后单独等待它们: co...
    编程 发布于2025-07-21
  • 在Python中如何创建动态变量?
    在Python中如何创建动态变量?
    在Python 中,动态创建变量的功能可以是一种强大的工具,尤其是在使用复杂的数据结构或算法时,Dynamic Variable Creation的动态变量创建。 Python提供了几种创造性的方法来实现这一目标。利用dictionaries 一种有效的方法是利用字典。字典允许您动态创建密钥并分...
    编程 发布于2025-07-21

免责声明: 提供的所有资源部分来自互联网,如果有侵犯您的版权或其他权益,请说明详细缘由并提供版权或权益证明然后发到邮箱:[email protected] 我们会第一时间内为您处理。

Copyright© 2022 湘ICP备2022001581号-3