Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
151 changes: 150 additions & 1 deletion docs/internet/cdn.mdx
Original file line number Diff line number Diff line change
@@ -1 +1,150 @@
<ComingSoon />
---
title: "Understanding CDNs (Content Delivery Networks)"
description: "Learn how CDNs make websites faster, more reliable, and globally accessible by caching and delivering content from distributed servers close to users."
tags: [cdn, performance, caching, networking, internet, web, optimization]
sidebar_label: CDN
---

Modern websites and apps serve millions of users worldwide but sending data directly from one central server to everyone would be slow and inefficient. That’s where **CDNs (Content Delivery Networks)** come in.

A **CDN** is a distributed network of servers located across the globe that **deliver content faster** by caching it closer to users.

## What Is a CDN?

A **Content Delivery Network (CDN)** is a group of geographically distributed servers that work together to deliver web content such as images, videos, CSS, JavaScript, and HTML pages to users based on their location.

Instead of fetching data from your website’s origin server every time, a CDN stores (or *caches*) copies of static files on its **edge servers** around the world.

```mermaid
graph TD
A[User in India] --> B[Nearest Edge Server - Mumbai]
B --> C[Origin Server - USA]
A2[User in France] --> D[Nearest Edge Server - Paris]
D --> C
C -->|Updates Cached Data| B
C -->|Updates Cached Data| D
```

> The closer the user is to the CDN edge server, the faster the content loads.

## How a CDN Works

<Tabs>
<TabItem value="simple" label="Simple View" default>
A CDN keeps cached copies of your website’s files on global servers.
When a user visits your site, they automatically connect to the **closest** CDN node, reducing latency and improving speed.
</TabItem>
<TabItem value="technical" label="Technical View">
1. User requests a file (e.g., `index.html`).
2. DNS redirects the request to the **nearest CDN edge node**.
3. The edge server checks if it has a **cached copy** of the resource.
4. If cached, it serves the file directly (cache hit).
5. If not cached, it fetches it from the **origin server**, caches it, and serves it to the user (cache miss).
6. The process repeats for users worldwide.
</TabItem>
</Tabs>

## CDN Example (Simulation)

```jsx live
function CDNExample() {
const handleRequest = (cached) => {
alert(cached ? "Served from CDN Edge (Cache Hit)" : "Fetched from Origin Server (Cache Miss)");
};

return (
<div style={{ textAlign: "center" }}>
<h3>CDN Request Simulation</h3>
<button onClick={() => handleRequest(true)}>Request Cached File</button>
<button onClick={() => handleRequest(false)}>Request New File</button>
</div>
);
}
```

## Components of a CDN

| Component | Description |
| ---------- | ------------ |
| **Origin Server** | The main server where the original content is hosted. |
| **Edge Server (PoP)** | CDN data centers close to users that cache content for faster delivery. |
| **Cache** | Stored version of website files to avoid repeated requests to the origin. |
| **DNS Routing** | Directs user requests to the nearest CDN node. |
| **Load Balancer** | Distributes traffic efficiently between servers. |

## Example Flow: How a CDN Delivers a Web Page

```mermaid
sequenceDiagram
participant U as User Browser
participant D as DNS Resolver
participant E as CDN Edge Server
participant O as Origin Server

U->>D: Request website (www.example.com)
D-->>U: Resolve to nearest CDN Edge (Mumbai)
U->>E: Request content
E-->>U: Serve from Cache (if available)
E->>O: Fetch new content (if cache miss)
O-->>E: Send original content
E-->>U: Deliver optimized response
```

## Benefits of Using a CDN

| Benefit | Description |
| -------- | ------------ |
| **Faster Load Times** | Users connect to nearby servers, reducing latency. |
| **Scalability** | Handles massive traffic loads without downtime. |
| **Reliability** | Multiple edge servers ensure uptime even if one fails. |
| **Security** | Protects against DDoS attacks and provides SSL/TLS encryption. |
| **Cost Efficiency** | Reduces bandwidth usage and load on origin servers. |

## Performance Impact (Example)

