A production-grade, high-performance User Microservice built with FastAPI, PostgreSQL, and Redis. Designed to handle massive traffic spikes with aggressive caching, asynchronous background tasks, and cloud-native resilience patterns.
- JWT-based Authentication: Secure access and refresh token flows with
jticlaim validation. - Async Password Hashing: Bcrypt operations are offloaded to a dedicated thread pool to prevent event loop starvation.
- Account Lockout: Automated protection against brute-force attacks (5 failed attempts = 15-minute lockout).
- Token Blacklisting: Real-time token revocation on logout and refresh.
- Aggressive Redis Caching: The
/meprofile endpoint is optimized for sub-10ms response times via intelligent caching. - Fail-Fast Load Shedding: Reduced database connection pool timeouts to prevent cascading failures under heavy load.
- Asynchronous Workflows: Email delivery and heavy tasks are handled by Celery workers to keep the API layer stateless and fast.
- Cloud-Native Health Checks: Split
/health/live(liveness) and/health/ready(readiness) probes for seamless Kubernetes/Docker integration. - Observability: Structured JSON logging, Request IDs, and Prometheus metrics at
/metrics. - Modern Tooling: Built with
uvfor lightning-fast dependency management andrufffor strict linting.
app/
├── api/ # Route handlers (v1)
├── core/ # Security, Logging, Metrics, Rate Limiting
├── db/ # Postgres & Redis Engine setup
├── middleware/ # Structured Logging & Prometheus Middleware
├── models/ # SQLAlchemy (SQL) Data Models
├── schemas/ # Pydantic (JSON) Validation Schemas
├── services/ # Business Logic & Cache Providers
└── tasks/ # Celery App & Background Workers
- Docker & Docker Compose
- Python 3.13+
- uv (Recommended)
Copy the example environment file and fill in your secrets:
cp .env.example .envThe easiest way to start the full stack (API + Worker + DB + Redis):
docker compose up --buildThe API will be available at http://localhost:8000.
If you prefer running without Docker:
# Install dependencies
uv sync
# Apply database migrations
uv run alembic upgrade head
# Start the API
uv run uvicorn app.main:app --reload
# Start the Celery Worker (In a new terminal)
uv run celery -A app.tasks.celery_app.celery_app worker --loglevel=info| Endpoint | Method | Description |
|---|---|---|
/api/v1/users/signup |
POST |
Create a new account |
/api/v1/users/login |
POST |
Authenticate & get JWT tokens |
/api/v1/users/me |
GET |
Get current user (Cached) |
/health/live |
GET |
Process liveness check |
/health/ready |
GET |
Dependency readiness check |
/metrics |
GET |
Prometheus telemetry |
We maintain a 100% green test suite covering all critical auth and scaling paths.
uv run pytestThe project includes a locustfile.py to simulate high-concurrency traffic.
# 1. Setup test data
uv run setup_test_data.py
# 2. Run Locust
uv run locust --headless -u 1000 -r 100 --run-time 1m --host=http://localhost:8000This project is licensed under the MIT License.
