VibeKoding / Ensiklopedia ยท Fondasi KuatEnsiklopedia ยท Fondasi Kuat / An Introduction to File and Object StorageAn Introduction to File and Object Storage
VK

An Introduction to File and Object StorageAn Introduction to File and Object Storage

๐Ÿ“š Ensiklopedia ยท Fondasi KuatEnsiklopedia ยท Fondasi Kuat ๐ŸŒ Dual Bahasa (ID / EN) โšก VibeKoding Native

Ensiklopedia VibeKoding: An Introduction to File and Object Storage.Ensiklopedia VibeKoding: An Introduction to File and Object Storage.

๐Ÿ’ก Tips Praktis๐Ÿ’ก Pro Tip

A user uploads an avatar, and you save it in the server's /uploads directory โ€” then the server's disk fills up, or you add a second server and the user finds their avatar appears and disappears. File storage seems simple, but in distributed environments it's an architectural problem that requires serious attention. Object storage is the standard answer to this problem in the internet age.A user uploads an avatar, and you save it in the server's /uploads directory โ€” then the server's disk fills up, or you add a second server and the user finds their avatar appears and disappears. File storage seems simple, but in distributed environments it's an architectural problem that requires serious attention. Object storage is the standard answer to this problem in the internet age.

What will you learn in this article?What will you learn in this article?

After reading this chapter, you will gain:After reading this chapter, you will gain:

ChapterContentCore Concepts
Chapter 1Storage type comparisonBlock storage, file storage, object storage
Chapter 2Object storage core conceptsBucket, Object, Key, Metadata
Chapter 3File upload solutionsClient-side direct upload, Pre-signed URL
Chapter 4CDN accelerationEdge nodes, cache policies, origin fetch
Chapter 5Best practicesNaming conventions, permissions, lifecycle

------

0. The Big Picture: Motivation for Caning 't You Store Files on the Server Locally0. The Big Picture: Motivation for Caning 't You Store Files on the Server Locally

When starting a project, saving user-uploaded files in a local server directory is the most intuitive approach. But as the project grows, you'll encounter a series of problems:When starting a project, saving user-uploaded files in a local server directory is the most intuitive approach. But as the project grows, you'll encounter a series of problems:

๐Ÿ’ก Tips Praktis๐Ÿ’ก Pro Tip

Object storage (like AWS S3, Alibaba Cloud OSS) solves all these problems: infinite capacity, globally accessible, automatic backup, native CDN support. It has become the de facto standard for file storage in internet applications.Object storage (like AWS S3, Alibaba Cloud OSS) solves all these problems: infinite capacity, globally accessible, automatic backup, native CDN support. It has become the de facto standard for file storage in internet applications.

------

1. Storage Type Comparison: Block, File, Object1. Storage Type Comparison: Block, File, Object

There are three main storage types in the computing world, each solving problems at different levels.There are three main storage types in the computing world, each solving problems at different levels.

DimensionBlock StorageFile StorageObject Storage
Data unitFixed-size blocksFiles + directoriesObjects (Key-Value)
Access protocoliSCSI/FCNFS/SMBHTTP REST API
PerformanceHighest (millisecond)MediumLower (but sufficient)
ScalabilityLimitedMediumNearly infinite
CostHighestMediumLowest
Typical use caseDatabasesShared filesImages/video/backups
๐Ÿ’ก Tips Praktis๐Ÿ’ก Pro Tip

- Block storage is like a hard drive โ€” for databases - File storage is like a network shared folder โ€” for sharing configurations across multiple servers - Object storage is like cloud storage โ€” for user-uploaded images and videos- Block storage is like a hard drive โ€” for databases - File storage is like a network shared folder โ€” for sharing configurations across multiple servers - Object storage is like cloud storage โ€” for user-uploaded images and videos

------

2. Object Storage Core Concepts2. Object Storage Core Concepts

The data model of object storage is very simple: a Bucket is the container, an Object is the file, and each object is identified by a unique Key.The data model of object storage is very simple: a Bucket is the container, an Object is the file, and each object is identified by a unique Key.

CODE
my-app-bucket/ โ† Bucket โ”œโ”€โ”€ avatars/user-123.jpg โ† Object Key โ”œโ”€โ”€ avatars/user-456.png โ† Object Key โ”œโ”€โ”€ reports/2024/q1-report.pdf โ† Object Key ("directory" is just a Key prefix) โ””โ”€โ”€ uploads/temp/file.zip โ† Object Key
ConceptDescriptionExample
BucketStorage container, globally unique namemy-app-prod, company-assets
ObjectThe stored file itself + metadataAn image, a PDF
KeyThe object's unique identifieravatars/user-123.jpg
MetadataAdditional information about the objectContent-Type, custom tags
ACLAccess Control Listpublic-read, private
Pre-signed URLTemporary authorized access linkUpload/download link valid for 15 minutes
๐Ÿ’ก Tips Praktis๐Ÿ’ก Pro Tip

avatars/user-123.jpg โ€” the avatars/ part is not a directory, just a Key prefix. Object storage is a flat structure; all objects are at the same level. The "folders" displayed in the console are just visual grouping by prefix.avatars/user-123.jpg โ€” the avatars/ part is not a directory, just a Key prefix. Object storage is a flat structure; all objects are at the same level. The "folders" displayed in the console are just visual grouping by prefix.

------

3. File Upload Solutions: Who Uploads the File3. File Upload Solutions: Who Uploads the File

There are two mainstream approaches for file upload: server-side relay and client-side direct upload. For most scenarios, client-side direct upload is the better choice.There are two mainstream approaches for file upload: server-side relay and client-side direct upload. For most scenarios, client-side direct upload is the better choice.

