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.
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
- 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
git clone https://github.com/your-username/grpc-microservices.git
cd grpc-microservices
pip install -r requirements.txt # Install dependencies for Python services
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
# 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
# Initialize Docker Swarm
docker swarm init
# Deploy the stack
docker stack deploy -c docker-compose.yml grpc_microservices
# List running services
docker service ls
- POST /login → Authenticate a user and return JWT token
- POST /register → Register a new user
- POST /logout → Logout and invalidate JWT session
- GET /users/{id} → Get user details
- PUT /users/{id} → Update user details
- POST /tasks → Create a new task
- GET /tasks/{id} → Retrieve a task
SECRET_KEY=your_secret_key
DATABASE_URL=postgresql://user:password@db:5432/database_name
REDIS_URL=redis://localhost:6379
- Unit Tests: Ensure individual components function correctly.
- Integration Tests: Test interactions between microservices.
- Run tests using:
pytest tests/
- Docker Swarm for scalable deployment.
- CI/CD Pipeline using GitHub Actions or GitLab CI/CD.
MIT License
Happy Coding! 🚀