Win Big with Google Cloud NEXT '26: $1,000 in Prizes for the Best Cloud Stories

Published: (April 28, 2026 at 09:02 PM EDT)
3 min read
Source: Dev.to

Source: Dev.to

๐ŸŽฏ Step 1 โ€“ Pick a Real Problem You Solved with Google Cloud

The best stories start with pain. Think: โ€œBefore GCP, we had X problem. After GCP, we achieved Y.โ€

Examples

  • Reduced API latency from 2โ€ฏs to 200โ€ฏms using Cloud Runโ€ฏ+โ€ฏCloud SQL
  • Automated monthly reports with Cloud Functions and BigQuery
  • Scaled image processing with Cloud Storageโ€ฏ+โ€ฏPub/Subโ€ฏ+โ€ฏCloud Functions

Your Turn โ€“ Choose one real project. For this guide weโ€™ll use:

โ€œI built a serverless URL shortener using Cloud Run, Firestore, and Firebase Hosting โ€” cutting costs by 70โ€ฏ% vs. EC2.โ€

๐Ÿ’ป Step 2 โ€“ Build & Document Your Project (With Code)

1. Set Up Your Environment

# Install Google Cloud CLI
curl https://sdk.cloud.google.com | bash
gcloud init

# Enable required APIs
gcloud services enable run.googleapis.com
gcloud services enable firestore.googleapis.com
gcloud services enable cloudbuild.googleapis.com

2. Create the Flask App (main.py)

from flask import Flask, request, jsonify, redirect
from google.cloud import firestore
import string, random, os
import logging
import google.cloud.logging

app = Flask(__name__)
db = firestore.Client()

# Enable Cloud Logging
logging_client = google.cloud.logging.Client()
logging_client.setup_logging()

def generate_short_id(length=6):
    return ''.join(random.choices(string.ascii_letters + string.digits, k=length))

@app.route('/shorten', methods=['POST'])
def shorten():
    logging.info("Shorten request received")
    data = request.get_json()
    long_url = data.get('url')
    if not long_url:
        return jsonify({'error': 'URL is required'}), 400

    short_id = generate_short_id()
    doc_ref = db.collection('urls').document(short_id)
    doc_ref.set({'long_url': long_url})

    logging.info(f"Generated short ID: {short_id}")
    return jsonify({'short_url': f"https://your-domain.com/{short_id}"}), 201

@app.route('/')
def redirect_url(short_id):
    doc_ref = db.collection('urls').document(short_id)
    doc = doc_ref.get()
    if doc.exists:
        return redirect(doc.to_dict()['long_url'])
    else:
        return "Not found", 404

if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=int(os.getenv('PORT', 8080)))

3. Add requirements.txt

Flask==2.3.3
google-cloud-firestore==2.13.0
google-cloud-logging==3.5.0

4. Create Dockerfile

FROM python:3.11-slim

WORKDIR /app
COPY requirements.txt .
RUN pip install --no-cache-dir -r requirements.txt

COPY . .

CMD ["python", "main.py"]

๐Ÿš€ Step 3 โ€“ Deploy to Google Cloud Run

1. Build and Deploy

# Set your project ID
gcloud config set project YOUR_PROJECT_ID

# Build and deploy
gcloud run deploy url-shortener \
  --source . \
  --platform managed \
  --region us-central1 \
  --allow-unauthenticated

Output: Youโ€™ll receive a public URL such as https://url-shortener-abcd-uc.a.run.app.

2. Test the API

curl -X POST https://url-shortener-abcd-uc.a.run.app/shorten \
  -H "Content-Type: application/json" \
  -d '{"url": "https://dev.to"}'

Expected response

{
  "short_url": "https://your-domain.com/aB3x9k"
}

Visiting the returned short_url redirects to the original site.

๐Ÿ“Š Step 4 โ€“ Add Monitoring (Bonus Points!)

Observability strengthens a submission. The example above already integrates Cloud Logging. After deploying, view logs in the Cloud Console Logs Viewer.

๐Ÿ† Step 5 โ€“ Write Your Story (Template)

Title

How I Built a Serverless URL Shortener on GCP โ€” For $5/Month

Problem

Describe the pain point you faced (e.g., high cost and low scalability of an EC2โ€‘based solution).

Solution

Explain the architecture (Cloud Run, Firestore, Firebase Hosting) and why it solved the problem.

Implementation

Include code snippets, deployment steps, and any CI/CD pipelines you used.

Results

Quantify improvements (cost reduction, latency, scalability).

Lessons Learned & Best Practices

Share challenges, optimizations, and advice for others.

0 views
Back to Blog

Related posts

Read more ยป