A sample end‑to‑end service showing how to build, deploy, and operate a Go‑based money‑transfer microservice on Google Cloud:
- gRPC API for processing transfers
- Cloud Pub/Sub for asynchronous audit‑event publishing
- Cloud SQL (PostgreSQL) for ledger persistence
- GKE (Kubernetes) to run the service behind a LoadBalancer
- Terraform for infrastructure as code
- GitHub Actions + Docker for CI/CD
- gRPC Definition & Codegen
transfer.proto
withgo_package
option → Go stubs generated undergo-server-demo/transfer/
- Go Transfer Service (
cmd/server
)ProcessTransfer
handler does currency conversion stub, ACID DB transaction, and publishes audit events to Pub/Sub
- Pub/Sub Infrastructure (
terraform/pubsub.tf
)- Topic
audit-events
, DLQ topicaudit-events-dlq
, subscriptionaudit-events-sub
with dead‑letter policy and 7 day retention
- Topic
- GKE Deployment & Service (
terraform/deployment.tf
)- Kubernetes Deployment (2 replicas) listening on port 50051 + LoadBalancer Service exposing port 50051
- Cloud SQL (
terraform/cloud_sql.tf
)- PostgreSQL 17 instance, database
ledger
, usertransfer_user
on a supporteddb-custom-1-3840
tier
- PostgreSQL 17 instance, database
- CI/CD Pipeline (
.github/workflows/ci-cd.yml
)- Regenerates protobuf code, builds & pushes Docker image to GCR, runs Terraform to provision infra and deploy
We set out to build a high‑throughput money‑transfer platform leveraging Go’s concurrency, crypto rails, and event‑driven audit logs. On deck:
-
Massive Parallel Transfers
- Use Go goroutines and channels to fan out thousands of concurrent transfers per second.
- Implement worker pools that back‑pressure on Pub/Sub backlog and coordinate idempotent retries.
-
Crypto‑Backend Integration
- Extend
ProcessTransfer
to route funds over a blockchain rail:- Sign transactions via GCP KMS or HSM
- Broadcast on‑chain, await confirmations
- Convert between fiat ↔ crypto using real‑time oracles before ledger commit
- Extend
-
Advanced Audit & Analytics
- Build a dedicated subscriber (e.g. in Go or .NET) that consumes
audit-events-sub
and persists to TimescaleDB or BigQuery. - Add dashboards and alerts on transfer volumes, failures, and anomalous patterns.
- Build a dedicated subscriber (e.g. in Go or .NET) that consumes
-
Resiliency & Auto‑Scaling
- Configure Horizontal Pod Autoscalers based on custom Pub/Sub metrics or gRPC latency.
- Chaos‑test failure paths (DB timeouts, Pub/Sub nacks) and verify self‑healing.
-
Multi‑Environment & GitOps
- Split Terraform into dev, staging, and prod workspaces or use Terragrunt
- Adopt a GitOps tool (Argo CD) so infrastructure changes self‑deploy on PR merge
- Go ≥ 1.24
protoc
compilergcloud
SDK- Terraform ≥ 1.5.0
- Docker
cd go-server-demo
go install google.golang.org/protobuf/cmd/protoc-gen-go@latest
go install google.golang.org/grpc/cmd/protoc-gen-go-grpc@latest
mkdir -p transfer
protoc \
--go_out=transfer --go_opt=paths=source_relative \
--go-grpc_out=transfer --go-grpc_opt=paths=source_relative \
transfer.proto
# (Optional) start Cloud SQL Proxy if using Cloud SQL:
# cloud-sql-proxy YOUR_INSTANCE_CONN=tcp:5432
export GOOGLE_APPLICATION_CREDENTIALS="../gcp-demo-460104-*.json"
export LEDGER_DSN="postgres://transfer_user:<PASSWORD>@127.0.0.1:5432/ledger?sslmode=disable"
cd go-server-demo
go run cmd/server
cd go-server-demo
go run cmd/client --addr localhost:50051
4. Deploy via CI/CD
Push to main and let GitHub Actions:
Regenerate protobuf
Build & push Docker image
Provision infra with Terraform
Deploy to GKE
5. Inspect the live service
gcloud container clusters get-credentials gcp-demo-cluster \
--region us-central1 --project YOUR_PROJECT_ID
kubectl get svc go-server-demo -o wide
grpcurl -plaintext <EXTERNAL_IP>:50051 list
docker build -t gcr.io/gcp-demo-460104/go-server-demo:v2 .
docker push gcr.io/gcp-demo-460104/go-server-demo:v2
pull messages command
gcloud pubsub subscriptions tail audit-events-sub \
--project=gcp-demo-460104 \
--format="json(message.message.data)"