Skip to content

aryan9867bar/vcc-event-processing-system

Repository files navigation

Event Processing System

Large-scale applications often process millions of events per second (e.g., IoT systems, log processing pipelines, or financial transaction monitors). Traditional monolithic architectures struggle to meet these demands due to scalability bottlenecks and cost inefficiencies.

Key Challenges Addressed

  • High Throughput Event Processing: Kafka acts as the central message broker, decoupling producers and consumers for asynchronous, high-speed communication.
  • Dynamic Auto-Scaling: Kubernetes manages containerized services and can auto-scale based on resource usage or queue depth.
  • Cost-Efficient Serverless Execution: Modular microservices allow fine-grained resource allocation, reducing overhead and enabling possible migration to FaaS platforms (like OCI Functions).
  • Low-Latency Responses: Services communicate over lightweight REST endpoints, and Kafka ensures real-time event delivery with minimal delay.

This system is designed with scalability, modularity, and performance in mind—ideal for event-driven architectures operating at scale.

Key Cloud Design Considerations (GCP Equivalent)

  • Google Cloud Load Balancer / Ingress exposes the producer API securely.
  • GKE (Google Kubernetes Engine) runs all microservices (producer, consumer, alerting).
  • Apache Kafka runs on GKE (or optionally Google Pub/Sub as a managed alternative).
  • Alerting is handled by a dedicated microservice (or can be migrated to Cloud Functions).
  • Cloud SQL (PostgreSQL) stores persistent event data.
  • Google Cloud Logging & Monitoring provide observability across services.

Deployment Strategy (Local + GCP)

Background

The system is designed as a cloud-native, event-driven architecture and can be deployed both locally and on Google Cloud Platform (GCP).

Due to resource and cost constraints, the primary implementation and testing were performed locally using Docker and Kubernetes. However, the architecture is fully compatible with GCP services and can be deployed with minimal changes.


GCP Service Mapping

Local Component GCP Equivalent
Kafka (Docker) Kafka on GKE / Google Pub/Sub
PostgreSQL (Docker) Cloud SQL (PostgreSQL)
Kubernetes (local) GKE (Google Kubernetes Engine)
Docker Images Artifact Registry
Port Forwarding LoadBalancer / Ingress

Local Deployment Strategy

The current system simulates the cloud architecture using local tools:

Component Technology Used
Producer Service Java Spring Boot + KafkaTemplate
Kafka Broker Dockerized Apache Kafka
Consumer Service Java Spring Boot + KafkaListener
Alerting Service Java Spring Boot (simulates real-time alerting)
Database PostgreSQL (Docker)
Monitoring & Logs STDOUT logs
Kubernetes Local cluster / Minikube

Architecture Adjustments (Local vs Cloud)

  • Kafka runs locally instead of managed Pub/Sub
  • Alerting runs as a microservice instead of serverless function
  • Kubernetes runs locally instead of GKE
  • APIs are tested using curl/Postman instead of external load balancers

GCP Deployment Overview

The same architecture can be deployed on GCP using:

  • GKE for container orchestration
  • Artifact Registry for Docker images
  • Cloud SQL (PostgreSQL) for persistent storage
  • LoadBalancer / Ingress for external access
  • Optional: Pub/Sub as a managed Kafka alternative

Refer to k8s/gcp/ for deployment scripts.



Planned GCP Deployment

GCP Deployment

Project Structure

VCC-EVENT-PROCESSING-SYSTEM/
├── alerting-service/
├── consumer-service/
├── producer-service/
├── diagram/
├── k8s/
│   ├── hpa/
│   │   ├── producer-hpa.yaml
│   │   ├── consumer-hpa.yaml
│   │   └── alerting-hpa.yaml
│   ├── gcp/                          # NEW FOLDER
│   │   ├── deploy-gcp.sh             # GCP deploy script
│   │   ├── producer-deployment.yaml  # updated with Artifact Registry image
│   │   ├── consumer-deployment.yaml  # updated with Cloud SQL proxy
│   │   ├── alerting-deployment.yaml  # updated with Artifact Registry image
│   │   └── producer-service.yaml     # LoadBalancer instead of ClusterIP
│   ├── alerting-deployment.yaml      # original local
│   ├── consumer-deployment.yaml      # original local
│   ├── kafka-deployment.yaml         # original local
│   ├── postgres-deployment.yaml      # original local
│   ├── producer-deployment.yaml      # original local
│   ├── producer-ingress.yaml
│   ├── zookeeper-deployment.yaml
│   └── deploy-all.sh                 # original local script
├── performance.sh
├── run-all.sh
└── README.md

Architechture Diagram

Architechture Diagram

Sequence Diagram

Sequence Diagram

Getting Started

Prerequisites

