This project demonstrates a Google Pub/Sub integration using a small microservices architecture (note : may not include best-practices, built in order to learn googel-pub/sub service). It includes multiple services written in different languagesโNode.js (Express), FastAPI, and Spring Bootโall containerized and stored in Google Artifact Registry (GAR). Continuous integration and deployment (CI/CD) are handled via GitHub Actions.
The project contains the following services:
- Client Application (React)
- Order Service (Node.js - Express)
- Notification Service (Spring Boot)
- Billing Service (FastAPI)
- The Client App triggers a message to be published by invoking an endpoint in the Order Service.
- The Order Service (Node.js - Express) publishes the message to a Google Pub/Sub topic.
- Two services are subscribed to this topic:
- Notification Service (Spring Boot)
- Billing Service (FastAPI)
The two subscribers handle the messages by performing different actions based on the published data.
Service | Technology | Description | Deployed URL |
---|---|---|---|
Client App | React | Frontend application that triggers messages to be published. | Client App |
Order Service | Node.js (Express) | Handles requests from the client and publishes messages to Google Pub/Sub. | Order Service |
Notification Service | Spring Boot | Subscribes to the Google Pub/Sub topic and processes notification events. | Notification Service |
Billing Service | FastAPI | Subscribes to the Google Pub/Sub topic and handles billing-related events. | Billing Service |
- Google Cloud Pub/Sub: Message broker used to decouple services.
- Google Artifact Registry (GAR): Container registry to store and manage Docker images.
- Cloud Run: To deploy services in a serverless environment.
- GitHub Actions: For CI/CD automation to deploy services.
- Docker: To containerize the services.
- React: Client-side user interface.
- Node.js (Express): Backend for the order service.
- Spring Boot: For the notification service.
- FastAPI: For the billing service.
-
Client App: User interacts with the client app to trigger an event.
- Endpoint:
/publish
(Express app)
- Endpoint:
-
Order Service: Receives the event and publishes the message to a Google Pub/Sub topic.
-
Google Pub/Sub: Distributes the message to two subscribers:
- Notification Service (Spring Boot)
- Billing Service (FastAPI)
-
Notification Service: Processes notification messages and logs to Google Cloud Logger.
-
Billing Service: Handles billing-related messages and logs to Google Cloud Logger.
The project is fully containerized using Docker, and CI/CD pipelines are set up using GitHub Actions to automate deployment to Google Cloud Run. Here's a brief outline of the steps:
- Commit Changes: Push your local commits to GitHub.
- GitHub Actions: Detects changes and triggers the pipeline.
- Containerization: Each service is containerized using Docker.
- Artifact Registry: Docker images are pushed to Google Artifact Registry.
- Cloud Run: Services are deployed to Google Cloud Run.
- IAM & Permissions: Managed via Google Cloud IAM for secure access and deployments.
To run the services locally, make sure you have the following tools installed:
- Docker
- Node.js (for the Order Service)
- Python (for the Billing Service)
- Java (for the Notification Service)
- React (for the Client App)
Steps:
- Clone the repository.
- Build the Docker images for each service (includes build--args):
docker build -t client-app ./client docker build -t order-service ./order docker build -t notification-service ./notification docker build -t billing-service ./billing
- Run the services
All services are integrated with Google Cloud Logger for logging and monitoring. You can view logs by navigating to the Google Cloud Console under the Cloud Logger section.
Topic | Subscribers |
---|---|
order-topic |
Notification Service (Spring Boot), Billing Service (FastAPI) |
Make sure the topic and subscriptions are correctly set up in Google Cloud Pub/Sub.
Service | URL |
---|---|
Client App | https://pubsub-client-850033850526.us-central1.run.app |
Order Service | https://pubsub-order-service-850033850526.us-central1.run.app |
Notification Service | https://pubsub-noti-service-850033850526.us-central1.run.app |
Billing Service | https://pubsub-billing-service-850033850526.us-central1.run.app |
This project successfully demonstrates the power of Google Pub/Sub in a microservices architecture. Each service is built using a different technology stack and deployed serverlessly using Google Cloud Run. CI/CD pipelines with GitHub Actions ensure that the system remains robust and easily maintainable.