A fast and scalable URL shortening service built with FastAPI, PostgreSQL, and Redis.
- Shorten long URLs into short, shareable links
- Caching for low latency
- User authentication with JWT tokens
- Rate limiting to prevent abuse
- RESTful API design
- Cloud-ready deployment
- Backend: FastAPI (Python 3.11)
- Database: PostgreSQL
- Cache: Redis
- Authentication: JWT
- ORM: SQLAlchemy
- Deployment: Google Cloud Run
- Python 3.11+
- Docker & Docker Compose
- PostgreSQL
- Redis
git clone https://github.com/nglong14/Interview-App.git
cd URL-Shortener
python -m venv .venv
.venv\Scripts\activate
pip install -r requirements.txtCreate .env file:
DATABASE_HOSTNAME=localhost
DATABASE_PORT=5432
DATABASE_PASSWORD=yourpassword
DATABASE_NAME=url_shortener
DATABASE_USERNAME=postgres
SECRET_KEY=your-secret-key
ALGORITHM=HS256
ACCESS_TOKEN_EXPIRE_MINUTES=30
REDIS_HOST=localhost
REDIS_PORT=6379
ENVIRONMENT=developmentdocker-compose up -d
uvicorn backend.main:app --reloadAccess at http://localhost:8000
Documentation at http://localhost:8000/docs
POST /register
POST /loginPOST /urls/ # Create short URL
GET /urls/ # Get user's URLs
GET /urls/r/{code} # Redirect to original URL
DELETE /urls/{id} # Delete URLGET /healthURL-Shortener/
├── backend/
│ ├── routers/
│ │ ├── auth.py
│ │ ├── users.py
│ │ └── url.py
│ ├── models.py
│ ├── database.py
│ ├── config.py
│ ├── oauth2.py
│ ├── utils.py
│ └── main.py
├── test/
│ ├── conftest.py
│ └── test_url.py
├── Dockerfile
├── docker-compose.yml
├── requirements.txt
├── DEPLOYMENT_GUIDE.md
└── README.md
See DEPLOYMENT_GUIDE.md for complete deployment instructions to Google Cloud Platform.