Ensiklopedia VibeKoding: Principles of Object Storage and CDN.Ensiklopedia VibeKoding: Principles of Object Storage and CDN.
> ๐ก Learning Guide: This article will walk you through a complete chainโfrom file upload to user download. You'll see how object storage manages massive files like a "smart warehouse," how CDN delivers content to users' doorsteps like a "courier network," and what pitfalls await you along the way. It's recommended to first understand basic HTTP requests and DNS resolution principles.> ๐ก Learning Guide: This article will walk you through a complete chainโfrom file upload to user download. You'll see how object storage manages massive files like a "smart warehouse," how CDN delivers content to users' doorsteps like a "courier network," and what pitfalls await you along the way. It's recommended to first understand basic HTTP requests and DNS resolution principles.
Before we begin, here are some foundational topics to brush up on:Before we begin, here are some foundational topics to brush up on:
------
Imagine this scenario: you upload a 10MB high-resolution photo to an image-sharing community, and it takes half a minute to finish. Yet your friend in Beijing downloads it in just 2 seconds. Why does the same file produce such drastically different upload and download experiences?Imagine this scenario: you upload a 10MB high-resolution photo to an image-sharing community, and it takes half a minute to finish. Yet your friend in Beijing downloads it in just 2 seconds. Why does the same file produce such drastically different upload and download experiences?
Or consider this: your e-commerce site runs a Double 11 promotion, and the product detail page suddenly gets flooded with millions of visitsโyour server goes down completely. Is it insufficient bandwidth? Or a flawed architecture design?Or consider this: your e-commerce site runs a Double 11 promotion, and the product detail page suddenly gets flooded with millions of visitsโyour server goes down completely. Is it insufficient bandwidth? Or a flawed architecture design?
The answers to these questions are hidden in the "golden duo" of object storage and CDN.The answers to these questions are hidden in the "golden duo" of object storage and CDN.
------
A traditional file system is like your wardrobe at home: clothes are organized by "tops/pants/skirts" in layers. To find a shirt, you have to open the wardrobe โ tops section โ shirt compartment. This "hierarchical nesting" model becomes extremely cumbersome when the number of files explodes.A traditional file system is like your wardrobe at home: clothes are organized by "tops/pants/skirts" in layers. To find a shirt, you have to open the wardrobe โ tops section โ shirt compartment. This "hierarchical nesting" model becomes extremely cumbersome when the number of files explodes.
Object storage, on the other hand, is like modern warehousing logistics: every package has a unique "tracking number" (object key). You just provide the tracking number, and the warehouse robot can precisely retrieve it from a sea of packages.Object storage, on the other hand, is like modern warehousing logistics: every package has a unique "tracking number" (object key). You just provide the tracking number, and the warehouse robot can precisely retrieve it from a sea of packages.
Key Differences at a Glance:Key Differences at a Glance:
| Dimension | Traditional File System | Object Storage |
|---|---|---|
| Organization | Hierarchical directory tree | Flat key-value pairs |
| Access Protocol | POSIX (local file operations) | HTTP/REST API |
| Scalability | Limited by single machine | Near-infinite horizontal scaling |
| Metadata | Basic attributes (size, time) | Rich custom metadata |
| Typical Use Case | Local office documents | Images/videos/backups/static assets |
A bucket is the top-level container in object storage, equivalent to an independent namespace. All objects must be stored in a bucket.A bucket is the top-level container in object storage, equivalent to an independent namespace. All objects must be stored in a bucket.
Naming Rules (using Alibaba Cloud OSS as an example):Naming Rules (using Alibaba Cloud OSS as an example):
Real-World Pitfall: A team once created dozens of buckets based on business lines, and were shocked when the monthly bill arrivedโeach bucket incurs minimum storage fees and request fees. Recommendation: plan buckets by combining "environment + purpose," such as prod-static-assets, dev-backup-archive.Real-World Pitfall: A team once created dozens of buckets based on business lines, and were shocked when the monthly bill arrivedโeach bucket incurs minimum storage fees and request fees. Recommendation: plan buckets by combining "environment + purpose," such as prod-static-assets, dev-backup-archive.
An object is the basic unit of storage, consisting of three parts:An object is the basic unit of storage, consisting of three parts:
images/avatar/2024/user123.jpgExample: images/avatar/2024/user123.jpgx-oss-meta-owner, x-oss-meta-projectCustom metadata: e.g., x-oss-meta-owner, x-oss-meta-projectObject storage provides multiple layers of permission control:Object storage provides multiple layers of permission control:
| Layer | Control Method | Typical Use Case |
|---|---|---|
| Bucket-level | Bucket Policy | Block all external access, allow only specific IPs |
| Object-level | ACL (Access Control List) | Public images, private documents |
| Temporary Auth | STS (Security Token Service) | Frontend direct upload, mobile uploads |
Security Red Line: Never write AccessKey ID and AccessKey Secret in frontend code! The correct approach is: the frontend requests temporary STS credentials from your backend, and the backend returns temporary credentials with an expiration time after verifying the user's identity.Security Red Line: Never write AccessKey ID and AccessKey Secret in frontend code! The correct approach is: the frontend requests temporary STS credentials from your backend, and the backend returns temporary credentials with an expiration time after verifying the user's identity.
------
Imagine you run an online store with servers in Shenzhen. Now a user in Beijing wants to access your images:Imagine you run an online store with servers in Shenzhen. Now a user in Beijing wants to access your images:
This is the core value of CDN: bringing content closer to the user.This is the core value of CDN: bringing content closer to the user.
Edge nodes are the tier closest to users in the CDN network, typically deployed at:Edge nodes are the tier closest to users in the CDN network, typically deployed at:
CDN Node Distribution in China:CDN Node Distribution in China:
The origin is where the CDN fetches content from when cache misses occur. It can be:The origin is where the CDN fetches content from when cache misses occur. It can be:
Key Configuration:Key Configuration:
Between edge nodes and the origin, CDNs typically have one or more layers of mid-tier nodes:Between edge nodes and the origin, CDNs typically have one or more layers of mid-tier nodes:
Benefits of this layered architecture:Benefits of this layered architecture:
Let's trace a real user request:Let's trace a real user request:
Step 1: DNS Resolution (Intelligent Scheduling)Step 1: DNS Resolution (Intelligent Scheduling)
CODE User enters: cdn.example.com/image.jpg โ DNS server returns: Beijing Unicom CDN node IP (1.2.3.4)
The key here is intelligent DNS: based on the user's ISP, geographic location, and node load, it returns the optimal CDN node IP.The key here is intelligent DNS: based on the user's ISP, geographic location, and node load, it returns the optimal CDN node IP.
Step 2: Edge Node Lookup (Cache Hit?)Step 2: Edge Node Lookup (Cache Hit?)
CODE Request arrives at Beijing Unicom CDN node (1.2.3.4) โ Node checks local cache: โโ Hit? Return content directly โ โโ Miss? Continue to next step
Step 3: Origin Fetch (Layer by Layer Upward)Step 3: Origin Fetch (Layer by Layer Upward)
CODE Edge node miss โ Request to parent node (e.g., North China regional center) โโ Parent node hit? Return content โโ Parent node miss? Continue upward โ Request to origin โ Origin returns content
Step 4: Cache and Return (Faster Next Time)Step 4: Cache and Return (Faster Next Time)
CODE Content returns along the chain โ Each layer caches a copy โ Finally reaches the user
This way, the next time a user requests the same file, it can be served directly from the edge node, achieving "instant loading."This way, the next time a user requests the same file, it can be served directly from the edge node, achieving "instant loading."
------
CODE Browser โ Your Backend Server โ Object Storage
Flow:Flow:
Pros:Pros:
Cons:Cons:
Use Cases: Small files (<10MB), scenarios requiring backend processing (e.g., image compression, watermarking), internal management systems.Use Cases: Small files (<10MB), scenarios requiring backend processing (e.g., image compression, watermarking), internal management systems.
CODE Browser โโโโโโโ Object Storage โ Backend only issues temporary credentials
Flow:Flow:
Pros:Pros:
Cons:Cons:
Use Cases: Large file uploads, user-generated content (UGC), businesses requiring high-concurrency uploads.Use Cases: Large file uploads, user-generated content (UGC), businesses requiring high-concurrency uploads.
CODE 10GB video file โ Split into 1,000 chunks of 10MB each โ Parallel upload (5 chunks at a time) โ Network drops! 600 chunks already uploaded โ Network recovers, resume from chunk 601 โ All chunks uploaded, initiate "merge" request
Why multipart?Why multipart?
| Scenario | Without Multipart | With Multipart |
|---|---|---|
| Network Fluctuation | 99% uploaded, disconnect โ restart all | Only re-upload failed chunks |
| Upload Speed | Single-threaded, slow | Multi-threaded parallel, fast |
| Memory Usage | Must buffer entire file | Only buffer current chunk |
| Progress Display | Only 0% and 100% | Precise progress per chunk |
Multipart Specifications by Major Cloud Providers:Multipart Specifications by Major Cloud Providers:
| Provider | Chunk Size Limit | Max Chunks | Min Chunk Size |
|---|---|---|---|
| Alibaba Cloud OSS | 100MB | 10,000 | 100KB |
| Tencent Cloud COS | 5GB | 10,000 | 1MB |
| AWS S3 | 5GB | 10,000 | 5MB (recommended) |
| Qiniu Cloud | 100MB | 10,000 | 4MB |
CDN edge nodes cache content from the origin, but when:CDN edge nodes cache content from the origin, but when:
CDN nodes need to request the latest content from the originโthis process is called "origin fetch."CDN nodes need to request the latest content from the originโthis process is called "origin fetch."
| Mode | Principle | Use Case | Pros/Cons |
|---|---|---|---|
| Direct Origin Fetch | CDN node โ Origin | Origin has a public IP and low traffic | Simple and direct, but high origin pressure |
| Mid-Tier Origin Fetch | CDN node โ Mid-tier โ Origin | Large websites, multi-layer cache | Reduces origin pressure, complex architecture |
| OSS/COS as Origin | CDN node โ Object Storage | Static assets, images, videos | Best practice, low cost, good performance |
Scenario 1: Object Storage as Origin (Recommended)Scenario 1: Object Storage as Origin (Recommended)
CODE User accesses: cdn.example.com/images/photo.jpg โ CDN Edge Node (Beijing) โ Miss, fetch from origin โ Origin: bucket-name.oss-cn-beijing.aliyuncs.com โ Returns image, CDN caches and responds to user
Key configuration items:Key configuration items:
Scenario 2: Multi-Origin Load BalancingScenario 2: Multi-Origin Load Balancing
When a single origin can't handle the origin fetch pressure, configure multiple origins:When a single origin can't handle the origin fetch pressure, configure multiple origins:
CODE CDN Edge Node โโ Origin A (weight 50%) โโ Origin B (weight 30%) โโ Origin C (weight 20%)
Active/standby mode:Active/standby mode:
CODE CDN Edge Node โโ Primary Origin A (all traffic when healthy) โโ Backup Origin B (failover when primary fails)
Here's an easily confused concept:Here's an easily confused concept:
| Metric | Definition | Billing Relationship |
|---|---|---|
| CDN Downstream Bandwidth | Traffic from CDN nodes to users | Usually billed as CDN traffic cost |
| Origin Fetch Bandwidth | Traffic from origin to CDN nodes | Usually object storage or origin egress cost |
Cost-Saving Tips:Cost-Saving Tips:
How does a CDN decide whether two requests should return the same cached copy? It relies on the cache key.How does a CDN decide whether two requests should return the same cached copy? It relies on the cache key.
Default cache key typically includes:Default cache key typically includes:
/images/photo.jpgFor example: /images/photo.jpgProblem Scenario:Problem Scenario:
CODE User A requests: /images/photo.jpg?w=100&h=100 (100ร100 thumbnail) User B requests: /images/photo.jpg?w=800&h=600 (800ร600 large image)
If the cache key only includes the path, the two different-sized images would be treated as the same file, causing confusion.If the cache key only includes the path, the two different-sized images would be treated as the same file, causing confusion.
Solution: Custom Cache Key RulesSolution: Custom Cache Key Rules
| Rule | Example | Effect |
|---|---|---|
| Keep specified query params | Keep w, h | Cache different sizes separately |
| Keep all query params | Keep all | Fully exact matching |
| Ignore specific query params | Ignore token, timestamp | URLs with timestamps can hit cache |
| Include request headers | Include Accept-Language | Return different content for different languages |
Real-World Configuration Example (Alibaba Cloud CDN):Real-World Configuration Example (Alibaba Cloud CDN):
CODE Cache key rules: - URL path: /images/* - Keep query params: w, h, format - Ignore query params: token, timestamp, utm_source
TTL (Time To Live) determines how long content is cached on CDN nodes. Set it too short, and you'll have many origin fetches and high costs; set it too long, and users will see stale content after updates.TTL (Time To Live) determines how long content is cached on CDN nodes. Set it too short, and you'll have many origin fetches and high costs; set it too long, and users will see stale content after updates.
Recommended TTL by File Type:Recommended TTL by File Type:
| File Type | Recommended TTL | Reason |
|---|---|---|
| HTML pages | 0-5 minutes | Frequently updated, needs real-time |
| JS/CSS files | 1 year (with filename hash) | Content unchanged; cache invalidates when filename changes |
| Images/videos | 7-30 days | Low update frequency, can be cached long-term |
| Font files | 1 year | Almost never change |
| API responses | 0-5 minutes (business-dependent) | High data real-time requirements |
Best Practices for Frontend Engineering with CDN:Best Practices for Frontend Engineering with CDN:
javascript // webpack/vite configuration output: { filename: 'js/[name]-[contenthash:8].js', chunkFilename: 'js/[name]-[contenthash:8].chunk.js', }
Generated filename: app-a3f2b1c9.jsGenerated filename: app-a3f2b1c9.js
Manual Purge (Emergency Scenarios):Manual Purge (Emergency Scenarios):
When you've updated origin content but the CDN cache hasn't expired yet, users still see the old content:When you've updated origin content but the CDN cache hasn't expired yet, users still see the old content:
| Purge Type | Effect | Time Required | Use Case |
|---|---|---|---|
| URL Purge | Invalidate cache for a specific URL | 5-10 minutes | Single file update |
| Directory Purge | Invalidate all content under a directory | 10-30 minutes | Batch update |
| Full-site Purge | Invalidate all cache for the entire domain | 30+ minutes | Emergency rollback |
Important Reminder: Purging only invalidates the cache; the next request will fetch new content from the origin. Don't do large-scale purges during peak hours, or you might overwhelm the origin.Important Reminder: Purging only invalidates the cache; the next request will fetch new content from the origin. Don't do large-scale purges during peak hours, or you might overwhelm the origin.
Preheat (Proactive Optimization):Preheat (Proactive Optimization):
Purge is reactive (content already updated); preheat is proactive (cache in advance).Purge is reactive (content already updated); preheat is proactive (cache in advance).
CODE Scenario: A viral article is going live tomorrow at 10 AM Submit preheat request tonight: - URL: https://cdn.example.com/articles/viral-article.html - Preheat scope: All edge nodes nationwide Result: When users access it at 10 AM tomorrow, the content is already waiting at edge nodes โ Zero origin fetch latency, instant loading experience
------
Traditional DNS resolution:Traditional DNS resolution:
CODE User asks: What's the IP for cdn.example.com? DNS answers: 1.2.3.4 (fixed)
Intelligent DNS resolution:Intelligent DNS resolution:
CODE User (Beijing Unicom) asks: What's the IP for cdn.example.com? Intelligent DNS: Let me check... Beijing Unicom's CDN node is 1.2.3.4 User (Shanghai Telecom) asks: What's the IP for cdn.example.com? Intelligent DNS: Shanghai Telecom's CDN node is 5.6.7.8
Scheduling Dimensions:Scheduling Dimensions:
| Dimension | Description | Effect |
|---|---|---|
| Geographic Location | Assign by province/city/country | Nearby access, reduced latency |
| ISP | Unicom/Telecom/Mobile/BGP | Same-ISP transmission, avoid cross-ISP |
| Node Load | Real-time CPU/bandwidth/QPS | Avoid overloaded nodes |
| Node Health | Availability probing | Auto-remove faulty nodes |
| Cost Factors | Bandwidth unit price differences | Balance performance and cost |
Traditional DNS has a problem: DNS hijacking and resolution latency.Traditional DNS has a problem: DNS hijacking and resolution latency.
HTTP DNS Solution:HTTP DNS Solution:
CODE Client โ Bypasses system DNS โ Directly queries HTTP DNS service (e.g., 223.5.5.5:80) โ Returns optimal IP list (with weights) โ Client probes network quality and selects the best IP
Advantages:Advantages:
Practical Recommendations:Practical Recommendations:
------
Scenario Comparison:Scenario Comparison:
CODE Without HTTPS: User accesses http://cdn.example.com/image.jpg โ Browser address bar shows "Not Secure" โ Some browsers/APPs directly block access โ SEO ranking drops
CODE With HTTPS: User accesses https://cdn.example.com/image.jpg โ Browser shows green lock icon โ HTTP/2 multiplexing takes effect โ Performance + security both improved
| Solution | Description | Cost | Use Case |
|---|---|---|---|
| Cloud provider free cert | Provided by Alibaba Cloud/Tencent Cloud | Free | Single domain, quick start |
| Let's Encrypt | Community free certificate | Free | Automated deployment |
| Commercial DV/OV/EV cert | Symantec, GeoTrust, etc. | Hundreds to tens of thousands CNY/year | Enterprise, green bar needed |
| Wildcard certificate | \*.example.com | Thousands CNY/year | Multiple subdomains |
Practical Recommendations:Practical Recommendations:
TLS Version Selection:TLS Version Selection:
CODE Recommended: TLS 1.2 and TLS 1.3 only Compatibility: TLS 1.1 + TLS 1.2 + TLS 1.3 (for legacy browsers)
Cipher Suites:Cipher Suites:
CODE Recommended: ECDHE key exchange + AES-GCM encryption Disabled: DES, RC4, MD5, SHA1
OCSP Stapling:OCSP Stapling:
CODE Function: CDN node pre-fetches certificate revocation status Effect: Reduces client verification time by 200-500ms Recommendation: Always enable
TLS Session Resumption:TLS Session Resumption:
CODE Session ID resumption: Client sends last Session ID, server resumes session Session Ticket resumption: Server encrypts session state and sends to client, client sends it back next time Effect: Avoids full TLS handshake, saves 1-RTT
HTTP/2 Multiplexing:HTTP/2 Multiplexing:
CODE HTTP/1.1: Request 1 (index.html) โโโโโโโโโโโโโโโโโ Response 1 โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Request 2 (style.css) โโโโโโโโโโโโโโโโโโ Response 2 โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ Request 3 (script.js) โโโโโโโโโโโโโโโโโโ Response 3 โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ (Serial, one finishes before the next) HTTP/2: Request 1 โโโ Request 2 โโโ Merged on one TCP connection, frames interleaved Request 3 โโโ Response 1 โโโ Streamed back by priority Response 2 โโโ Response 3 โโโ (Parallel, one connection multiplexed)
HTTP/2 Server Push:HTTP/2 Server Push:
CODE Scenario: User requests index.html, which references style.css and script.js Traditional approach: 1. User downloads index.html 2. Parsing discovers style.css and script.js are needed 3. Two more requests to fetch them HTTP/2 Push: 1. User requests index.html 2. CDN node returns index.html while proactively pushing style.css and script.js 3. When the user parses the HTML, the resources are already in the cache Note: Push cautiouslyโtoo much wastes bandwidth, too little has no effect
HTTP/3 (QUIC):HTTP/3 (QUIC):
CODE HTTP/2 problem: TCP-based, head-of-line blocking โ One TCP packet lost, entire connection waits for retransmission HTTP/3 solution: QUIC-based (reliable transport over UDP) โ Each stream is independent; one stream blocked doesn't affect others โ Connection migration: WiFi to 4G switch, connection doesn't drop โ 0-RTT handshake: Fast connection establishment even on first visit Current status: As of 2024, mainstream CDNs support HTTP/3; recommended to enable
------
CODE Definition: Amount of data transferred per unit of time Unit: bps (bits per second), Mbps, Gbps CDN bandwidth = Total egress traffic from all edge nodes Note the distinction: - Billing bandwidth: Usually billed by 95th percentile peak or daily peak - Actual bandwidth: Real-time transfer rate
Relationship Between Bandwidth and Traffic:Relationship Between Bandwidth and Traffic:
CODE 1 Mbps bandwidth running continuously for 1 hour = 450 MB of traffic (Calculation: 1,000,000 bps ร 3600s รท 8 รท 1024 รท 1024 โ 429 MB)
CODE Definition: Number of queries/requests per second CDN QPS = Total HTTP requests processed per second across all edge nodes Note: High QPS doesn't mean high bandwidth - Small file scenarios: High QPS, low bandwidth - Large file scenarios: Low QPS, high bandwidth
CODE Definition: Proportion of requests served from CDN edge node cache out of total requests Formula: Hit Ratio = (Hits / Total Requests) ร 100% or Hit Ratio = (1 - Origin Fetch Traffic / Total Egress Traffic) ร 100% Industry standards: - Images/videos/JS/CSS: > 95% - HTML pages: 50-80% (depending on update frequency) - API endpoints: Usually not cached or very low
Common Causes of Low Hit Ratio:Common Causes of Low Hit Ratio:
| Cause | Symptom | Solution |
|---|---|---|
| Cache time too short | TTL only a few minutes | Adjust TTL by file type |
| Query parameter changes | URL carries random numbers | Configure to ignore specific params |
| Improper cache key | Things that shouldn't differ are differentiated | Optimize cache key rules |
| Frequent content updates | Files frequently overwritten | Use version numbers or hash filenames |
| Many first-time visits | New content or new nodes | Preheat in advance |
A typical CDN access log contains the following fields:A typical CDN access log contains the following fields:
CODE Time | Client IP | Request Method | URL | HTTP Status Code | Response Size | Cache Status | Response Time | Referer | User-Agent Example: 2024-01-15 14:32:01 | 114.114.114.114 | GET | https://cdn.example.com/images/photo.jpg | 200 | 153600 | HIT | 23 | https://example.com/ | Mozilla/5.0...
Key Field Explanations:Key Field Explanations:
| Field | Description | Analysis Value |
|---|---|---|
cache_status | Cache status | HIT (hit), MISS (miss), EXPIRED (expired) |
response_time | Response time (ms) | Determines user experience; optimize if >500ms |
http_status | HTTP status code | Troubleshoot 404/500 errors |
bytes_sent | Bytes sent | Bandwidth statistics |
Issue 1: Users Report Slow AccessIssue 1: Users Report Slow Access
Troubleshooting steps:Troubleshooting steps:
CODE 1. Check log response_time - If high (>500ms): Check if cache MISS or slow origin 2. Check cache_status - HIT: Cache hit; slowness may be due to large file or node issue - MISS: Cache miss; need to optimize cache strategy or hit ratio 3. Check client IP distribution - Slow in certain regions: May be high node load or insufficient coverage
Issue 2: Cache Not Taking Effect, Always Fetching from OriginIssue 2: Cache Not Taking Effect, Always Fetching from Origin
Troubleshooting checklist:Troubleshooting checklist:
CODE โก Does the origin response header have Cache-Control: no-cache / private? โก Does the URL carry random parameters (e.g., ?_=123456)? โก Is the cache key configuration correct? โก Is the TTL too short? โก Is it hitting the browser's local cache instead of CDN?
Issue 3: Sudden Cost SpikeIssue 3: Sudden Cost Spike
Investigation directions:Investigation directions:
CODE 1. Check bill details - High CDN traffic cost: Check if large files are being frequently accessed or hotlinked - High origin fetch traffic cost: Check if hit ratio has dropped sharply - High request count cost: Check for CC attacks or crawlers 2. Check access logs - Are there many 404 requests (possibly scanning or configuration errors)? - Is the Referer abnormal (to determine if hotlinking)? 3. Security settings - Enable hotlink protection (Referer whitelist) - Enable IP blacklist/whitelist - Configure CC protection
------
Imagine you're the technical lead for an image-sharing community facing these challenges:Imagine you're the technical lead for an image-sharing community facing these challenges:
CODE โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ User Upload Flow โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ User Browser Backend Service Object Storage โ โ โ โ 1. Request upload credentials โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ>โ โ โ โ โ โ โ 2. Request STS temp credentialsโ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ>โ โ โ โ โ โ 3. Return STS credentials โ โ โ<โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ 4. Return upload credentials (with STS) โ โ โ<โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ โ 5. Direct file upload (using STS signature)โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ>โ โ โ โ โ 6. Return upload result (URL, ETag, etc.) โ โ โ<โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ 7. Notify backend upload complete (save to DB)โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ>โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ User Access Flow โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ User Browser DNS Resolution CDN Node Object Storage (Origin) โ โ โ โ โ 1. Request image URL โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ>โ โ โ โ โ โ โ โ 2. DNS query โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโ>โ โ โ โ โ โ โ โ 3. Return optimal node IPโ โ โ โ<โโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ โ โ 4. Connect to CDN node โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ>โ โ โ โ โ โ โ โ 5. Check cache โ โ โ โ โโ Hit? Return directly โ โ โ โโ Miss? Continue โ โ โ โ โ โ โ โ 6. Origin fetch โ โ โ โโโโโโโโโโโโโโโโโโโโโโโโ>โ โ โ โ โ โ โ โ 7. Return file โ โ โ โ<โโโโโโโโโโโโโโโโโโโโโโโโ โ โ โ โ โ โ 8. Cache and respond โ โ โ<โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ โ
Bucket Planning:Bucket Planning:
CODE Bucket: myapp-images-prod โโ Directory structure: โ โโ uploads/ # Original images uploaded by users โ โ โโ 2024/01/15/user123-abc.jpg โ โ โโ 2024/01/15/user456-def.png โ โโ thumbnails/ # Thumbnails โ โ โโ small/ # 100ร100 โ โ โโ medium/ # 400ร300 โ โ โโ large/ # 800ร600 โ โโ processed/ # Processed images (watermarked, etc.) โ โโ Access permissions: โ โโ Original images directory: Private (requires signed access) โ โโ Thumbnails directory: Public read โ โโ CORS: Allow *.myapp.com access โ โโ Lifecycle policies: โโ 7 days after upload: Infrequent Access storage (save 40% cost) โโ 90 days after upload: Archive storage (save 70% cost) โโ 3 years after upload: Auto-delete (or transfer to cheaper cold storage)
CORS Configuration:CORS Configuration:
xml <CORSConfiguration> <CORSRule> <AllowedOrigin>https://myapp.com</AllowedOrigin> <AllowedOrigin>https://www.myapp.com</AllowedOrigin> <AllowedMethod>GET</AllowedMethod> <AllowedMethod>HEAD</AllowedMethod> <AllowedHeader>*</AllowedHeader> <ExposeHeader>ETag</ExposeHeader> <ExposeHeader>x-oss-request-id</ExposeHeader> <MaxAgeSeconds>3600</MaxAgeSeconds> </CORSRule> </CORSConfiguration>
Cache Strategy Configuration:Cache Strategy Configuration:
CODE Global default rules: โโ Cache key: URL path + keep w, h, format query params โโ Default TTL: 7 days โโ Origin HOST: Auto-follow By file type: โโ *.html: โ โโ TTL: 5 minutes โ โโ Prefer memory cache reads โ โโ *.js, *.css: โ โโ TTL: 1 year โ โโ Ignore query params (since filenames have hashes) โ โโ *.jpg, *.png, *.gif, *.webp: โ โโ TTL: 30 days โ โโ Keep query params (w, h, format for dynamic resizing) โ โโ Enable automatic image compression optimization โ โโ /api/*: โโ TTL: 0 (no cache) โโ Direct origin fetch
HTTPS Optimization Configuration:HTTPS Optimization Configuration:
CODE Certificate configuration: โโ Certificate type: Wildcard certificate *.myapp.com โโ Deployment method: Upload via CDN console, auto-renewal โโ Backup certificate: EV certificate for main domain (shows green address bar) TLS configuration: โโ Minimum TLS version: 1.2 (balance compatibility and security) โโ Maximum TLS version: 1.3 โโ Cipher suites: Only enable strong cipher suites โโ OCSP Stapling: Enabled โโ TLS Session Resumption: Enable Session Ticket โโ HSTS: Enabled (max-age=31536000) HTTP/2 and HTTP/3: โโ HTTP/2: Enabled (multiplexing, header compression) โโ HTTP/2 Server Push: Enable as needed (Preload recommended as alternative) โโ HTTP/3 (QUIC): Enabled (experimental feature, gradual rollout)
CODE Monthly CDN + Object Storage cost breakdown: CDN portion: โโ Downstream traffic cost (major, ~60%) โ โโ China mainland: 0.15-0.30 CNY/GB โ โโ Asia-Pacific: 0.40-0.80 CNY/GB โ โโ Europe & Americas: 0.30-0.60 CNY/GB โ โโ Request count cost (minor, ~5%) โ โโ HTTP: 0.01-0.05 CNY per 10,000 requests โ โโ HTTPS: 0.05-0.15 CNY per 10,000 requests (TLS handshake consumes resources) โ โโ Peak bandwidth cost (optional billing method) โ โโ 95th percentile billing: Suitable for highly fluctuating traffic โ โโ Value-added feature costs (~5%) โโ HTTPS certificate management โโ WAF protection โโ Real-time log push โโ Edge scripts/functions Object Storage portion: โโ Storage capacity cost (~15%) โ โโ Standard storage: 0.12-0.15 CNY/GB/month โ โโ Infrequent Access storage: 0.08-0.10 CNY/GB/month โ โโ Archive storage: 0.03-0.05 CNY/GB/month โ โโ Request costs (~5%) โ โโ PUT: 0.01-0.05 CNY per 10,000 requests โ โโ GET: 0.005-0.01 CNY per 10,000 requests โ โโ Data retrieval costs (Infrequent Access/Archive) โ โโ Early deletion or retrieval incurs additional fees โ โโ Origin fetch egress traffic cost (~10%) โโ Traffic cost for CDN origin fetch to object storage
Tip 1: Storage Tiering with Automatic Lifecycle ManagementTip 1: Storage Tiering with Automatic Lifecycle Management
yaml # Lifecycle rule example rules: - id: image-lifecycle prefix: uploads/ transitions: # After 7 days, transition to IA storage, save 30% cost - days: 7 storageClass: IA # After 90 days, transition to Archive storage, save 70% cost - days: 90 storageClass: Archive # Auto-delete after 3 years expiration: days: 1095
Tip 2: Improve CDN Hit Ratio, Reduce Origin FetchTip 2: Improve CDN Hit Ratio, Reduce Origin Fetch
CODE What does improving hit ratio from 90% to 95% mean? Assuming: - Daily traffic: 10 TB - Hit ratio 90%: 1 TB origin fetch - Hit ratio 95%: 0.5 TB origin fetch Origin fetch savings: 0.5 TB/day ร 0.15 CNY/GB ร 30 days = 2,250 CNY/month
Tip 3: Compression and Format OptimizationTip 3: Compression and Format Optimization
CODE Image optimization plan: โโ Store original images in object storage (not directly exposed) โโ Enable CDN image processing: โ โโ Auto format conversion: JPEG โ WebP/AVIF (save 30-50%) โ โโ Auto quality compression: Visually lossless compression (save 20-40%) โ โโ Responsive sizing: Return appropriate size based on device โ โโ Progressive loading: Blur to sharp โโ Result: Bandwidth cost reduced by 50-70%
Tip 4: Bandwidth Peak Cap and AlertsTip 4: Bandwidth Peak Cap and Alerts
yaml # Bandwidth cap configuration bandwidth_cap: daily_limit: 500 # Mbps, auto-disable CDN if daily peak exceeds monthly_limit: 10000 # GB, disable if monthly traffic exceeds # Alert thresholds alerts: - threshold: 70% # Alert at 70% channels: [sms, email] - threshold: 90% # Call at 90% channels: [phone]
------
Principle 1: Separate Static and Dynamic ContentPrinciple 1: Separate Static and Dynamic Content
CODE Dynamic content (API, HTML) โ Route to origin or edge functions Static content (images, JS, CSS, videos) โ Route through CDN + object storage
Principle 2: Serve NearbyPrinciple 2: Serve Nearby
CODE Content is cached wherever the users are โ Choose a CDN provider with broad coverage โ Enable intelligent DNS scheduling โ Preheat important content in advance
Principle 3: Layered CachingPrinciple 3: Layered Caching
CODE Browser local cache (strongest) โ CDN edge node cache (second strongest) โ CDN mid-tier/regional node (fallback) โ Object storage/origin (last line of defense)
Principle 4: Balance Cost and ExperiencePrinciple 4: Balance Cost and Experience
CODE Storage tiering: Hot data on standard storage, cold data on archive storage Cache strategy: Long TTL for high-frequency content, short TTL for low-frequency content Compression optimization: WebP/AVIF formats, intelligent quality compression Monitoring and alerts: Set bandwidth caps, prevent abnormal traffic
Bucket Naming and PermissionsBucket Naming and Permissions
CDN Cache ConfigurationCDN Cache Configuration
HTTPS SecurityHTTPS Security
Cost ControlCost Control
------
javascript /** * Object Storage Direct Upload Utility * Supports: Alibaba Cloud OSS, Tencent Cloud COS, AWS S3 */ class DirectUploader { constructor(config) { this.provider = config.provider // 'oss' | 'cos' | 's3' this.region = config.region this.bucket = config.bucket this.getCredentials = config.getCredentials // Function to fetch temporary credentials } /** * Fetch STS temporary credentials */ async fetchCredentials() { // Request temporary credentials from backend const credentials = await this.getCredentials() return { accessKeyId: credentials.accessKeyId, accessKeySecret: credentials.accessKeySecret, sessionToken: credentials.securityToken || credentials.sessionToken, expiration: credentials.expiration } } /** * Generate upload signature (for client-side signature computation) */ generateSignature(credentials, fileKey, fileType, options = {}) { const timestamp = new Date().toISOString() const date = timestamp.slice(0, 10).replace(/-/g, '') // Signature algorithms differ slightly by provider switch (this.provider) { case 'oss': return this._ossSignature(credentials, fileKey, date, options) case 'cos': return this._cosSignature(credentials, fileKey, date, options) case 's3': return this._s3Signature(credentials, fileKey, date, options) default: throw new Error('Unknown provider') } } /** * Single file upload (small files < 100MB) */ async upload(file, options = {}) { const credentials = await this.fetchCredentials() const fileKey = this._generateFileKey(file, options.directory) const formData = new FormData() // Build form fields (field names differ by provider) const formFields = this._buildFormFields( credentials, fileKey, file.type, options ) Object.entries(formFields).forEach(([key, value]) => { formData.append(key, value) }) formData.append('file', file) // Send upload request const uploadUrl = this._getUploadUrl() const response = await fetch(uploadUrl, { method: 'POST', body: formData, // For large files, you may need a longer timeout signal: options.signal // Support AbortController to cancel upload }) if (!response.ok) { const errorText = await response.text() throw new Error(`Upload failed: ${response.status} ${errorText}`) } return { url: this._getFileUrl(fileKey), key: fileKey, etag: response.headers.get('ETag'), size: file.size } } /** * Multipart upload (large files > 100MB) */ async multipartUpload(file, options = {}) { const partSize = options.partSize || 10 * 1024 * 1024 // Default 10MB per part const parallel = options.parallel || 3 // Default 3 concurrent const credentials = await this.fetchCredentials() const fileKey = this._generateFileKey(file, options.directory) // 1. Initialize multipart upload const uploadId = await this._initMultipartUpload( credentials, fileKey, file.type ) // 2. Calculate parts const parts = [] const totalParts = Math.ceil(file.size / partSize) for (let i = 0; i < totalParts; i++) { const start = i * partSize const end = Math.min(start + partSize, file.size) parts.push({ number: i + 1, start, end, blob: file.slice(start, end) }) } // 3. Upload parts (with concurrency control and resumable upload) const uploadedParts = [] const failedParts = [] // Support resumable upload: check which parts are already uploaded if (options.resume) { const existingParts = await this._listParts( credentials, fileKey, uploadId ) for (const part of existingParts) { uploadedParts.push(part) } } // Filter out already uploaded parts const pendingParts = parts.filter( (p) => !uploadedParts.some((up) => up.partNumber === p.number) ) // Concurrent upload const uploadPart = async (part) => { try { const etag = await this._uploadPart( credentials, fileKey, uploadId, part ) return { partNumber: part.number, etag } } catch (error) { failedParts.push({ part, error }) throw error } } // Use Promise.all to control concurrency const chunks = [] for (let i = 0; i < pendingParts.length; i += parallel) { chunks.push(pendingParts.slice(i, i + parallel)) } for (const chunk of chunks) { const results = await Promise.allSettled(chunk.map(uploadPart)) for (const result of results) { if (result.status === 'fulfilled') { uploadedParts.push(result.value) } } } // Check if all parts uploaded successfully if (uploadedParts.length !== totalParts) { throw new Error( `Upload incomplete: ${uploadedParts.length}/${totalParts} parts uploaded` ) } // 4. Complete multipart upload (merge parts) await this._completeMultipartUpload( credentials, fileKey, uploadId, uploadedParts ) return { url: this._getFileUrl(fileKey), key: fileKey, size: file.size, parts: totalParts } } /** * Generate file storage path */ _generateFileKey(file, directory = '') { const date = new Date() const datePath = `${date.getFullYear()}/${String(date.getMonth() + 1).padStart(2, '0')}/${String(date.getDate()).padStart(2, '0')}` const random = Math.random().toString(36).substring(2, 10) const ext = file.name.split('.').pop() || 'bin' const key = directory ? `${directory}/${datePath}/${random}.${ext}` : `${datePath}/${random}.${ext}` return key } // ============ Provider-Specific Methods ============ _getUploadUrl() { switch (this.provider) { case 'oss': return `https://${this.bucket}.oss-${this.region}.aliyuncs.com` case 'cos': return `https://${this.bucket}.cos.${this.region}.myqcloud.com` case 's3': return `https://${this.bucket}.s3.${this.region}.amazonaws.com` default: throw new Error('Unknown provider') } } _getFileUrl(key) { return `https://${this.bucket}.${this.provider === 'oss' ? 'oss' : 'cos'}-${this.region}.${ this.provider === 'oss' ? 'aliyuncs.com' : this.provider === 'cos' ? 'myqcloud.com' : 'amazonaws.com' }/${key}` } // Provider-specific signature, multipart upload methods... (implement as needed) _buildFormFields(credentials, fileKey, fileType, options) { // Provider-specific form field construction logic // Implement according to each provider's documentation return {} } async _initMultipartUpload(credentials, fileKey, fileType) { // Provider-specific multipart upload initialization logic return 'upload-id' } async _uploadPart(credentials, fileKey, uploadId, part) { // Provider-specific part upload logic return 'etag' } async _completeMultipartUpload(credentials, fileKey, uploadId, parts) { // Provider-specific multipart upload completion logic } async _listParts(credentials, fileKey, uploadId) { // Provider-specific logic to list uploaded parts return [] } } // Usage example const uploader = new DirectUploader({ provider: 'oss', region: 'cn-beijing', bucket: 'myapp-images-prod', getCredentials: async () => { // Request temporary credentials from backend const res = await fetch('/api/upload/credentials') return res.json() } }) // Small file upload async function uploadAvatar(file) { try { const result = await uploader.upload(file, { directory: 'avatars', onProgress: (progress) => { console.log(`Upload progress: ${progress.percent}%`) } }) console.log('Upload successful:', result.url) return result } catch (error) { console.error('Upload failed:', error) throw error } } // Large file multipart upload async function uploadVideo(file) { try { const result = await uploader.multipartUpload(file, { directory: 'videos', partSize: 10 * 1024 * 1024, // 10MB per part parallel: 3, // 3 concurrent resume: true, // Support resumable upload onProgress: (progress) => { console.log( `Upload progress: ${progress.percent}%, uploaded ${progress.loaded}/${progress.total}` ) }, onPartComplete: (part) => { console.log(`Part ${part.number} upload complete`) } }) console.log('Upload successful:', result.url) return result } catch (error) { console.error('Upload failed:', error) // You can implement retry logic or save checkpoint info here throw error } }
javascript /** * Object Storage STS Temporary Credential Service * Supports: Alibaba Cloud OSS, Tencent Cloud COS, AWS S3 */ const express = require('express') const STS = require('ali-oss').STS // Alibaba Cloud // const COS = require('cos-nodejs-sdk-v5') // Tencent Cloud const router = express.Router() // Configuration const config = { // Alibaba Cloud OSS configuration oss: { accessKeyId: process.env.OSS_ACCESS_KEY_ID, accessKeySecret: process.env.OSS_ACCESS_KEY_SECRET, region: 'oss-cn-beijing', bucket: 'myapp-images-prod', // STS role ARN (needs to be created in RAM console) roleArn: process.env.OSS_STS_ROLE_ARN } } /** * Get STS temporary credentials (Alibaba Cloud OSS) * POST /api/upload/credentials */ router.post('/credentials', async (req, res) => { try { // 1. Verify user identity (implement as needed) const userId = req.user?.id if (!userId) { return res.status(401).json({ error: 'Unauthorized' }) } // 2. Generate unique file path prefix (for permission isolation) const date = new Date() const prefix = `uploads/${date.getFullYear()}/${String(date.getMonth() + 1).padStart(2, '0')}/${userId}/` // 3. Create STS client const sts = new STS({ accessKeyId: config.oss.accessKeyId, accessKeySecret: config.oss.accessKeySecret }) // 4. Request temporary credentials const result = await sts.assumeRole( config.oss.roleArn, { // Policy restricts permission scope (principle of least privilege) Statement: [ { Effect: 'Allow', Action: [ 'oss:PutObject', 'oss:InitiateMultipartUpload', 'oss:UploadPart', 'oss:CompleteMultipartUpload', 'oss:AbortMultipartUpload', 'oss:ListParts' ], Resource: [`acs:oss:*:*:${config.oss.bucket}/${prefix}*`] } ], Version: '1' }, 3600, // Credential validity: 1 hour 'web-upload-session-' + Date.now() ) // 5. Return credentials and configuration res.json({ success: true, data: { // STS temporary credentials credentials: { accessKeyId: result.credentials.AccessKeyId, accessKeySecret: result.credentials.AccessKeySecret, sessionToken: result.credentials.SecurityToken, expiration: result.credentials.Expiration }, // Upload configuration config: { provider: 'oss', region: config.oss.region, bucket: config.oss.bucket, endpoint: `https://${config.oss.bucket}.${config.oss.region}.aliyuncs.com`, prefix: prefix, // File path prefix // Security limits maxSize: 100 * 1024 * 1024, // Max 100MB allowedTypes: [ 'image/jpeg', 'image/png', 'image/gif', 'image/webp', 'video/mp4' ] } } }) } catch (error) { console.error('Get credentials failed:', error) res.status(500).json({ success: false, error: 'Failed to get upload credentials', message: error.message }) } }) /** * Callback notification: frontend notifies backend after upload completes * POST /api/upload/callback */ router.post('/callback', async (req, res) => { try { const { key, etag, size, mimeType, originalName } = req.body const userId = req.user?.id // 1. Verify file existence // 2. Save file info to database const fileRecord = await db.files.create({ userId, key, etag, size, mimeType, originalName, url: `https://cdn.example.com/${key}`, createdAt: new Date() }) // 3. Async processing: generate thumbnails, extract metadata, content moderation, etc. await processFileAsync(fileRecord) res.json({ success: true, data: { fileId: fileRecord.id, url: fileRecord.url, size: fileRecord.size } }) } catch (error) { console.error('Upload callback failed:', error) res.status(500).json({ success: false, error: 'Failed to process uploaded file' }) } }) module.exports = router
javascript /** * CDN Hotlink Protection and Security Configuration Example */ // 1. Referer hotlink protection (prevent other websites from directly referencing your resources) const refererConfig = { // Whitelist mode: only allow the following Referers allowList: [ '*.myapp.com', // Main site '*.myapp.cn', // Domestic site 'localhost:*', // Local development '127.0.0.1:*' ], // Blacklist mode (optional): block the following Referers blockList: [ '*.competitor.com', // Competitors 'spam-site.com' ], // Empty Referer handling: whether to allow direct access (typing URL in browser address bar) allowEmptyReferer: false // Recommended false for production, can be true for testing } // 2. URL authentication (more secure hotlink protection with timestamp and signature) class URLAuth { constructor(config) { this.key = config.key // Authentication key, stored only on the server this.expireTime = config.expireTime || 3600 // Default 1 hour validity } /** * Generate an authenticated URL * @param {string} url - Original URL, e.g., https://cdn.example.com/images/photo.jpg * @param {number} expireIn - Validity period (seconds) * @returns {string} URL with authentication parameters */ sign(url, expireIn = this.expireTime) { const urlObj = new URL(url) const pathname = urlObj.pathname const timestamp = Math.floor(Date.now() / 1000) + expireIn // Construct signature string (format varies by provider; this is a generic example) const signStr = `${pathname}-${timestamp}-${this.key}` const signature = this._md5(signStr) // Add authentication parameters urlObj.searchParams.set('sign', signature) urlObj.searchParams.set('t', timestamp.toString()) return urlObj.toString() } /** * Verify URL signature (used at CDN edge or origin) */ verify(url) { const urlObj = new URL(url) const signature = urlObj.searchParams.get('sign') const timestamp = parseInt(urlObj.searchParams.get('t')) const pathname = urlObj.pathname // Check if expired if (timestamp < Math.floor(Date.now() / 1000)) { return { valid: false, error: 'URL expired' } } // Verify signature const signStr = `${pathname}-${timestamp}-${this.key}` const expectedSign = this._md5(signStr) if (signature !== expectedSign) { return { valid: false, error: 'Invalid signature' } } return { valid: true } } _md5(str) { // In real projects, use crypto-js or another MD5 library // This is a demonstration only return require('crypto').createHash('md5').update(str).digest('hex') } } // Usage example const auth = new URLAuth({ key: 'your-secret-key-only-known-by-server', expireTime: 3600 // 1 hour validity }) // Server generates signed URL const signedUrl = auth.sign( 'https://cdn.example.com/private/document.pdf', 7200 ) // Result: https://cdn.example.com/private/document.pdf?sign=xxxxx&t=1699123456 // CDN edge or origin verification const result = auth.verify(signedUrl) if (!result.valid) { // Return 403 Forbidden } // 3. IP Blacklist/Whitelist const ipConfig = { // Only allow specific IPs (suitable for internal systems) whiteList: [ '192.168.1.0/24', // Internal network segment '10.0.0.0/8' ], // Block specific IPs (ban attackers) blackList: ['1.2.3.4', '5.6.7.8'] } // 4. UA (User-Agent) Blacklist/Whitelist const uaConfig = { // Block crawlers/download tools blackList: [ 'Wget', 'curl', 'python-requests', 'Scrapy', 'AhrefsBot', 'SemrushBot' ], // Only allow browser access (strict mode) whiteList: [ 'Mozilla/*', // Modern browsers 'AppleWebKit/*' ] }
------
| English Term | Chinese Translation | Explanation |
|---|---|---|
| Object Storage | ๅฏน่ฑกๅญๅจ | A data storage architecture that manages data as objects rather than a file system hierarchy. Suitable for storing images, videos, backups, and other unstructured data. |
| Bucket | ๅญๅจๆกถ | The top-level container in object storage for organizing and isolating data. Each bucket has independent permission controls and configuration. |
| Object | ๅฏน่ฑก/ๆไปถๅฏน่ฑก | The basic unit of object storage, consisting of the data itself, metadata, and a globally unique key. |
| CDN | ๅ ๅฎนๅๅ็ฝ็ป | Content Delivery Network. Accelerates access by deploying edge nodes globally to cache website content closer to users. |
| Edge Node | ่พน็ผ่็น | Cache servers deployed across regions in a CDN network, directly serving content to users. |
| Origin | ๆบ็ซ | The server from which a CDN fetches content on a cache miss. Can be object storage, ECS, or a self-managed server. |
| Cache Hit | ็ผๅญๅฝไธญ | The requested content already exists on the CDN edge node and is returned directly without fetching from origin. |
| Cache Miss | ็ผๅญๆชๅฝไธญ | The edge node does not have the requested content and must fetch it from the origin. |
| Hit Ratio | ๅฝไธญ็ | The proportion of cache hits to total requests. Higher hit ratio means fewer origin fetches and lower costs. |
| TTL | ็ๅญๆถ้ด/็ผๅญๆถ้ด | Time To Live. The validity period of content cached on a CDN node. After expiration, it must be re-fetched from the origin. |
| Back to Source | ๅๆบ | The process of a CDN edge node requesting content from the origin. |
| Purge/Refresh | ๅทๆฐ็ผๅญ | Force CDN cache invalidation so the next request fetches the latest content from the origin. |
| Preheat | ้ข็ญ | Proactively push content to CDN nodes before official release, so users hit the cache on their first visit. |
| CORS | ่ทจๅ่ตๆบๅ ฑไบซ | Cross-Origin Resource Sharing. A browser security mechanism that controls resource access between different domains. |
| Referer | ๆฅๆบ้กต้ข | An HTTP request header field indicating which page the request was linked from. Used for hotlink protection. |
| STS | ๅฎๅ จไปค็ๆๅก | Security Token Service. A service that issues temporary access credentials, used for scenarios like frontend direct upload. |
| Multipart Upload | ๅ็ไธไผ | Splitting a large file into multiple chunks for parallel upload, supporting resumable uploads for improved efficiency and reliability. |
| ETag | ๅฎไฝๆ ็ญพ | An HTTP response header used to identify a specific version of a resource, commonly used for cache validation. |
| S3 API | S3 ๅ ผๅฎนๆฅๅฃ | AWS S3's object storage API specification, which most cloud providers' object storage services are compatible with. |
| Canonical Query String | ่ง่ๆฅ่ฏขๅญ็ฌฆไธฒ | Part of the signature string used to compute request signatures, ensuring requests are not tampered with. |
------
This architecture underpins the vast majority of static resource access on the internet. Understand it, and you understand the cornerstone of modern web performance optimization.This architecture underpins the vast majority of static resource access on the internet. Understand it, and you understand the cornerstone of modern web performance optimization.