This project is a production-style FastAPI authentication system designed with scalability, performance, and real-world backend engineering practices in mind.
It demonstrates how to build and optimize a backend system using:
- FastAPI
- PostgreSQL
- Redis
- JWT Authentication
- Load Testing (Locust)
- ๐ JWT-based Authentication (Login/Register)
- ๐ค User Management APIs
- โก Redis Caching for performance optimization
- ๐๏ธ PostgreSQL with optimized connection pooling
- ๐งช Load testing with Locust
- ๐ Performance benchmarking & analysis
- ๐ Multi-worker scaling using Uvicorn
| Layer | Technology |
|---|---|
| Backend | FastAPI |
| Database | PostgreSQL |
| Cache | Redis |
| ORM | SQLAlchemy |
| Auth | JWT (python-jose) |
| Password Hashing | bcrypt (passlib) |
| Load Testing | Locust |
Client โ FastAPI โ Redis (cache) โ PostgreSQL
โ
JWT Auth
Shows interactions between FastAPI, Redis, and PostgreSQL with JWT-based authentication.

- High latency
- DB bottleneck
- Poor scalability
- Connection pooling introduced
- Improved stability
- Reduced hashing cost
- Improved response time
- Cached
/users/me - Eliminated repeated DB reads
- Throughput: ~155 RPS
- Avg Latency: ~456 ms
- Failure Rate: ~0.09%
- Throughput: ~93 RPS
- Avg Latency: ~1.7 sec
- Failure Rate: ~3%
- Redis removed the database bottleneck
- System shifted from I/O-bound โ CPU-bound
- bcrypt hashing became the main limitation
- Worker saturation affects performance under high load
FastAPI-Authentication-System/
โ
โโโ .github/
โ โโโ workflows/
โ โโโ ci.yml # CI/CD pipeline (GitHub Actions)
โ
โโโ app/
โ โโโ core/
โ โ โโโ redis.py # Redis client setup
โ โ
โ โโโ routes/
โ โ โโโ auth_routes.py # Authentication endpoints (login/register)
โ โ โโโ user_routes.py # User endpoints (/users/me)
โ โ โโโ redis_routes.py # Redis test/debug endpoints
โ โ โโโ init.py
โ โ
โ โโโ init.py
โ โโโ auth.py # JWT + password hashing (bcrypt)
โ โโโ config.py # Environment configuration
โ โโโ database.py # DB connection & session
โ โโโ dependencies.py # Auth dependency (get_current_user)
โ โโโ logger.py # Logging setup
โ โโโ main.py # FastAPI entry point
โ โโโ models.py # SQLAlchemy models
โ โโโ schemas.py # Pydantic schemas
โ
โโโ diagrams/ # System design diagrams
โ โโโ architectural_design.png
โ โโโ component.png
โ โโโ sequence_login.png
โ โโโ sequence_users_me.png
โ โโโ state_auth.png
โ โโโ deployment.png
โ โโโ data_flow.png
โ
โโโ performance/ # Load testing & benchmarking
โ โโโ screenshots/ # Locust UI screenshots
โ โโโ results/ # Metrics per phase
โ โโโ notes/ # Observations & insights
โ
โโโ tests/ # Unit & integration tests
โโโ logs/ # Application logs
โ
โโโ requirements.txt # Dependencies
โโโ README.md # Project documentation
โโโ LICENSE
โโโ .gitignore
โโโ test_auth.db # SQLite test DB (local/testing)
โโโ .test_auth.db # Temporary test DB (CI)
git clone <your-repo-url>
cd FastAPI-Authentication-System
pip install -r requirements.txt
Make sure PostgreSQL is running and configured.
docker run -d -p 6379:6379 redis
uvicorn app.main:app --workers 4
Run Locust:
locust -f locustfile.py --host=http://127.0.0.1:8000
Open:
http://localhost:8089
- Async DB (asyncpg)
- Background password hashing
- Load balancer (Nginx)
- Horizontal scaling (multiple instances)
- Rate limiting using Redis
- Backend system design
- Performance optimization
- Load testing & benchmarking
- Bottleneck identification
- Real-world scalability challenges
Aniket Paswan
Aspiring AI/ML Engineer,Backend Engineer
This project reflects a real engineering journey:
Database Bottleneck โ Redis Optimization โ CPU Bottleneck
Understanding this transition is key to designing scalable backend systems.