If your site’s origin is in the USA and a visitor from India requests it:

| Delivery Type | Latency | Load Time | User Experience |
| -------------- | -------- | ---------- | ---------------- |
| **Without CDN** | 250 ms | 3.5s | Slow, laggy |
| **With CDN (India Edge)** | 45 ms | 1.2s | Fast, smooth |

That’s nearly **3x faster**, thanks to edge caching.

## CDN Caching Strategies

| Strategy | Description |
| ---------- | ------------ |
| **Time-to-Live (TTL)** | Defines how long an asset stays cached before refresh. |
| **Cache Invalidation** | Removes outdated content from CDN nodes. |
| **Stale-while-revalidate** | Serves old content while fetching fresh data in the background. |

> Example: Cloudflare and Akamai use *smart caching* to automatically refresh only changed files.

## CDN and Security

Modern CDNs not only improve performance — they also **protect websites**.

### Built-in Security Features

* **DDoS Protection** – Blocks malicious traffic before it reaches the origin.
* **WAF (Web Application Firewall)** – Filters harmful requests.
* **TLS/SSL Termination** – Ensures encrypted data transfer.
* **Bot Management** – Detects and mitigates automated attacks.

## Popular CDN Providers

| Provider | Description |
| --------- | ------------ |
| **Cloudflare** | Offers global caching, security, and edge compute features. |
| **Akamai** | One of the oldest and largest CDN providers. |
| **AWS CloudFront** | Integrated with Amazon Web Services. |
| **Fastly** | Known for real-time caching and edge logic. |
| **Google Cloud CDN** | Delivers content via Google’s backbone network. |

## Key Takeaways

* A **CDN** distributes your website’s content to servers closer to users, drastically improving performance.
* It reduces **latency**, **bandwidth usage**, and **server load**.
* CDNs use **edge caching** and **routing intelligence** to deliver fast, reliable, and secure content.
* For global applications, CDNs are **essential for scalability and user experience**.
153 changes: 152 additions & 1 deletion docs/internet/firewalls.mdx
Original file line number Diff line number Diff line change
@@ -1 +1,152 @@
<ComingSoon />
---
title: "Understanding Firewalls"
description: "Learn what firewalls are, how they protect networks from unauthorized access, and explore the different types of firewalls used in modern Internet security."
tags: [firewall, security, networking, internet, protection, cybersecurity]
sidebar_label: Firewalls
---

The Internet is a powerful and open system but that openness also creates risks. To keep networks secure, we rely on **firewalls**, the first line of defense against unwanted traffic, hackers, and cyberattacks.

## What Is a Firewall?

A **firewall** is a **security barrier** that monitors and controls incoming and outgoing network traffic based on a set of rules. It acts as a **filter between trusted and untrusted networks**, such as between your computer and the Internet.

:::info
Think of a firewall as a security guard at the entrance of a building, checking IDs and only allowing authorized personnel to enter.

In simple terms, firewalls help ensure that only safe and approved data can pass through to your network.
:::

```mermaid
graph LR
A[Internet] -->|Allowed Traffic| B(Firewall)
B -->|Filtered & Safe| C[Internal Network]
A -.->|Blocked Traffic| B
```

## How Firewalls Work

Firewalls inspect **data packets** as they travel across networks. Each packet is analyzed against **security rules**, such as:

* Source and destination IP addresses
* Port numbers
* Protocols (HTTP, HTTPS, FTP, etc.)
* Packet contents (in advanced firewalls)

<Tabs>
<TabItem value="basic" label="Basic View" default>
A basic firewall might allow web traffic (port 80/443) but block suspicious connections or file transfers on other ports.
</TabItem>
<TabItem value="technical" label="Technical View">
1. Packet enters the firewall.
2. Firewall checks **header information** (source, destination, port).
3. Rules are applied — e.g., “block all incoming SSH except from admin IPs.”
4. Packet is either **allowed**, **blocked**, or **logged** for review.
</TabItem>
</Tabs>

## Example: Simple Firewall Simulation

