A polyglot microservice architecture designed for a smart order fulfillment system.
The system is built using a modern microservice architecture, separating concerns across multiple specialized services. It uses a polyglot approach, leveraging the strengths of different programming languages for specific tasks.
- Frontend: React (Vite)
- Backend Services (Java/Spring Boot):
api-gateway: Routes incoming traffic to the appropriate microservice. Also handles initial CORS configurations.auth-service: Manages user authentication and JWT token generation.inventory-service: Manages product inventory and stock levels.order-service: Handles order creation and lifecycle management.
- Backend Services (Go):
delivery-service: Manages the delivery logistics of orders.notification-service: Sends notifications (e.g., email) to users.warehouse-service: Manages warehouse operations.
- Databases: PostgreSQL (hosted on Neon.tech in development)
- Infrastructure & Deployment:
- Kubernetes (Minikube for local development)
- Ansible (Configuration management and secret injection)
- Jenkins (CI/CD pipeline)
- Docker (Containerization)
- Kustomize (Kubernetes manifest management)
We have recently migrated from Docker Compose to a full Kubernetes-native deployment using Minikube and Ansible.
- Minikube installed and running.
- Docker installed.
- Ansible installed (with
kubernetes.corecollection:ansible-galaxy collection install kubernetes.core). - kubectl installed.
-
Start Minikube: Ensure your Minikube cluster is running.
minikube start
-
Configure Secrets: The project uses Ansible Vault for secret management. For local development, copy the
.envtemplate and set your actual database credentials.cp k8s/.env ansible/group_vars/dev/vault.yml
Note: Ensure the keys in
vault.ymlare prefixed withvault_(e.g.,vault_jwt_secret). -
Deploy via Ansible: Run the Ansible playbook to set up namespaces, inject secrets, apply Kustomize manifests, and deploy the services.
ANSIBLE_CONFIG=ansible/ansible.cfg ansible-playbook -i ansible/inventories/dev/hosts.yml ansible/playbooks/deploy-k8s.yml -e target_env=dev -e image_tag=latest -e '{"project_src_dir": "/home/vishnu-dholu/Code/Smart Order"}' -e 'ansible_become=false'
-
Wait for Pods: Check the status of your pods and wait for them to enter the
Runningstate.kubectl get pods -n smart-order
-
Access the Application: Since
minikube tunnelcan sometimes face issues binding to port 80 withoutsudo, the recommended way to access the frontend and API Gateway locally is by port-forwarding the Nginx Ingress Controller to a free port (e.g.,8888).In a separate terminal, run:
kubectl port-forward service/ingress-nginx-controller 8888:80 -n ingress-nginx
Now open your browser and navigate to: http://localhost:8888
(The Ingress controller will route
/api/*to the API Gateway and everything else to the React frontend).
The project includes a Jenkinsfile that orchestrates the build and deployment process.
- It builds Docker images for all services.
- It loads the images directly into Minikube (
minikube image load). - It executes the Ansible playbook to roll out the new images to the Kubernetes cluster.
When you modify code in a microservice and want to test it locally in Minikube without running the full Jenkins pipeline, follow these steps:
-
Build the new Docker image:
# Example for auth-service docker build --network=host -t localhost:5001/smart-order/auth-service:dev-update -f services/spring/auth-service/Dockerfile services/spring/auth-service -
Load the image into Minikube:
minikube image load localhost:5001/smart-order/auth-service:dev-update
-
Update the Kubernetes Deployment:
kubectl set image deployment/auth-service auth-service=localhost:5001/smart-order/auth-service:dev-update -n smart-orderKubernetes will automatically roll out the new pods using the updated image.
- Cause: Kubernetes is trying to pull an image from a remote registry (like
localhost:5001which points to the Minikube node itself, not your host) and failing. - Fix: Ensure your deployments are using
imagePullPolicy: IfNotPresent(notAlways). Make sure you have loaded the image into Minikube usingminikube image load <image-name>.
- Cause: You are accessing the app via
http://localhost:8888, but this URL is either missing from your Google Cloud Console's "Authorized JavaScript origins", or the change hasn't propagated yet. - Fix: Add
http://localhost:8888to the Google Console. Note that it can take 5 minutes to a few hours for Google to propagate this change. Clearing your browser cache or using Incognito mode can help.
- Cause: This usually happens if the frontend fails to acquire a valid Google token (due to the error above) and sends an empty or invalid token to the API Gateway.
- Fix: Resolve the Google Sign-in origin issue first. Ensure the
api-gatewayand downstream microservices have the correct CORS configuration matching your frontend URL.
- Cause:
kubectl port-forwardprocesses can sometimes drop if left idle. - Fix: Simply restart the port-forward command:
kubectl port-forward service/ingress-nginx-controller 8888:80 -n ingress-nginx