Patient Management System

Microservices-Based Healthcare Management Backend

Project Overview

This project is a microservices-based backend system for managing appointments, patients, doctors, and billing in a healthcare environment. It follows a modular, scalable design and uses different databases tailored to each service's needs.

Architecture

6 independent microservices with API Gateway

Containerization

Fully dockerized with Docker Compose

Event-Driven

Apache Kafka for service communication

Multi-Database

MySQL, PostgreSQL, and MongoDB

System Architecture

The system consists of the following microservices, each containerized via Docker:

Service Port Database Primary Function
API Gateway 4004 - Request routing and management
Patient Service 8080 MySQL Patient records management
Billing Service 8081 PostgreSQL Payment processing and billing
Analytics Service 8082 MongoDB Data analytics and reporting
Doctor Service 8083 MySQL Doctor profiles and specializations
Appointment Service 8084 PostgreSQL Appointment scheduling and validation
Auth Service 8089 PostgreSQL Auth process

Microservices Details

πŸ‘₯

Patient Service

Database: Postgresql | Port: 8080

Responsibility: This microservice is responsible for managing endpoints about patient records. The relationship between Kafka and Patient Service sends an event to the Analytics Service. The database of this microservice is PostgresSQL and it runs simultaneously with the microservice, thanks to docker-compose.

{ "id": UUID, "name": String, "email": String, "address": String, "dateOfBirth": LocalDate, "registeredDate" LocalDate, }
πŸ‘¨β€βš•οΈ

Doctor Service

Database: MySQL | Port: 8083

Responsibilities: This microservice is responsible for managing endpoints about doctor records. The database of that microservice is MySQL. The reason beyond this database selection, it's generally optimized for read-heavy operations and offers slightly better performance in that context.

{ "id": UUID, "name": String, "yearsOfExperience": Integer, "hospitalName": String, "department": String, "licenseNumber" Integer, "specialization": ENUM, "Number": String, "email": String, "available": Boolean, "gender": ENUM }
πŸ“…

Appointment Service

Database: PostgreSQL | Port: 8084

Responsibilities: This microservice is responsible for managing appointments, verifying IDs, notifying other services with Kafka. The database of this microservice is PostgresSQL. It also has two services. One of the services is managing appointment process. With the help of Rest Template, this service verify the Patient ID and Doctor ID to create an appointment. Also, if any patient's payment process is successful then Kafka triggers an event for The Billing Service. The second service of this microservice is Cleanup Service, manages deleting outdated appointments every day.

{ "patientId": UUID, "doctorId": UUID, "serviceDate": String, "serviceDateEnd": String, "serviceType": ServiceType, "amount": float, "paymentStatus": boolean, "PaymentType": paymentType }
πŸ’°

Billing Service

Database: PostgreSQL | Port: 8081

Responsibilities: This microservice is responsible for creating billing records after appointments. It creates an invoice for a patient with invoice-generator API, and it stores invoice instances (PDF) on Billing Service image.

{ "patientId": Long, "appointmentId": Long, "paymentStatus": Boolean, "paymentType": ENUM }
πŸ“Š

Analytics Service

Database: MongoDB | Port: 8082
Storing event-based and analytical data (trends, usage stats)

πŸ“Š

Auth Service

Database: PostgreSQL | Port: 8089

Responsibilities: This microservice is responsible for creating auth records. It generates an JWT token for accessing other endpoints

{ "Name": String, "Email": String, "Password": String, "RegisterDate": LocalDate }
🌐

API Gateway

Port: 4004

Responsibilities: This microservice is responsible for managing request routing, and API management.

🌐

Common Things

  • βœ”Logger - slf4j -
  • βœ”REST API
  • βœ”Docker Compose
  • βœ”API Gateway Routing
  • βœ”Kafka
  • βœ”SQL

Why This ... Tool/Framework/Design?

?

Why Microservice Design?

I chose a microservice architecture to achieve loose coupling, scalability, and independent deployments. Each service is responsible for a specific domain (patients, doctors, appointments, billing, authentication), which makes the system modular and easier to maintain. This design also allows services to use different databases and technologies depending on their requirements, rather than being restricted to a single stack. In addition, microservices enable fault isolation β€” if one service fails, the others can continue functioning, improving the system’s reliability

?

Why PostgreSQL (and MySQL)?

Each microservice has its own database to respect the loose coupling principle. I used PostgreSQL for the Patient Service because of its powerful relational features, JSONB support, and advanced querying capabilities, which fit patient data well. On the other hand, I chose MySQL for the Doctor Service since it is lightweight and efficient for handling structured data with high read/write operations.

?

Why Kafka?

