Use this file to discover all available pages before exploring further.
Serverless computing is a cloud model where you don’t manage any servers at all. You upload your code, and the platform handles everything: provisioning machines, scaling up during traffic spikes, scaling down to zero when idle, and even patching security updates. You only pay for the actual compute time your code uses.The term “serverless” is a bit misleading—there are still servers, you just don’t see or manage them. It’s like electricity: you don’t maintain a power plant, you just use what you need and pay for consumption.This guide covers deploying Mizu applications to AWS Lambda, Google Cloud Functions, and other serverless environments.
Serverless platforms work differently from traditional servers. Understanding these characteristics helps you design better serverless applications:
Aspect
Impact on Mizu Apps
Cold starts
When your function hasn’t run recently, the platform needs to start a new instance. This “cold start” adds latency (100-500ms). Warm instances respond immediately
Stateless
Each request might run on a different instance, so you can’t store data in memory between requests. Use databases or caches instead
Timeout limits
Functions have maximum execution times (15-30 minutes). Long-running tasks need different architectures
Concurrency
Each instance typically handles one request at a time. High traffic means many parallel instances
Why Go is great for serverless: Go’s compiled binary starts in ~50ms (compared to 500ms+ for Java or 200ms+ for Node.js), making cold starts much less painful. Go also uses little memory, which reduces costs since you pay for memory usage.
AWS Lambda is the original and most popular serverless platform. You upload a function, and AWS runs it in response to events—HTTP requests, database changes, file uploads, or scheduled triggers.For web applications, you need a way to receive HTTP requests. AWS offers two options: Function URLs (simpler, direct HTTP access) or API Gateway (more features like rate limiting, API keys, and request transformation).
Function URLs are the simplest way to invoke Lambda via HTTP. AWS gives you a URL like https://xyz123.lambda-url.us-east-1.on.aws/ that directly invokes your function. No API Gateway setup required.main.go:
Google Cloud Functions is Google’s serverless platform. It’s tightly integrated with other Google Cloud services and has a simpler deployment model than Lambda—you can deploy directly from source code without building a container.
The simplest approach is an HTTP-triggered function. Your function receives standard http.ResponseWriter and *http.Request parameters, so Mizu works seamlessly:function.go:
Serverless performance is all about reducing cold starts and minimizing execution time (since you pay per millisecond). These optimizations can significantly reduce costs and improve user experience.
Cold starts happen when there’s no warm instance available to handle your request. The key insight is that initialization code runs once per instance, not once per request. Put expensive setup (like database connection pools) in init() so it only runs during cold starts:
var ( app *mizu.App db *sql.DB)func init() { // Initialize during cold start, not per request app = mizu.New() setupRoutes(app) // Lazy database connection // Don't connect in init() - connect on first request}func setupRoutes(app *mizu.App) { app.Get("/", handleHome) app.Get("/users/{id}", handleGetUser)}func getDB() *sql.DB { if db == nil { var err error db, err = sql.Open("postgres", os.Getenv("DATABASE_URL")) if err != nil { log.Fatal(err) } } return db}