Skip to content

Cloud

Object Storage (Buckets & Keys)

Put and get are O(1) — a direct lookup by key, no matter how many other objects exist in the bucket. Listing by prefix costs O(n) in the number of matching keys, since it has to find and return every match.

The idea, in plain English

Picture a self-storage facility with countless rooms, and every room has countless lockers. Each locker has a unique label taped to the front — not a folder path, just one long label like '2024/jan/sunset.png'. That's object storage. The room is a 'bucket,' a named container you create once. The label on each locker is its 'key,' a unique name; no two lockers in the same room share a label. What's inside the locker — the actual file, like a photo or a video — is the 'object.' Keys often look like folder paths with slashes in them, but there are no real subfolders here. It's genuinely one flat room of labeled lockers, and you can reach every locker directly by its label, without walking through any folders.

How it works

  1. 1Create a bucket first. This is a named container that will hold your objects, like naming the storage room before you rent lockers in it.
  2. 2Store something with 'put': give it a bucket, a unique key (the label), and the object itself. If that exact key already exists in that bucket, this overwrites it.
  3. 3Fetch something with 'get': give the bucket and key. If a locker with that exact label exists, you get its contents back — a HIT. If not, you get nothing — a MISS. There's no partial match.
  4. 4Browse what's in a bucket with 'list.' You can filter by prefix, meaning everything whose key starts with a given string. This is the closest thing to 'listing a folder,' even though it's really just a text match over flat labels.

When you'd use it

Use this for storing files that don't need a database's structure — user-uploaded photos, video files, PDFs, backups, log archives. Anything from a few kilobytes to many gigabytes, that you mostly write once and read many times, is a natural fit for object storage instead of a regular database.

Common beginner mistakes

  • Expecting real folders and subfolder operations, like renaming a 'folder.' A key with slashes in it is still just one flat string. Renaming a 'folder' means rewriting every key that starts with that prefix, one by one.
  • Assuming 'get' does partial or fuzzy matching on the key. It's an exact match only — even one different character is a MISS, not a close hit.
  • Reusing the same key for different content without meaning to. 'Put' silently overwrites, so a naming collision quietly destroys the previous object with no warning.

Try it — edit and run

Click the code to edit · press ⌘/Ctrl+↵ to run

Editable code. Tab and Shift+Tab indent. Press Escape, then Tab, to move focus out of the editor.

Expected output — hit Run to try it
Created bucket 'photos'
Uploaded photos/2024/jan/sunset.png (612 bytes)
Uploaded photos/2024/jan/party.png (305 bytes)
Uploaded photos/2024/feb/cat.png (802 bytes)
Uploaded photos/2023/dec/fireworks.png (1200 bytes)
Listing photos/2024/jan/* -> 2024/jan/party.png, 2024/jan/sunset.png
GET photos/2024/jan/sunset.png -> HIT (612 bytes)
GET photos/2024/jan/notfound.png -> MISS (no such key)

Not sure this is the right topic? See the learning paths → or where this leads →