A production-ready, highly scalable microservices backend built with FastAPI and Python. This architecture employs modern asynchronous programming, event-driven communication, API Gateway patterns, and robust containerization suitable for large-scale enterprise applications.
- Domain-Driven Design (DDD): Divided into logical bounded contexts (
Auth,User,Product,Order,Notification). - API Gateway Pattern: Centralized entry point dynamically routing to backend microservices utilizing asynchronous
HTTPX. - Asynchronous Stack: Leveraging
asyncpgfor PostgreSQL,redis.asynciofor caching, andaio-pikafor RabbitMQ. - Hybrid Communication:
- Synchronous: RESTful API via HTTPX through the Gateway.
- Asynchronous: Event-driven message brokering via RabbitMQ for decoupled operations.
- Resilient Infrastructure: Centralized shared core library for Authentication, Database, Messaging, and Caching.
- Automated Migrations: SQLAlchemy and Alembic configured for zero-downtime database schema upgrades.
- Kubernetes Ready: Out-of-the-box support for Deployments, Services, ConfigMaps, and Ingress routing.
graph TD
Client([Client / Frontend]) -->|HTTP Requests| Gateway[API Gateway]
subgraph Synchronous Layer
Gateway -->|HTTPX Route| Auth[Auth Service]
Gateway -->|HTTPX Route| User[User Service]
Gateway -->|HTTPX Route| Product[Product Service]
Gateway -->|HTTPX Route| Order[Order Service]
end
subgraph Data Layer
Auth --> DB_Auth[(PostgreSQL)]
User --> DB_User[(PostgreSQL)]
User --> Redis_Cache[(Redis)]
Product --> DB_Product[(PostgreSQL)]
Order --> DB_Order[(PostgreSQL)]
end
subgraph Asynchronous Layer
User -->|Publish Event| RMQ[[RabbitMQ]]
Order -->|Publish Event| RMQ
RMQ -->|Consume Event| Notification[Notification Service]
end
.
├── auth-service/ # JWT Authentication and Authorization provider
├── user-service/ # User Management, profiles, and CRUD logic
├── product-service/ # Product Catalog and Inventory tracking
├── order-service/ # Order processing and orchestration
├── notification-service/ # Async consumer (e.g., Email, SMS via RabbitMQ)
├── gateway/ # Centralized entry point, rate limiting, and routing
├── shared/ # Core Python package (DB, Redis, MQ, Auth utils)
├── k8s/ # Kubernetes manifest templates
├── docker-compose.yml # Local orchestration map
└── README.md # You are here
- Docker and Docker Compose installed.
- Python 3.10+ (for local testing).
To start the services locally (including PostgreSQL, Redis, and RabbitMQ):
docker-compose up --build -dNote: This will spin up all 6 microservices and 3 infrastructure containers. Wait a few moments for the databases to initialize.
Check the health of the API Gateway and underlying services:
- Gateway Swagger UI:
http://localhost:8000/docs - Gateway Health Check:
http://localhost:8000/health - RabbitMQ Dashboard:
http://localhost:15672(guest / guest)
Navigate to any microservice folder and run pytest:
cd user-service
pip install pytest httpx
pytest tests/This project contains complete manifestation templates for Kubernetes deployments under the k8s/ directory.
- Deploy Infrastructure:
kubectl apply -f k8s/postgres.yaml kubectl apply -f k8s/redis.yaml kubectl apply -f k8s/rabbitmq.yaml
- Deploy Microservices:
kubectl apply -f k8s/gateway.yaml kubectl apply -f k8s/auth-service.yaml kubectl apply -f k8s/user-service.yaml kubectl apply -f k8s/product-service.yaml kubectl apply -f k8s/order-service.yaml kubectl apply -f k8s/notification-service.yaml
- Deploy Ingress:
kubectl apply -f k8s/ingress.yaml
- JWT Bearer Auth: Stateless tokens passed through headers, validated at the API Gateway or individual services.
- Environment Variables: No hardcoded secrets. Relying on
.envlocally andConfigMapsin K8s. - Rate Limiting: (Designed) utilizing Redis to prevent brute-force attacks at the Gateway layer.
- Statelessness: All API nodes are 100% stateless, safely scaling up and down on demand.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.