GCP App Engine

App Engine is GCP's fully managed Platform as a Service (PaaS) for building and deploying web applications. Developers write the application code, and App Engine handles the deployment, scaling, load balancing, and server management automatically. There are no virtual machines to set up or maintain.

App Engine is ideal when the goal is to ship a web application quickly without worrying about the underlying infrastructure. Write code, run one command, and the app is live on the internet.

App Engine Environments

App Engine has two runtime environments:

FeatureStandard EnvironmentFlexible Environment
LanguagesPython, Java, Go, Node.js, PHP, RubyAny language via Docker
ScalingScales to zero (no cost when idle)Minimum 1 instance always running
Cold StartsYes (brief delay when idle)No (always warm)
Custom LibrariesLimitedFull access (Docker-based)
Best ForLightweight web apps, APIsApps with custom dependencies or frameworks

App Engine Application Structure

my-app/
├── main.py          ← Application code (Python example)
├── app.yaml         ← App Engine configuration file
├── requirements.txt ← Python dependencies
└── static/
    └── index.html   ← Static assets (optional)

app.yaml – The Configuration File

The app.yaml file tells App Engine how to run the application. It defines the runtime, scaling settings, and environment variables.

# app.yaml for a Python app
runtime: python311

instance_class: F2

automatic_scaling:
  min_instances: 0
  max_instances: 5
  target_cpu_utilization: 0.65

env_variables:
  DB_HOST: "10.0.0.5"
  APP_ENV: "production"

Building and Deploying a Simple Web App

Step 1 – Write the Application (Python + Flask)

# main.py
from flask import Flask

app = Flask(__name__)

@app.route('/')
def home():
    return '<h1>Hello from App Engine!</h1>'

@app.route('/about')
def about():
    return '<p>This app runs on Google App Engine.</p>'

if __name__ == '__main__':
    app.run(host='0.0.0.0', port=8080)

Step 2 – Add Dependencies

# requirements.txt
Flask==3.0.0

Step 3 – Deploy to App Engine

# Deploy from the app directory using Cloud Shell
gcloud app deploy

# After deployment, open the app in a browser
gcloud app browse

App Engine assigns a URL like https://my-project.uc.r.appspot.com. The app is publicly accessible immediately.

App Engine Scaling

App Engine automatically adjusts the number of running instances based on traffic. Three scaling modes are available:

Automatic Scaling (default):
Traffic ↑ → More instances created
Traffic ↓ → Instances removed (scales to 0 in Standard)

Manual Scaling:
Set a fixed number of instances that always run

Basic Scaling:
Instances created on-demand, removed after idle timeout

Traffic Flow Diagram

Internet
   │
   ▼
App Engine Load Balancer
   │
   ├──▶ Instance 1 (handles request)
   ├──▶ Instance 2 (handles request)
   └──▶ Instance 3 (handles request)

(Instances are automatically added/removed based on load)

App Engine Services and Versions

Services

Large applications can be split into multiple services (microservices). Each service handles a specific function and can be deployed independently.

App Engine Application: my-ecommerce
├── Service: default        → Handles product browsing
├── Service: checkout       → Handles cart and payments
└── Service: admin          → Admin dashboard

Versions

Every deployment creates a new version of the app. Traffic can be split between versions for A/B testing or gradual rollouts.

# Deploy a new version without sending traffic to it
gcloud app deploy --no-promote

# Send 10% of traffic to the new version
gcloud app services set-traffic default \
  --splits v1=0.90,v2=0.10

App Engine Cron Jobs

Scheduled tasks can be configured using a cron.yaml file. This is useful for tasks like sending daily emails, cleaning up old data, or generating reports.

# cron.yaml
cron:
- description: "Daily report generation"
  url: /tasks/generate-report
  schedule: every 24 hours

- description: "Hourly data cleanup"
  url: /tasks/cleanup
  schedule: every 1 hours
# Deploy the cron configuration
gcloud app deploy cron.yaml

Key Takeaways

  • App Engine is a PaaS — deploy code without managing servers.
  • Standard Environment scales to zero; Flexible Environment always has at least one instance running.
  • app.yaml defines runtime, scaling, and environment variables.
  • Deploying an app takes one command: gcloud app deploy
  • Multiple services allow splitting an application into microservices.
  • Version management supports traffic splitting for safe rollouts.
  • Cron jobs schedule background tasks using cron.yaml.

Leave a Comment