GCP Multi-Service Architecture Lab
A microservices deployment on Google Cloud Platform demonstrating Cloud Run, Pub/Sub, API Gateway, VPC networking, and IAM.
Overview
This project features three Node.js services deployed on Cloud Run, which communicate asynchronously using Pub/Sub for job processing. An API Gateway serves as the unified entry point for these services, and Cloud Logging is utilized for centralized observability.
Services
auth-service
Token generation and verification
POST /authenticate, GET /verify
api-service
Job submission, publishes to Pub/Sub
POST /submit-job, GET /job/:jobId
worker-service
Consumes jobs from Pub/Sub, processes async
(subscriber, GET /health)
All services include a GET /health endpoint for Cloud Run health checks.
Architecture
Client traffic is managed through Cloud Load Balancing and Cloud Armor before being routed by the API Gateway to the respective Cloud Run services. The api-service publishes jobs to Pub/Sub, which are then consumed by the worker-service. Supporting infrastructure includes CI/CD pipelines, networking configurations, security measures, and observability tools.
Message Flow
- Client authenticates with the auth-service to obtain a token.
- Client submits a job to the api-service. This service publishes a message to the job-queue Pub/Sub topic and returns a 202 Accepted status with a job ID.
- The worker-service subscribes to the job-queue-sub, processes the job, logs the activity in Cloud Logging, and acknowledges the message.
Infrastructure
- Cloud Run: Provides serverless container hosting for each microservice.
- Pub/Sub: Facilitates asynchronous messaging via the job-queue topic and job-queue-sub subscription.
- API Gateway: Acts as the single, unified external entry point for routing requests.
- VPC and NAT: Ensure network isolation for enhanced security.
- IAM: Manages service accounts with least-privilege access for each service.
- Cloud Logging: Enables centralized log aggregation and analysis.
Repository Layout
- auth-service/: Contains the authentication service (Node.js, Express).
- api-service/: Houses the REST API and Pub/Sub publisher.
- worker-service/: Implements the Pub/Sub subscriber and job processor.
- docs/: Includes the OpenAPI specification (openapi.yaml).
- assets/: Contains screenshots and other assets.
Each service directory includes an index.js, package.json, and Dockerfile.
Concepts Demonstrated
- IAM service accounts and least-privilege access
- VPC and NAT for network isolation
- Serverless compute with Cloud Run
- Asynchronous messaging with Pub/Sub
- API Gateway as a single entry point
- Centralized observability with Cloud Logging
Cost
This lab is designed to run within the GCP free tier under typical usage conditions:
- Cloud Run: Up to 2 million invocations per month (free tier).
- Pub/Sub: Up to 10 GB per month (free tier).
- Estimated total cost: Under $1 for typical lab usage.