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-photosbecause 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. Standard: Best for "hot" data accessed frequently (e.g., profile pictures on a live website). Most expensive storage, cheapest retrieval.
- 2. Nearline: Best for data accessed once a month (e.g., monthly reports).
- 3. Coldline: Best for data accessed once a quarter.
- 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 theStorage 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.
On your laptop, create an
index.htmlfile with a simple<h1>Hello World from GCP Storage!</h1>tag.
- 2. In the GCP Console, navigate to Cloud Storage > Buckets.
- 3. Click Create.
-
4.
Name: Give it a unique name (e.g.,
website-bucket-yourname12345).
- 5. Location type: Choose Region and pick a region near you.
- 6. Storage class: Choose Standard.
- 7. Access control: Uncheck "Enforce public access prevention on this bucket" (We *want* it to be public!). Click Create.
- 8. Once inside the bucket, click the Permissions tab.
- 9. Click Grant Access.
-
10.
In "New principals", type exactly:
allUsers.
- 11. In "Select a role", search for and select Storage Object Viewer. Click Save. (Acknowledge the warning that the bucket is now public).
-
12.
Go back to the Objects tab and click Upload Files. Upload your
index.htmlfile.
-
13.
Once uploaded, you will see a
Public URLlink 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
allUsersaccess 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 calledgsutil (soon to be integrated entirely into gcloud storage).
To create a new bucket:
bash
To upload a file from your laptop to the bucket:
bash
12. Exercises
-
1.
Why can two different GCP users not have buckets named
project-backups?
-
2.
Explain the financial tradeoff between the
Standardstorage class and theArchivestorage 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.