Skip to content

yadavshubham01/gRPC-Based-Microservices

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🚀 gRPC-Based Microservices with FastAPI

📌 Project Overview

This project implements a gRPC-based microservices architecture using FastAPI as the API Gateway. It consists of multiple microservices communicating via gRPC, each handling different functionalities like authentication, user management, and task processing. The project is containerized using Docker and supports Redis for caching sessions.

🏗 Architecture

grpc-microservices/
│── auth_service/         # gRPC Auth Service (User Authentication)
│── user_service/         # gRPC User Service (Handles User Profiles)
│── task_service/         # gRPC Task Service (Task Queues, Scheduling)
│── api_gateway/          # FastAPI API Gateway (REST Wrapper)
│── proto/                # gRPC Protocol Buffers
│── docker-compose.yml    # Docker Setup
│── README.md             # Project Documentation
│── tests/                # Unit and Integration Tests

⚡ Tech Stack

  • FastAPI - API Gateway
  • gRPC - Inter-service communication
  • PostgreSQL - Database for user management
  • Redis - Caching & Session Management
  • Docker & Docker Swarm - Containerization & Deployment
  • JWT Authentication - Secure user sessions

🚀 Getting Started

1️⃣ Clone the Repository

git clone https://github.com/your-username/grpc-microservices.git
cd grpc-microservices

2️⃣ Install Dependencies

pip install -r requirements.txt  # Install dependencies for Python services

3️⃣ Generate gRPC Code

python -m grpc_tools.protoc -I proto --python_out=auth_service --grpc_python_out=auth_service proto/auth.proto
python -m grpc_tools.protoc -I proto --python_out=user_service --grpc_python_out=user_service proto/user.proto
python -m grpc_tools.protoc -I proto --python_out=task_service --grpc_python_out=task_service proto/task.proto

4️⃣ Start Services

Run Each Service Manually

# Start Authentication Service
terminal 1: python auth_service/server.py

# Start User Service
terminal 2: python user_service/server.py

# Start Task Service
terminal 3: python task_service/server.py

# Start API Gateway
terminal 4: python api_gateway/main.py

Run Using Docker Swarm

# Initialize Docker Swarm
docker swarm init

# Deploy the stack
docker stack deploy -c docker-compose.yml grpc_microservices

# List running services
docker service ls

🎯 API Endpoints

Authentication

  • POST /login → Authenticate a user and return JWT token
  • POST /register → Register a new user
  • POST /logout → Logout and invalidate JWT session

Users

  • GET /users/{id} → Get user details
  • PUT /users/{id} → Update user details

Tasks

  • POST /tasks → Create a new task
  • GET /tasks/{id} → Retrieve a task

🛠 Environment Variables (.env)

SECRET_KEY=your_secret_key
DATABASE_URL=postgresql://user:password@db:5432/database_name
REDIS_URL=redis://localhost:6379

📝 Testing

  • Unit Tests: Ensure individual components function correctly.
  • Integration Tests: Test interactions between microservices.
  • Run tests using:
pytest tests/

📌 Deployment

  • Docker Swarm for scalable deployment.
  • CI/CD Pipeline using GitHub Actions or GitLab CI/CD.

📜 License

MIT License

💡 Author

Shubham yadav

Happy Coding! 🚀

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published