๐Ÿ’ก Tips Praktis๐Ÿ’ก Pro Tip

1. Saves server bandwidth: Files don't pass through your server; they go directly to OSS 2. Avoids timeouts: Large file uploads won't trigger Nginx/gateway timeout limits 3. Reduces server load: The server only needs to issue credentials, not process file streams 4. Supports resumable uploads: OSS natively supports multipart upload; the frontend can implement resumable uploads Implementation steps: Frontend requests a Pre-signed URL from the backend โ†’ Frontend uses this URL to upload directly to OSS โ†’ OSS callback notifies the backend1. Saves server bandwidth: Files don't pass through your server; they go directly to OSS 2. Avoids timeouts: Large file uploads won't trigger Nginx/gateway timeout limits 3. Reduces server load: The server only needs to issue credentials, not process file streams 4. Supports resumable uploads: OSS natively supports multipart upload; the frontend can implement resumable uploads Implementation steps: Frontend requests a Pre-signed URL from the backend โ†’ Frontend uses this URL to upload directly to OSS โ†’ OSS callback notifies the backend

------

4. CDN Acceleration: Making It Fast for Users Worldwide4. CDN Acceleration: Making It Fast for Users Worldwide

When your users are distributed globally, downloading files from a single origin server is slow. CDN (Content Delivery Network) deploys edge nodes worldwide, caching files at nodes closest to users, dramatically reducing access latency.When your users are distributed globally, downloading files from a single origin server is slow. CDN (Content Delivery Network) deploys edge nodes worldwide, caching files at nodes closest to users, dramatically reducing access latency.

CDN ConceptDescription
Edge nodeCache servers distributed around the world
Origin fetchWhen an edge node doesn't have a cached copy, it requests the file from the origin server
Cache hit rateThe proportion of requests served directly by edge nodes; the higher the better
TTLCache validity period; after expiration, a new origin fetch is needed
Cache invalidationProactively clearing edge node caches to make new files take effect
๐Ÿ’ก Tips Praktis๐Ÿ’ก Pro Tip

- Add hash to filenames: logo.a3f2b1.png instead of logo.png, so you don't need to invalidate cache when updating files - Set reasonable TTLs: Static assets (JS/CSS/images) get long TTLs (1 year), HTML gets short TTLs (5 minutes) - Enable Gzip/Brotli compression: Text-based resources can be reduced by 60-80% after compression- Add hash to filenames: logo.a3f2b1.png instead of logo.png, so you don't need to invalidate cache when updating files - Set reasonable TTLs: Static assets (JS/CSS/images) get long TTLs (1 year), HTML gets short TTLs (5 minutes) - Enable Gzip/Brotli compression: Text-based resources can be reduced by 60-80% after compression

------

5. Best Practices5. Best Practices

PracticeDescriptionExample
Key naming conventionUse meaningful prefixes to organize files{type}/{date}/{uuid}.{ext}
Avoid hot spot KeysDon't start with incrementing numbersUse UUID or hash prefixes
Minimum necessary permissionsBucket defaults to privateOnly set public-read for files that need to be public
Lifecycle rulesAutomatically clean up expired filesTemp files auto-deleted after 7 days
CORS configurationFrontend direct upload requires CORS setupAllow your domain to PUT/POST
Server-side encryptionEnable SSE for sensitive filesSSE-S3 or SSE-KMS

------

SummarySummary

File storage is a fundamental issue that every web application encounters. Object storage, with its infinite capacity, low cost, and high availability, has become the standard choice for internet applications.File storage is a fundamental issue that every web application encounters. Object storage, with its infinite capacity, low cost, and high availability, has become the standard choice for internet applications.

Key takeaways from this chapter:Key takeaways from this chapter:

  1. Three storage types: Block storage for databases, file storage for sharing, object storage for user filesThree storage types: Block storage for databases, file storage for sharing, object storage for user files
  2. Object storage model: Bucket + Key + Object, flat structure, HTTP API accessObject storage model: Bucket + Key + Object, flat structure, HTTP API access
  3. Client-side direct upload: Pre-signed URL approach โ€” files don't pass through the server, efficient and resource-savingClient-side direct upload: Pre-signed URL approach โ€” files don't pass through the server, efficient and resource-saving
  4. CDN acceleration: Edge node caching + filename hashing, making it fast for users worldwideCDN acceleration: Edge node caching + filename hashing, making it fast for users worldwide
  5. Security and management: Minimum necessary permissions, lifecycle rules, server-side encryptionSecurity and management: Minimum necessary permissions, lifecycle rules, server-side encryption
  6. Further ReadingFurther Reading

    • [AWS S3 Developer Guide](https://docs.aws.amazon.com/s3/) - The benchmark documentation for object storage[AWS S3 Developer Guide](https://docs.aws.amazon.com/s3/) - The benchmark documentation for object storage
    • [Alibaba Cloud OSS Best Practices](https://help.aliyun.com/document_detail/31853.html) - The most commonly used object storage in China[Alibaba Cloud OSS Best Practices](https://help.aliyun.com/document_detail/31853.html) - The most commonly used object storage in China
    • [MinIO Documentation](https://min.io/docs/minio/linux/index.html) - Open-source S3-compatible object storage[MinIO Documentation](https://min.io/docs/minio/linux/index.html) - Open-source S3-compatible object storage
    • [Cloudflare R2](https://developers.cloudflare.com/r2/) - Object storage with zero egress fees[Cloudflare R2](https://developers.cloudflare.com/r2/) - Object storage with zero egress fees
    • [Pre-signed URL Details](https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html) - The core mechanism for client-side direct upload[Pre-signed URL Details](https://docs.aws.amazon.com/AmazonS3/latest/userguide/using-presigned-url.html) - The core mechanism for client-side direct upload