Make sure the following tools are installed:

  • Docker
  • Kubernetes
  • Maven
  • Java 17+
  • Curl

Step-by-Step Deployment Guide

1. Clone the Repository

git clone <repository-url>
cd event-processing

2. Build Docker Images

Run the following inside each microservice directory:

cd producer-service
mvn clean install
docker build -t producer-service:latest .

cd ../consumer-service
mvn clean install -Dspring.profiles.active=test
docker build -t consumer-service:latest .

cd ../alerting-service
mvn clean install
docker build -t alerting-service:latest .

3. Docker Deployment Steps

  1. Clone the repository containing the deployment scripts.

  2. Navigate to the root directory containing run-all.sh.

  3. Make the script executable:

    chmod +x run-all.sh
  4. Run the deployment script:

    ./run-all.sh

The script performs the following actions:

  • Cleans up any existing containers
  • Creates a shared Docker network
  • Deploys Zookeeper and waits for it to become available
  • Deploys Kafka and waits for it to become available
  • Deploys PostgreSQL
  • Builds Docker images for the Producer, Consumer, and Alerting services
  • Deploys all three services
  • Provides a command to test the system

4. Docker Troubleshooting

General Issues

  1. Container Startup Failure

    • Check logs for the failing container:

      docker logs <container-name>
    • Ensure there is sufficient system memory and disk space.

  2. Network Connectivity Issues

    • Verify the network was created:

      docker network ls | grep event-net
    • Inspect network details:

      docker network inspect event-net

Component-Specific Issues

  1. Zookeeper Issues

    • Check Zookeeper logs:

      docker logs zookeeper
    • Verify port accessibility:

      nc -zv localhost 2181
  2. Kafka Issues

    • Check Kafka logs:

      docker logs kafka
    • Verify Kafka can reach Zookeeper:

      docker exec kafka ping zookeeper
    • Check broker status:

      docker exec -it kafka kafka-topics.sh --bootstrap-server localhost:9092 --list
  3. PostgreSQL Issues

    • Check PostgreSQL logs:

      docker logs postgres
    • Test database connection:

      docker exec -it postgres psql -U postgres -d eventdb -c "SELECT 1"
  4. Service Container Issues

    • Check service logs:

      docker logs producer-service
      docker logs consumer-service
      docker logs alerting-service
    • Verify connections to Kafka:

      docker exec producer-service curl -v telnet://kafka:9092
  5. Image Build Failures

    • Manually attempt to build the images:

      cd producer-service && docker build -t producer-service:latest .
    • Check for Docker build errors in the console output.

Docker Deployment

Docker Deployment


5. Deploy Using Kubernetes

From the root directory:

cd k8s
chmod +x deploy-all.sh
./deploy-all.sh

The script performs the following actions:

  • Creates a namespace called event-system if it doesn't exist
  • Cleans up any existing deployments
  • Deploys Zookeeper and waits for it to be ready
  • Deploys Kafka and PostgreSQL
  • Deploys the Producer, Consumer, and Alerting services
  • Applies Horizontal Pod Autoscaler (HPA) configurations for automatic scaling
  • Sets up port forwarding for local testing

7. Verifying Deployment

kubectl get pods
kubectl logs <pod-name>

You should see logs from the services interacting with Kafka.

Kubernetes Troubleshooting

General Issues

  1. Namespace Issues

    • Verify the namespace exists:

      kubectl get namespace event-system
    • Check namespace status:

      kubectl describe namespace event-system
  2. Resource Status

    • Check the status of all pods:

      kubectl get pods -n event-system
    • View detailed information about a specific pod:

      kubectl describe pod <pod-name> -n event-system
  3. Pod Crash or Startup Failures

    • Check pod logs:

      kubectl logs <pod-name> -n event-system
    • Check events for a pod:

      kubectl describe pod <pod-name> -n event-system | grep -A 10 Events

