Storage classes, lifecycle and versioning

Google Cloud · Practical · 10 min

Storage bills grow quietly; lifecycle rules and the right class can cut them by an order of magnitude.

Every object has a storage class. All have the same latency and durability; they differ in price per GB, retrieval fee and minimum storage duration:

  • Standard: hot data, no minimum duration.
  • Nearline: accessed about once a month; 30-day minimum.
  • Coldline: about once a quarter; 90-day minimum.
  • Archive: less than once a year; 365-day minimum.

Deleting or rewriting an object before its minimum is billed as if it stayed. Retrieval fees make cold classes expensive to read often.

Lifecycle rules act on objects automatically: SetStorageClass after N days, Delete after N days, delete noncurrent versions, abort incomplete multipart uploads. Rules are evaluated asynchronously, typically within a day. If you cannot predict access patterns, Autoclass moves each object between classes based on actual use.

Object versioning keeps the previous generation as a noncurrent version when an object is overwritten or deleted. Pair it with a lifecycle rule that deletes old versions, or costs grow forever.

For compliance there are retention policies (objects cannot be deleted before an age, optionally locked permanently) and object holds. Soft delete protects against accidental deletes even without versioning.

Example

cat > lifecycle.json <<'EOF'
{"rule": [
  {"action": {"type": "SetStorageClass", "storageClass": "NEARLINE"},
   "condition": {"age": 30, "matchesStorageClass": ["STANDARD"]}},
  {"action": {"type": "SetStorageClass", "storageClass": "ARCHIVE"},
   "condition": {"age": 365}},
  {"action": {"type": "Delete"},
   "condition": {"isLive": false, "numNewerVersions": 3}}
]}
EOF
gcloud storage buckets update gs://shop-dev-4821-uploads \
  --lifecycle-file=lifecycle.json --versioning
gcloud storage buckets describe gs://shop-dev-4821-uploads --format="yaml(lifecycle_config,versioning_enabled)"

Remember

  • Same latency in every class; colder = cheaper storage, pricier access, longer minimums
  • Lifecycle rules automate transitions and deletion
  • Versioning needs a cleanup rule for noncurrent versions

Watch out for

  • Moving frequently-read data to Coldline to save money and paying more in retrieval fees.

Check yourself

  1. You upload an object to Archive and delete it after 10 days. How long are you billed for?

Sign in to answer, see the explanations, and get this lesson back as a quick review later.

Official docs: cloud.google.com/storage/docs/storage-classes

Builds on

Unlocks

Nothing builds on this yet.