I used Apache Kafka for asynchronous, event-driven communication between services. Instead of relying only on HTTP calls, Kafka enabled me to build a scalable and fault-tolerant data pipeline. Producers generate events (such as patient updates or logs), and consumers process them independently, which reduces coupling and improves system resilience.

?

Why Docker & Kubernetes?

Docker allowed me to containerize services and databases, ensuring they run consistently across environments. Volumes were used to persist user data. Kubernetes provided orchestration features such as service discovery, load balancing, scaling, and persistent storage management, making deployments production-ready and easier to maintain.

?

Why API Gateway?

I implemented an API Gateway to act as the single entry point for all requests. This simplified routing, authentication, and abstraction, since clients do not need to know individual service endpoints. It also centralized security and cross-cutting concerns like logging and request filtering, improving both usability and maintainability.

?

Why CI/CD with GitHub Actions?

I set up GitHub Actions to automate build, test, and deployment pipelines. This reduced deployment time to under 15 minutes and ensured multi-platform Docker images could be pushed and deployed to cloud providers (AWS, GCP, Azure). The CI/CD pipeline improved reliability, minimized human error, and made the project more production-ready.

?

Why JWT Authentication?

I chose JWT (JSON Web Tokens) because it enables stateless and lightweight authentication, which is ideal in a microservices architecture. Tokens are passed with each request, so services can validate user identity without maintaining server-side sessions.

How Authentication And Authorization Works?

Ready to authenticate...
πŸ‘€
User
Makes request to protected resource
Sending request...
🌐
API Gateway
Routes requests & handles authentication
Routing to auth...
πŸ”
Auth Service
Handles login/register & JWT generation
Generating JWT...
eyJhbGciOiJIUzI1NiJ9.eyJzdWI...
πŸ—„οΈ
Database
Stores user credentials & data
User validated βœ“

Appointment Validation Flow

When a user tries to create an appointment, the system follows this validation process:

1
Request Received
The Appointment Service receives the appointment creation request
2
Patient Validation
Sends GET request to Patient Service to verify if the patientId exists
3
Doctor Validation
Sends GET request to Doctor Service to verify if the doctorId exists
4
Appointment Creation
If both validations pass, the appointment is created and stored
5
Billing Trigger
A billing record is automatically triggered and created as PDF

Billing - Invoice Flow

When a user create an appointment, the system follows this process for billing:

1
Kafka Triggered
The Kafka Receiver receives the necessary data from Appointment Service
2
Generating Unique ID And Using The Given Data
Process the data and creates Invoice Path
3
Invoice PDF Generated
With the help of Invoice Generator API, Billing process is ended.
4
Result
Instance

Api Gateway Flow

When a user request to an endpoint, the system follows this process for Api Gateway:

1
Client Request β†’ API Gateway
User sends a request (e.g. http://localhost:4004/api/patients) to API Gateway.
2
Predicate Check
Gateway checks the Path predicates to determine the correct microservice (patient-service, doctor-service, appointment-service, etc.).
3
Apply Filters
Defined filters are applied (e.g. StripPrefix, RewritePath) to adjust the request before forwarding.
4
Forward to Target Service
The modified request is forwarded to the target microservice (e.g. patient-service:8080).
5
Service Processes Request
The microservice executes business logic and returns a response.
6
Response Returned
API Gateway sends the response back to the client, so the user still communicates via http://localhost:4004.

DevOps & Deployment Workflow

From code to production: Complete CI/CD pipeline with containerization and Kubernetes orchestration

1
Code Push to GitHub
Developer pushes code changes to main branch, triggering automated workflow
2
Docker Image Build
GitHub Actions builds Docker images for all 6 microservices simultaneously
3
Container Registry Push
Built images are pushed to GitHub Container Registry with proper versioning
4
Kubernetes Manifest Update
Deployment manifests are automatically updated with new image tags
5
Production Deployment
Ready for deployment to any cloud provider (AWS ECS, GCP, Azure) in under 15 minutes

πŸ› οΈ DevOps Technology Stack

Docker Kubernetes GitHub Actions GitHub Container Registry AWS ECS Ready Google Cloud Run Ready Azure Container Ready

πŸ’‘ Deployment Impact: What previously took hours of manual setup and configuration now takes less than 15 minutes to deploy to any major cloud provider. The entire microservices ecosystem is containerized, orchestrated, and ready for horizontal scaling.

FIGMA - WEB STRUCTURE

Figma File Open Figma Folder

Postman Collection

Test all API endpoints with this ready-to-use Postman collection. Import the collection into your Postman to explore requests, headers, and sample responses.

Key Features

View Project

Explore the complete source code and documentation for this microservices architecture