Technology

From Zero to Microservices: Architecting the EndoTwin Digital Health AI

A deep-dive technical breakdown of how I designed and built EndoTwin — a distributed AI platform for Endometriosis utilizing Federated Learning, Physics-Informed Neural Networks (PINN), and a Next.js + FastAPI microservices stack.

Akash Kumar Singh

Founder @ Dilwado.com · 400K+ YouTube Creator

14 min read
MicroservicesFederated LearningPythonNext.jsFastAPIAI Architecture

The EndoTwin Architecture: Reimagining Healthcare AI

Endometriosis affects 1 in 10 women globally, yet diagnosing and managing it remains extremely complex. When I set out to build EndoTwin, the goal was ambitious: create a privacy-first, distributed AI digital twin for patient health.

The initial architecture was a single monolithic Streamlit application. It worked for proof-of-concept, but it couldn't scale. It wasn't secure enough for sensitive medical data. It couldn't handle real-time Federated Learning models dynamically.

So, I tore it down and rebuilt it from scratch.

Here is the complete technical breakdown of how I architected EndoTwin's modern microservices infrastructure.

The Core Stack

I chose technologies specifically optimized for high-performance AI integration and scalable web delivery:

  • ▸Frontend: Next.js 14, React, Tailwind CSS, Framer Motion (for real-time 3D dashboard visualization)
  • ▸Backend API: FastAPI (Python) — because native asynchronous support makes inference routing lightning fast
  • ▸Database: PostgreSQL with Prisma ORM
  • ▸AI Engine: PyTorch, TensorFlow, SHAP (Explainability)
  • ▸Federated Learning: Flower (flwr) framework
  • ▸Infrastructure: Docker, Kubernetes, NGINX
  • The Problem with Monoliths in AI

    When building AI platforms, data processing and UI rendering compete for resources. In our monolithic version, a background inference job would freeze the user interface. By decoupling the architecture into microservices, the FastAPI backend now strictly handles the heavy computational load (PINN aggregations), while the Next.js frontend consumes the resulting JSON streams effortlessly.

    Federated Learning: Privacy by Design

    Medical data cannot be legally or ethically centralized in a single database. This is where Federated Learning comes in.

    Using the Flower framework, EndoTwin trains individual models on local hospital servers. Only the model weights (the learned patterns) are transmitted back to our central FastAPI aggregator.

  • 1Local nodes compute gradients on private patient data.
  • 2Encrypted weights are sent to the central aggregator.
  • 3The aggregator averages these weights and broadcasts the improved global model back.
  • Result? A highly intelligent predictive model that never actually 'sees' patient data.

    Physics-Informed Neural Networks (PINN)

    Standard neural networks are black boxes. In healthcare, a black box is dangerous.

    We integrated PINN because it forces the neural network to obey known biological laws (e.g., specific hormonal progression rates). This severely reduced our "impossible" AI hallucinations.

    The Future of EndoTwin

    EndoTwin is more than a project; it is a proof that high-end AI engineering can solve deeply human problems. The transition to Dockerized Kubernetes pods means we can now deploy this system to any healthcare provider's isolated environment in minutes.

    If you're an AI/ML developer, don't just build scripts. Build systems.

    Akash Kumar Singh

    Akash Kumar Singh

    Founder & CEO @ Dilwado.com · Tech Entrepreneur · Full-Stack Developer

    MCA student at Sarala Birla University, Ranchi. Google Student Ambassador. 400K+ YouTube creator. BIT Mesra Hackathon winner. Building AI-powered educational tools that democratize learning for 10,000+ students.

    Share this article
    Tweet Share

    Related Articles

    Want more insights?

    Explore all articles on entrepreneurship, AI/ML, YouTube growth, and developer career building from Ranchi, India.