Skip to content

A simple but fast URL shortener built using FastAPI, PostgreSQL, and Redis.

License

Notifications You must be signed in to change notification settings

Mohsen-Khodabakhshi/url-shortener

Repository files navigation

FastAPI URL Shortener

A simple but fast URL shortener built using FastAPI, PostgreSQL, and Redis.

Load/Stress Test Result

System info:

  • Memory: 16GB
  • CPU: 8 cores

Redirect Result:

  • Read from Redis(Cache): RPS(request per second) ≅ 900
  • Read from Postgresql: RPS(request per second) ≅ 400
  • AVG response time ≅ 200ms

Installation

To run the project locally, follow these steps:

Option 1:

Prerequisites

  • Docker
  • Docker Compose
  1. Clone the repository:
    git clone https://github.com/Mohsen-Khodabakhshi/url-shortener.git
    cd url-shortener
    
  2. Setup configuration file:
    cp src/.env.sample src/.env
  3. Run using docker-compose:
    docker-compose up --build
    

Option 2:

Prerequisites

  • Python 3.10.12
  • Poetry 1.8.3
  • Postgresql
  • Redis
  1. Clone the repository:
    git clone https://github.com/Mohsen-Khodabakhshi/url-shortener.git
    cd url-shortener/src
  2. Setup configuration file:
    cp .env.sample .env
  3. Install dependencies:
    poetry install
  4. Database migrations:
    poetry run alembic upgrade head
  5. Run project:
    poetry run uvicorn core.main:app --host 127.0.0.1 --port 8000
    

Contributing

Contributions are welcome! To contribute to this project, please follow these steps:

  1. Fork the repository.
  2. Create a new branch
  3. Make your changes.
  4. Install pre-commit hooks:
    pip install pre-commit
    pre-commit install
  5. Commit your changes
  6. Push to your branch
  7. Submit a pull request.