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.
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.
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.
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.
To understand how networks operate, we use the OSI Model, which divides networking into seven layers:
Most of the time in system design, we focus on layers 3 to 7, especially when dealing with communication protocols, security, and data flow.
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.
Example: You type "www.fooddelivery.com" in your browser, and it sends an HTTP request to fetch the home page.
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 (Transmission Control Protocol) and IP (Internet Protocol) are two of the fundamental protocols that power the internet.
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.
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 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.
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.
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.
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.
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.
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.
In any system where data travels across networks, security is paramount. Here are some key security practices for ensuring a secure system:
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.
IDS)** can help alert you when there’s an attempt to breach your network.
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.
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.
The above is the detailed content of Network fundamentals. For more information, please follow other related articles on the PHP Chinese website!