Component-Specific Issues

  1. Zookeeper Issues

    • Check Zookeeper pod status:

      kubectl get pods -l app=zookeeper -n event-system
    • Check Zookeeper logs:

      kubectl logs -l app=zookeeper -n event-system
  2. Kafka Issues

    • Check Kafka pod status:

      kubectl get pods -l app=kafka -n event-system
    • Check Kafka logs:

      kubectl logs -l app=kafka -n event-system
    • Verify Kafka can reach Zookeeper:

      kubectl exec -it $(kubectl get pod -l app=kafka -n event-system -o jsonpath='{.items[0].metadata.name}') -n event-system -- ping zookeeper-service
  3. PostgreSQL Issues

    • Check PostgreSQL pod status:

      kubectl get pods -l app=postgres -n event-system
    • Check database service:

      kubectl get svc postgres-service -n event-system
    • Test database connection:

      kubectl exec -it $(kubectl get pod -l app=postgres -n event-system -o jsonpath='{.items[0].metadata.name}') -n event-system -- psql -U postgres -d eventdb -c "SELECT 1"
  4. Service Pod Issues

    • Check service pods status:

      kubectl get pods -l app=producer-service -n event-system
      kubectl get pods -l app=consumer-service -n event-system
      kubectl get pods -l app=alerting-service -n event-system
    • Check service logs:

      kubectl logs -l app=producer-service -n event-system
      kubectl logs -l app=consumer-service -n event-system
      kubectl logs -l app=alerting-service -n event-system
  5. Service Connectivity

    • Check service endpoints:

      kubectl get endpoints -n event-system
  6. HPA Issues

    • Check HPA status:

      kubectl get hpa -n event-system
    • Check detailed HPA information:

      kubectl describe hpa producer-hpa -n event-system
    • Verify metrics are being collected:

      kubectl top pods -n event-system
  7. Port Forwarding Issues

    • Verify service exists:

      kubectl get svc producer-service -n event-system
    • Try alternative port forwarding:

      kubectl port-forward deployment/producer-deployment 8080:8080 -n event-system

Kubernetes Deployment

Kubernetes Deployment

Services Overview

  • ProducerService: Publishes user-defined events to a Kafka topic.
  • ConsumerService: Listens to the Kafka topic and processes the events.
  • AlertingService: Triggers alerts based on event type/threshold.

GCP CLI Setup (Essential Commands)

Below are the key GCP CLI commands required to deploy this system on Google Cloud.

1. Authenticate and Set Project

gcloud auth login
gcloud projects create event-processing-system
gcloud config set project event-processing-system

What it does:

  • Logs into GCP
  • Creates a new project
  • Sets it as the active project

2. Enable Required Services

gcloud services enable container.googleapis.com \
  artifactregistry.googleapis.com \
  sqladmin.googleapis.com \
  cloudbuild.googleapis.com

What it does:

  • Enables GKE (Kubernetes)
  • Enables Artifact Registry (Docker images)
  • Enables Cloud SQL (database)
  • Enables Cloud Build (optional builds)

3. Create Artifact Registry

gcloud artifacts repositories create event-processing-system \
  --repository-format=docker \
  --location=us-central1

What it does:

  • Creates a private Docker image repository on GCP

4. Build and Push Docker Images

docker build -t <REGION>-docker.pkg.dev/<PROJECT_ID>/event-processing-system/producer-service .
docker push <REGION>-docker.pkg.dev/<PROJECT_ID>/event-processing-system/producer-service

What it does:

  • Builds Docker image
  • Uploads it to GCP Artifact Registry

5. Create GKE Cluster

gcloud container clusters create event-processing-system-cluster \
  --zone=us-central1-a \
  --num-nodes=2

What it does:

  • Creates a Kubernetes cluster on GCP

6. Connect kubectl to Cluster

gcloud container clusters get-credentials event-processing-system-cluster \
  --zone=us-central1-a
kubectl get nodes

What it does:

  • Connects your local machine to GKE
  • Verifies cluster is running

7. Create Cloud SQL (PostgreSQL)

gcloud sql instances create event-db \
  --database-version=POSTGRES_14 \
  --tier=db-f1-micro \
  --region=us-central1

What it does:

  • Creates managed PostgreSQL database on GCP

8. Deploy Services

cd k8s/gcp
./deploy-gcp.sh

What it does:

  • Deploys all services to GKE using Kubernetes manifests

9. Verify Deployment

kubectl get pods -n event-system
kubectl get svc -n event-system

What it does:

  • Checks if services are running correctly

Testing

Use Postman or CURL to send test events to the /publish endpoint of the producer service (usually exposed via a NodePort or Ingress).

Example:

curl -X POST http://<node-id>:<nodeport>/publish -H "Content-Type: application/json" -d  -d '{"type":"TEMP","value":"ALERT:90"}'

Expected:

  • consumer-service logs the event to DB

    kubectl exec -it $(kubectl get pod -l app=postgres -n event-system -o jsonpath='{.items[0].metadata.name}') -n event-system -- psql -U postgres -d eventdb -c "SELECT * FROM EVENTS"
  • alerting-service prints alert to console

    kubectl logs -l app=alerting-service  -n event-system

Notes

  • This system simulates a cloud-native event-driven architecture using local infrastructure.
  • The architecture is fully compatible with GCP services such as GKE, Cloud SQL, and Artifact Registry.
  • Kafka setup uses Dockerized Confluent/Bitnami images.
  • Recommended for development and testing environments.

About

Scalable event-driven microservices architecture using Apache Kafka, Spring Boot, Docker, and Kubernetes, with optional GCP deployment. Processes real-time events via producer, consumer, and alerting services, enabling asynchronous communication, fault tolerance, and cloud-native scalability.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors