You are viewing a free preview of this lesson.
Subscribe to unlock all 10 lessons in this course and every other course on LearningBro.
Building reliable, performant, and cost-effective serverless applications on Google Cloud requires attention to function design, cold start mitigation, security, monitoring, and cost optimisation. This lesson consolidates best practices across Cloud Functions, Cloud Run, App Engine, and the supporting serverless services.
Each function should do one thing well. A function that fetches data, transforms it, validates it, and writes to a database is doing too much. Break it into smaller functions connected by Pub/Sub or Workflows.
Serverless triggers provide at-least-once delivery. Your function may be invoked multiple times for the same event. Design functions to produce the same result when called repeatedly with the same input.
# BAD: Not idempotent — duplicates data on retry
def process_order(event, context):
order = parse_event(event)
db.insert(order) # Duplicate row on retry
# GOOD: Idempotent — uses upsert with event ID
def process_order(event, context):
order = parse_event(event)
db.upsert(order, key=event['id']) # Same result on retry
Cold starts occur when a new instance is created to handle a request. Strategies to reduce cold start latency:
Subscribe to continue reading
Get full access to this lesson and all 10 lessons in this course.