Skip to main content
Google Cloud Platform (GCP)
CHAPTER 05

Google Cloud Storage (GCS)

Updated: May 15, 2026
20 min read

# CHAPTER 5

Google Cloud Storage (GCS)

1. Introduction

If you are building the next Netflix or Instagram, you cannot store millions of videos and photos on the hard drive of a Virtual Machine. If the VM crashes, the data is gone, and VM hard drives are incredibly expensive to scale. Enter Google Cloud Storage (GCS). GCS is an "Object Storage" service. It provides infinite, highly durable, and incredibly cheap storage space. In this chapter, we will learn how to create Buckets, manage Storage Classes to save money, and host a static website directly from storage.

2. Learning Objectives

By the end of this chapter, you will be able to:
  • Define Object Storage and contrast it with Block/File Storage.
  • Understand the hierarchy of Buckets and Objects.
  • Choose the correct Storage Class (Standard, Nearline, Coldline, Archive).
  • Upload and manage objects via the Console and CLI.
  • Host a public, static HTML website using a GCS Bucket.

3. Beginner-Friendly Explanation

Imagine a massive, magical warehouse.
  • Block Storage (VM Hard Drives): Like a filing cabinet. Fast, structured, but has a strict physical limit. When it's full, you have to buy a bigger cabinet.
  • Object Storage (Cloud Storage): Like throwing boxes into an infinitely expanding warehouse. You don't organize the boxes on shelves; you just attach a barcode label (the URL) to the box and throw it in. When you need the box, you ask the warehouse for the barcode, and it instantly retrieves it. The warehouse never gets full, and you only pay for the exact space your boxes take up.

4. Buckets and Objects

In GCS, data is stored in containers called Buckets.
  • Buckets: The top-level folder. *Crucial Rule:* Bucket names must be Globally Unique across all of Google Cloud. You cannot name your bucket my-photos because someone else in the world already claimed it.
  • Objects: The actual files (images, videos, text files) you put inside the bucket.

5. Storage Classes (Saving Money)

Google charges you based on *how often* you need to access the data.
  1. 1. Standard: Best for "hot" data accessed frequently (e.g., profile pictures on a live website). Most expensive storage, cheapest retrieval.
  1. 2. Nearline: Best for data accessed once a month (e.g., monthly reports).
  1. 3. Coldline: Best for data accessed once a quarter.
  1. 4. Archive: Best for data you hope to *never* access, like legal compliance backups kept for 10 years. Extremely cheap to store, but incredibly expensive if you actually download it!

6. Permissions and Public Access

By default, every bucket and file you create is highly secure and private. Only your Google account can see it. If you want to use a bucket to serve images for a public website, you must explicitly change the IAM permissions to grant the Storage Object Viewer role to the identity allUsers.

7. Mini Project: Host a Static Website

We don't need a Virtual Machine to host a simple HTML/CSS website!

Step-by-Step Tutorial:

  1. 1. On your laptop, create an index.html file with a simple <h1>Hello World from GCP Storage!</h1> tag.
  1. 2. In the GCP Console, navigate to Cloud Storage > Buckets.
  1. 3. Click Create.
  1. 4. Name: Give it a unique name (e.g., website-bucket-yourname12345).
  1. 5. Location type: Choose Region and pick a region near you.
  1. 6. Storage class: Choose Standard.
  1. 7. Access control: Uncheck "Enforce public access prevention on this bucket" (We *want* it to be public!). Click Create.
  1. 8. Once inside the bucket, click the Permissions tab.
  1. 9. Click Grant Access.
  1. 10. In "New principals", type exactly: allUsers.
  1. 11. In "Select a role", search for and select Storage Object Viewer. Click Save. (Acknowledge the warning that the bucket is now public).
  1. 12. Go back to the Objects tab and click Upload Files. Upload your index.html file.
  1. 13. Once uploaded, you will see a Public URL link next to the file. Click it! Your website is live on the internet, and you are paying fractions of a penny to host it!

8. Real-World Scenarios

A hospital generates thousands of X-Ray images (10GB total) daily. They need immediate access to X-Rays taken this week (Standard Storage). However, by law, they must keep all X-Rays for 7 years. A Cloud Engineer configures an Object Lifecycle Policy on the GCS bucket. The rule automatically moves any X-Ray older than 30 days into the ultra-cheap "Archive" storage class. This zero-maintenance automation saves the hospital hundreds of thousands of dollars a year in storage costs.

9. Best Practices

  • Never Make Private Data Public: The #1 cause of cloud data breaches is an engineer accidentally granting allUsers access to a bucket containing sensitive customer data (like database backups or PII). Triple-check your bucket permissions!

10. Cost Optimization Tips

  • Use the Right Class: If you dump 50 Terabytes of disaster recovery backups into "Standard" storage, you will receive a massive bill. Analyze how often data is accessed and relentlessly utilize Coldline or Archive storage for backups.

11. CLI Examples

The command-line tool for Cloud Storage is called gsutil (soon to be integrated entirely into gcloud storage). To create a new bucket:
bash
1
gsutil mb gs://my-unique-bucket-name

To upload a file from your laptop to the bucket:

bash
1
gsutil cp my-picture.jpg gs://my-unique-bucket-name

12. Exercises

  1. 1. Why can two different GCP users not have buckets named project-backups?
  1. 2. Explain the financial tradeoff between the Standard storage class and the Archive storage class.

13. FAQs

Q: Can I run a PHP or Node.js backend using Cloud Storage? A: No. Cloud Storage can only host "Static" assets (HTML, CSS, JavaScript, Images). It has no compute power to execute backend server-side code like PHP.

14. Interview Questions

  • Q: Describe the architectural difference between Block Storage (Persistent Disks) and Object Storage (Cloud Storage). When would you architecturally mandate the use of one over the other?
  • Q: A client needs to store petabytes of financial compliance logs that must be retained for 5 years but will likely never be audited. Detail your storage class recommendation and explain how you would automate the cost-reduction pipeline over time.

15. Summary

In Chapter 5, we solved the problem of infinite data storage. We introduced Google Cloud Storage as a massively scalable Object Storage solution, untethered from the physical limitations of Virtual Machine hard drives. We explored the financial impact of Storage Classes, prioritizing data based on access frequency. Finally, we manipulated IAM permissions to expose a bucket to the public internet, successfully deploying a serverless, static HTML website with zero compute overhead.

16. Next Chapter Recommendation

We have Servers and Storage. But right now, they are just floating in the cloud. We need to connect them together securely. Proceed to Chapter 6: Virtual Private Cloud (VPC) Networking.

Finish this Chapter

Save your progress on your learning path and prepare for coding interview challenges.

Discussion

Join the discussion

Log in or create a free account to participate.

Sort: ·