Building an AI-Powered Spring Boot Microservices Application: My Journey, Issues & Fixes

In this post, Iβll walk you through my experience building an AI-powered fitness recommendation app using Spring Boot microservices, integrated with MongoDB Atlas, Eureka Service Discovery, and Google Gemini for personalized AI recommendations.
π― In this post, Iβll highlight:
π§± The architecture I used
π¨ Key steps in building it
β Challenges I faced
β How I fixed them
ποΈ Project Architecture
My application is made up of three microservices (so far):
User Service β Handles user data (uses PostgreSQL)
Activity Service β Stores activity logs (uses MongoDB Atlas)
AI Recommendation Service β Generates personalized fitness plans using Google Gemini
All services are registered with the Eureka Server for service discovery.
π§ Tech Stack
Java 17
Spring Boot 3.1.9
Spring Cloud 2025.0.0
MongoDB Atlas
PostgreSQL
Google Gemini (AI API)
Eureka Server
Docker (for future deployment)
π οΈ Steps I Followed
β Created microservices using Spring Initializr
β Integrated JPA & PostgreSQL for
user-service
β Set up MongoDB Atlas for
activity-service
β Integrated Google Gemini API in
ai-service
β Added Eureka Server and registered all services
β Tested all APIs using Postman
β Used Spring Cloud OpenFeign for inter-service communication
π§± Problems I Faced & How I Solved Them:
1. β MongoSocketReadException β MongoDB Atlas Connection Issue
Issue: While connecting
activity-service
to MongoDB Atlas, I got aMongoSocketReadException
.Root Cause: I had not whitelisted my current IP address in the MongoDB Atlas dashboard.
Fix:
Go to MongoDB Atlas Console β Network Access
Click Add IP Address
Use "Allow access from anywhere" (0.0.0.0/0) or your specific IP
Save and reconnect
2. β Eureka Client Not Registering Microservices
Issue: Microservices were not appearing in the Eureka Dashboard.
Root Cause: I forgot to add the Eureka Client dependency in the
pom.xml
.Fix:
Add the following to each microservice:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId> </dependency>
Also add these properties:
eureka.client.register-with-eureka=true eureka.client.fetch-registry=true eureka.client.service-url.defaultZone=http://localhost:8761/eureka/
Make sure every service has a unique
spring.application.name
π‘ Learnings
β Always whitelist your IP in MongoDB Atlas
β Never miss essential dependencies like Eureka Client
β Use Spring Profiles for environment-specific configs
β Test each microservice individually before full integration
π Conclusion
This project helped me:
π§© Build scalable microservices using Spring Boot
π Securely connect to external databases
π§ Integrate AI-powered services using Google Gemini
π οΈ Troubleshoot real-world issues with networking and microservice registration
π Whatβs Next?
βοΈ Setting up asynchronous communication using RabbitMQ for better service decoupling
π‘οΈ Implementing authentication & authorization using Keycloak
π» Adding a frontend using React or Next.js
Subscribe to my newsletter
Read articles from Rudra Narayan directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
