TL;DR
Learn how to deploy and scale applications on Google App Engine. This guide covers standard and flexible environments, configuration options, and best practices for optimal performance.
Building and Deploying Applications on Google App Engine
Google App Engine (GAE) is a fully managed Platform-as-a-Service (PaaS) that makes deploying and scaling applications easy. This guide covers everything you need to know about using App Engine effectively.
$1
`` graph TB
subgraph AppEngine["App Engine Service"]
direction TB
subgraph Environments["Environments"]
direction LR
SE["Standard Environment"]
FE["Flexible Environment"]
end
subgraph Features["Platform Features"]
direction LR
AS["Auto Scaling"]
LB["Load Balancing"]
VS["Version Management"]
end
subgraph Services["Platform Services"]
direction LR
DS["Datastore"]
MM["Memcache"]
TQ["Task Queue"]
end
end
subgraph External["External Services"]
direction TB
SQL["Cloud SQL"]
CDN["Cloud CDN"]
SM["Secret Manager"]
end
AppEngine --> External
classDef primary fill:#4285f4,stroke:#666,stroke-width:2px,color:#fff
classDef secondary fill:#34a853,stroke:#666,stroke-width:2px,color:#fff
classDef tertiary fill:#fbbc05,stroke:#666,stroke-width:2px,color:#fff
class AppEngine,Environments primary
class Features,Services secondary
class External tertiary
mermaid
`
$1
| Feature | Standard Environment | Flexible Environment |
|---------|---------------------|---------------------|
| Startup | Seconds | Minutes |
| SSH Access | No | Yes |
| Network Access | Via App Engine services | Full network access |
| Pricing | Per instance hour | Per vCPU, memory, disk |
| Scale to Zero | Yes | No |
| Custom Runtime | No | Yes (Docker) |
$1
$1
Example Python application:
` from flask import Flask app = Flask(__name__) @app.route('/')
def hello():
return 'Hello from App Engine!' if __name__ == '__main__':
app.run(host='127.0.0.1', port=8080, debug=True)
python
`main.py
Configuration file:
` runtime: python39
instance_class: F1 automatic_scaling:
target_cpu_utilization: 0.65
min_instances: 1
max_instances: 10
handlers:
script: auto
yaml
`app.yaml
$1
` runtime: custom
env: flex manual_scaling:
instances: 2 resources:
cpu: 1
memory_gb: 2
disk_size_gb: 10 env_variables:
ENV: 'production'
yaml
`app.yaml
Dockerfile for custom runtime:
` FROM python:3.9-slim WORKDIR /app
COPY requirements.txt .
RUN pip install -r requirements.txt COPY . .
CMD gunicorn -b :$PORT main:app
dockerfile
`
$1
$1
` gcloud app deploy app.yaml gcloud app deploy app.yaml --version=v1 gcloud app deploy app.yaml --version=v2 --no-promote
bash
`Deploy application
Deploy specific version
Deploy with traffic splitting
$1
` gcloud app versions list gcloud app services set-traffic default \
--splits=v1=0.5,v2=0.5 gcloud app services set-traffic default \
--splits=v2=1 \
--migrate
bash
`List versions
Split traffic
Migrate traffic
$1
$1
` automatic_scaling:
target_cpu_utilization: 0.65
target_throughput_utilization: 0.6
min_instances: 1
max_instances: 10
max_concurrent_requests: 50 basic_scaling:
max_instances: 5
idle_timeout: 10m manual_scaling:
instances: 3
yaml
`Automatic scaling
Basic scaling
Manual scaling
$1
` env_variables:
DATABASE_URL: 'postgresql://user:pass@host:5432/db'
API_KEY: '${SECRET_KEY}'
CACHE_TTL: '3600'
yaml
`
$1
$1
` gcloud app domain-mappings create \
--domain=www.example.com gcloud app ssl-certificates update \
--display-name=main-cert \
--domain=www.example.com
bash
`Map custom domain
Update SSL certificate
$1
` queue:
rate: 5/s
bucket_size: 10
retry_parameters:
task_retry_limit: 3
min_backoff_seconds: 30
yaml
`queue.yaml
$1
$1
` gcloud app set-iam-policy policy.yaml gcloud projects add-iam-policy-binding PROJECT_ID \
--member="user:jane@example.com" \
--role="roles/appengine.deployer"
bash
`Set IAM policy
Grant access
$1
` gcloud app firewall-rules create allow-internal \
--action allow \
--source-range 10.0.0.0/8 \
--description "Allow internal traffic"
bash
`Create firewall rule
$1
$1
` gcloud app logs tail gcloud logging read "resource.type=gae_app" \
--project=PROJECT_ID \
--limit=10
bash
`View application logs
Read specific logs
$1
Key metrics to monitor:
$1
$1
` from google.appengine.api import memcache def get_data(key):
data = memcache.get(key)
if data is None:
data = fetch_from_database(key)
memcache.add(key, data, 3600) # Cache for 1 hour
return data
python
`Using Memcache
$1
` handlers:
static_dir: static
http_headers:
Cache-Control: public, max-age=3600 script: auto
yaml
`app.yaml
$1
$1
` gcloud app describe gcloud app instances list gcloud app routes list
bash
`Check application status
View instance details
Debug routing issues
$1
` health_check:
enable_health_check: true
check_interval_sec: 5
timeout_sec: 4
unhealthy_threshold: 2
healthy_threshold: 2
yaml
``app.yaml
$1
1. Instance Management
- Use automatic scaling
- Set appropriate instance classes
- Implement efficient caching
- Use CDN for static content
2. Resource Utilization
- Monitor and adjust instance count
- Optimize database queries
- Use asynchronous tasks
- Implement proper caching
$1
Google App Engine provides a robust platform for deploying and scaling applications. Key takeaways:
For more information, refer to the [official App Engine documentation](https://cloud.google.com/appengine/docs).
Why This Matters
Understanding the business and technical context helps you make informed decisions rather than blindly following patterns.
Trade-offs to Consider
Every architectural decision involves trade-offs. Consider your specific requirements, team expertise, and scale when evaluating options.
When NOT to Use This
Knowing when a solution doesn't apply is as valuable as knowing when it does. Consider alternatives for your specific situation.
Decision Framework
Use this framework to evaluate whether this approach is right for your use case based on your specific constraints and requirements.