Serverless Transformation
GO-DUCK isn't just for heavy-duty containers. With the Serverless Transformation Layer, your entire Federated Microservice can be deployed as an elastic, zero-cost-when-idle function on AWS, GCP, or Vercel.
Stateless Silo Routing
Every serverless invocation is fully isolated and stateless. The system resolves the tenant's database silo dynamically from the JWT, ensuring 100% data privacy even in shared-compute environments.
Shared Router Pattern
We use a unified internal router package. This means your security middlewares, search logic, and endpoint definitions are shared between main.go and all serverless entrypoints.
1 AWS Lambda
GO-DUCK generates a specialized lambda_main.go utilizing the aws-lambda-go-api-proxy. This adapter wraps the Gin router and translates API Gateway events into standard HTTP requests.
Build for AWS Lambda
# Set target OS and Architecture
export GOOS=linux
export GOARCH=amd64
# Build with lambda tag to include the handler
go build -tags lambda -o bootstrap lambda_main.go
# Zip and deploy to AWS
zip function.zip bootstrap
Cold Start Warning: Lambda initializations include DB connection pooling. The shared router uses sync.Once to keep these connections warm across subsequent invocations.
2 Vercel (Serverless Functions)
The system generates an api/index.go file compatible with Vercel's Go runtime. By using the generated vercel.json, all incoming traffic is routed to this single entrypoint.
Immediate Deployment
# Login to vercel
vercel login
# Deploy the project
vercel deploy --prod
The vercel.json configuration handles the necessary rewrites to ensure paths like /api/users are correctly served by the Go handler:
{
"version": 2,
"rewrites": [
{ "source": "/(.*)", "destination": "/api/index" }
]
}
3 Google Cloud Functions (GCF)
For GCP, we use the Functions Framework for Go. The generated gcf_handler.go exports a standard HTTP trigger named GoDuckEntry.
Deploying to Cloud Functions
# Deploy using gcloud CLI
gcloud functions deploy GoDuckEntry \
--runtime go124 \
--trigger-http \
--allow-unauthenticated \
--region us-central1
Ensure the //go:build gcf tag is handled correctly by your deployment pipeline if you are building remotely.
Configuration Comparison
| Feature | Standard (Binary) | Serverless |
|---|---|---|
| Execution Mode | Persistent Process | On-Demand Invocations |
| gRPC Server (Kratos) | Enabled | Disabled (Async only) |
| Outbox Worker | Automatic Background | Recommended via Cloud Cron |
| Cold Start Optimization | N/A | sync.Once initialization |