Overview and What You Will Learn
Pick the Cloud Storage class by how often you read the data and how long you will keep it: Standard for frequent access, Nearline for about monthly, Coldline for about quarterly, and Archive for less than yearly. Every class colder than Standard has a minimum storage duration, and deleting an object earlier still bills you for the full minimum.
In this lab, you will:
- Create a bucket and upload objects into different classes
- Change an object's class and see that it counts as a rewrite
- Calculate the early-deletion charge on short-lived data and find the break-even point
- Automate class changes with a Lifecycle rule, then with Autoclass
Why This Matters in Production
A cold class only saves money when the data really stays put for the minimum duration. Imagine a platform team at a company like Zerodha that moves daily export files into Coldline for the lower per-GB price, then deletes them after 10 days. Coldline bills each file as if it had been stored for 90 days, so those short-lived files cost more than they would have in Standard. Teams at companies like Netflix and Datadog check real retention against minimum duration before choosing any cold tier.
Core Principles
Colder classes lower the storage price and raise the retrieval price, and they add a minimum duration you pay for even if you delete sooner. Pick the class from two questions: how often will this be read, and how long will it live.
the data read?] D -->|Frequently| S[Standard
no minimum] D -->|About monthly| N[Nearline
30-day minimum] D -->|About quarterly| C[Coldline
90-day minimum] D -->|Under yearly| A[Archive
365-day minimum] classDef decision fill:#F59E0B,color:#111827 classDef hot fill:#EF4444,color:#FFFFFF classDef warm fill:#F97316,color:#FFFFFF classDef cold fill:#326CE5,color:#FFFFFF class D decision class S hot class N warm class C,A cold
| Class | Typical access | Minimum duration |
|---|---|---|
| Standard | Frequent | None |
| Nearline | About once a month | 30 days |
| Coldline | About once a quarter | 90 days |
| Archive | Less than once a year | 365 days |
RememberAll four classes have the same low latency and the same API. The difference is price structure, not speed to first byte.
Detailed Step-by-Step Practical Lab
Use a sandbox project with billing enabled. Bucket names are globally unique, so replace the rahul part with your own suffix.
- Set the project and create a Standard bucket:
gcloud config set project mumbai-prod-storage-lab gcloud storage buckets create gs://storage-lab-rahul-2026 \ --location=asia-south1 \ --default-storage-class=STANDARD- Upload one file at the default class and one directly into Nearline:
echo "audit entry 2026-10-13" > audit-log.txtgcloud storage cp audit-log.txt gs://storage-lab-rahul-2026/audit-standard.txtgcloud storage cp audit-log.txt gs://storage-lab-rahul-2026/audit-nearline.txt \ --storage-class=NEARLINE- Check each object's class:
gcloud storage objects describe gs://storage-lab-rahul-2026/audit-standard.txt \ --format="value(storage_class)"gcloud storage objects describe gs://storage-lab-rahul-2026/audit-nearline.txt \ --format="value(storage_class)"- Change the Standard object to Coldline. This rewrites the object, so it counts as a new object and its minimum duration starts from now:
gcloud storage objects update gs://storage-lab-rahul-2026/audit-standard.txt \ --storage-class=COLDLINE gcloud storage objects describe gs://storage-lab-rahul-2026/audit-standard.txt \ --format="value(storage_class)"- Estimate the early-deletion penalty. The prices below are placeholders for illustration, so replace them with current prices from the Cloud Storage pricing page for your region:
STANDARD_PRICE=0.020COLDLINE_PRICE=0.004SIZE_GB=1000DAYS_KEPT=10MIN_DAYS=90 # Coldline bills at least MIN_DAYS, even if the data is deleted soonerBILLED_DAYS=$(( DAYS_KEPT > MIN_DAYS ? DAYS_KEPT : MIN_DAYS )) STANDARD_COST=$(echo "scale=2; $SIZE_GB * $STANDARD_PRICE * $DAYS_KEPT / 30" | bc)COLDLINE_COST=$(echo "scale=2; $SIZE_GB * $COLDLINE_PRICE * $BILLED_DAYS / 30" | bc) echo "Standard for $DAYS_KEPT days: \$$STANDARD_COST"echo "Coldline billed for $BILLED_DAYS days: \$$COLDLINE_COST"With these numbers, Standard costs about $6.66 and Coldline costs $12.00, so the cold class loses. The break-even point is the minimum duration multiplied by the price ratio: 90 days x 0.004 / 0.020 = 18 days. Change DAYS_KEPT to 30 to see Coldline win. Retrieval charges would add to the Coldline side as well.
- Apply a Lifecycle rule so data ages into colder classes automatically. Lifecycle files are JSON, and
SetStorageClasscan only move objects to a colder class:
cat > lifecycle-config.json << 'LIFECYCLEEOF'{ "rule": [ { "action": { "type": "SetStorageClass", "storageClass": "COLDLINE" }, "condition": { "age": 90, "matchesStorageClass": ["STANDARD", "NEARLINE"] } }, { "action": { "type": "SetStorageClass", "storageClass": "ARCHIVE" }, "condition": { "age": 365, "matchesStorageClass": ["COLDLINE"] } } ]}LIFECYCLEEOF gcloud storage buckets update gs://storage-lab-rahul-2026 \ --lifecycle-file=lifecycle-config.json gcloud storage buckets describe gs://storage-lab-rahul-2026 \ --format="json(lifecycle_config)"- For buckets with unpredictable access, enable Autoclass instead of hand-written rules. Autoclass moves each object between classes based on how it is actually accessed, and it does not charge retrieval or early-deletion fees for objects it manages. It cannot be combined with Lifecycle rules that set the storage class, so clear the rules first:
gcloud storage buckets update gs://storage-lab-rahul-2026 --clear-lifecyclegcloud storage buckets update gs://storage-lab-rahul-2026 --enable-autoclass gcloud storage buckets describe gs://storage-lab-rahul-2026 \ --format="value(autoclass.enabled)"- Clean up:
gcloud storage rm --recursive gs://storage-lab-rahul-2026rm -f audit-log.txt lifecycle-config.jsonProduction Best Practices & Common Pitfalls
Common MistakeChoosing a colder class only for its lower per-GB price without comparing the minimum duration to how long the data will really live. Data deleted or overwritten early is billed for the full minimum, and for objects that live only a few weeks it can cost more than Standard would have.
TipAutomate class transitions with a Lifecycle rule or Autoclass instead of reclassifying by hand, so aging data moves to cheaper storage consistently.
- Retrieval and operation costs differ by class. Archive has the lowest storage price and the highest retrieval price, so it suits data that is almost never read, not data that is merely old.
- Changing a class rewrites the object. Updating a class by hand is a rewrite operation, and it restarts the minimum-duration clock for the new class.
- Match the class to the whole lifecycle. Compliance data kept for years suits cold tiers well, but temporary exports and rolling logs usually do not.
- Choose Autoclass when access is unpredictable. Use Lifecycle rules when age predicts access well, and Autoclass when it does not.
- Consider the bucket location. Dual-region and multi-region buckets cost more per GB, so choose location and class together.
Quick Reference & Troubleshooting Commands
| Command | Description |
|---|---|
gcloud storage buckets create --default-storage-class= |
Create a bucket with a default class |
gcloud storage cp --storage-class= |
Upload an object into a specific class |
gcloud storage objects update --storage-class= |
Rewrite an object into another class |
gcloud storage objects describe --format="value(storage_class)" |
Check an object's class |
gcloud storage buckets update --lifecycle-file= |
Apply Lifecycle rules from a JSON file |
gcloud storage buckets update --enable-autoclass |
Turn on Autoclass for a bucket |