Almacenamiento de Objetos

Almacenamiento de blobs · S3

Escrito por Darjus Kazakevic · revisado el

Files as immutable objects under a key, served over HTTP, at almost any scale.

Object storage keeps bytes as objects in a bucket, each under a key such as uploads/42/avatar.png. You put, get and delete whole objects over HTTP. Amazon S3, Google Cloud Storage, Azure Blob Storage and MinIO work this way. S3 is designed for 99.999999999% durability.

It is not a filesystem. There are no real folders, no append and no rename; a change is a new upload. In return, storage is cheap (about $0.023 per GB per month for S3 Standard) and nearly unlimited. Presigned URLs let clients upload and download directly, so large files never pass through your servers.

En esencia — Store large, immutable files under a key in a bucket, and give clients presigned URLs so the bytes go straight to storage, not through your servers.

Cuándo recurrir a él

Recurre a él cuando

  • Uploads, media and exports too large to belong in the database
  • Clients should move bytes directly, without passing through your app
  • Backups, logs and data-lake files kept for months or years

Reconsidéralo cuando

  • Data appended to or edited in place: objects are only replaced whole
  • Code that needs folder listings, renames or atomic moves to be cheap
  • Many small records updated often; that is a database's job

Conceptos clave

Bucket, key, object
A bucket is a container. An object is bytes plus metadata. The key is the object's full name. In a/b/c.jpg the slashes only look like folders, and listing a "folder" is a query by key prefix.
Presigned URL
A URL signed with your credentials that allows one operation, such as PUT or GET, on one key, for a limited time like 5 minutes. The client uses it directly, and your server never handles the bytes.
Multipart upload
A large file is uploaded in parts and joined at the end. Parts upload in parallel, and a failed part is retried alone. In S3, a single PUT is limited to 5 GB, so bigger objects must use multipart.
Storage classes and lifecycle rules
Cheaper classes trade access speed and retrieval fees for a lower price: S3 Standard, Standard-IA, Glacier. A lifecycle rule moves or deletes objects by age, for example to Glacier after 90 days.
Consistency
Since December 2020, S3 gives strong read-after-write consistency: a GET after a successful PUT returns the new object. A CDN or cache in front can still serve an old copy.

Reglas de diseño

Hand out presigned URLs, not bytes
Your server decides who may write which key, signs that for a few minutes, and the client talks to the bucket directly. Your servers never see the bytes, so uploads stop being a load problem.
Store the key in your database, not the URL
Presigned URLs expire and domains change. Save the bucket key and metadata such as size, type and owner, and sign a fresh URL each time you serve the file.
Treat an edit as a new key
Objects are replaced whole, never patched, and there is no rename. Write the new version under a new key, update the pointer in your database, then delete the old object.
Keep buckets private
Turn on Block Public Access. Serve files through short-lived presigned GET URLs or a CDN that alone can read the bucket. Most bucket data leaks come from a public setting nobody meant to keep.

Errores habituales

  • Streaming uploads through the app server, so a few large files use up its memory and bandwidth.
  • Saving presigned URLs in the database, then serving links that expired days ago.
  • Never aborting failed multipart uploads; their parts are billed until a lifecycle rule removes them.
  • Making a bucket public to fix one broken link, and exposing every object in it.