```jsx live
function FirewallSimulator() {
const handleRequest = (type) => {
if (type === "http") alert("Allowed: Web traffic (Port 443)");
else alert("Blocked: Unauthorized traffic (Port 23)");
};
return (
<div style={{ textAlign: "center" }}>
<h3>Firewall Traffic Filter</h3>
<button onClick={() => handleRequest("http")}>Send HTTPS Request</button>
<button onClick={() => handleRequest("telnet")}>Send Telnet Request</button>
</div>
);
}
```

## Types of Firewalls

Firewalls can operate at different layers of the network stack and offer varying levels of security:

| Type | Layer | Description |
|------|--------|-------------|
| **Packet-Filtering Firewall** | Network | Checks basic info like IPs and ports; fast but limited. |
| **Stateful Inspection Firewall** | Transport | Tracks active connections and allows related packets. |
| **Proxy Firewall** | Application | Intercepts and inspects data at the application layer (HTTP, FTP). |
| **Next-Generation Firewall (NGFW)** | Multiple | Includes intrusion detection, malware filtering, and deep inspection. |
| **Cloud Firewall (FWaaS)** | Cloud | Firewall-as-a-Service — protects cloud apps and virtual networks. |

```mermaid
graph TD
A[Packet Filtering] --> B[Stateful Inspection]
B --> C[Proxy Firewall]
C --> D[Next-Gen Firewall]
D --> E[Cloud Firewall]
```

## Firewall Rules Example

| Rule | Action | Description |
|------|---------|-------------|
| Allow TCP port 443 | Allow | Enable secure web browsing (HTTPS). |
| Block TCP port 23 | Block | Disable Telnet — an insecure protocol. |
| Allow ICMP from internal network | Allow | Permit internal ping requests. |
| Block all inbound traffic by default | Block | Enforce a default-deny security posture. |

```bash
# Example Linux UFW firewall commands
sudo ufw default deny incoming
sudo ufw allow 443/tcp
sudo ufw deny 23/tcp
sudo ufw enable
```

## Network Placement of Firewalls

Firewalls can exist in multiple forms hardware, software, or cloud-based — and are typically placed between the **LAN** and **Internet**. In a typical home or office setup:

```mermaid
graph LR
A[Internet] --> B[Firewall]
B --> C[Router]
C --> D[Local Network - Devices]
```

Some organizations use multiple layers of firewalls **perimeter firewalls** at the network edge and **internal firewalls** between departments or services.

## Stateful vs Stateless Firewalls

| Feature | Stateless Firewall | Stateful Firewall |
|----------|-------------------|-------------------|
| Tracks connections | No | Yes |
| Security level | Basic | High |
| Performance | Fast | Slightly slower |
| Use case | Simple traffic filtering | Complex enterprise networks |

:::note
Stateful firewalls are generally preferred for modern networks due to their ability to monitor ongoing connections and provide enhanced security.
:::

## Firewall Limitations

While firewalls are powerful, they aren’t a complete solution on their own.

* Cannot detect **internal threats** or **phishing attacks**.
* May slow down traffic if poorly configured.
* Need **regular updates** to remain effective.
* Must be combined with antivirus, intrusion detection, and monitoring tools.

## Real-World Examples of Firewalls

| Vendor | Product | Highlights |
|--------|----------|------------|
| **Cisco ASA** | Enterprise Firewall | Hardware-based security with advanced inspection. |
| **Fortinet FortiGate** | Unified Threat Management | Combines firewall, VPN, and intrusion prevention. |
| **Palo Alto Networks NGFW** | Next-Gen Firewall | Application-level inspection with ML-driven threat detection. |
| **Cloudflare WAF** | Cloud Firewall | Protects websites from online attacks at the edge. |

## Key Takeaways

* A **firewall** is a traffic filter that protects your system from unauthorized access.
* It uses predefined **rules** to allow or block network traffic.
* Modern **Next-Gen Firewalls** combine inspection, intrusion prevention, and threat intelligence.
* Firewalls are essential for **network security**, but should be part of a **multi-layered defense strategy**.
Loading
Loading