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

Rudra NarayanRudra Narayan
3 min read

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):

  1. User Service – Handles user data (uses PostgreSQL)

  2. Activity Service – Stores activity logs (uses MongoDB Atlas)

  3. 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 a MongoSocketReadException.

  • 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


0
Subscribe to my newsletter

Read articles from Rudra Narayan directly inside your inbox. Subscribe to the newsletter, and don't miss out.

Written by

Rudra Narayan
Rudra Narayan