Short-URL

A URL shortener system

View Demo · System Design Overview

Table of Contents
  1. About The Project
  2. Getting Started
  3. System Design Overview

About The Project

This project build based on karanpratapsingh url-shortener system design guideline.

What is a URL Shortener?

A URL shortener service creates an alias or a short URL for a long URL. Users are redirected to the original URL when they visit these short links.

For example, the following long URL can be changed to a shorter URL.

Long URL: https://karanpratapsingh.com/courses/system-design/url-shortener

Short URL: https://bit.ly/3I71d3o

Getting Started

This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.

Prerequisites

Installation

  • Clone the repo

    git clone https://github.com/aaydin-tr/short-url.git
    
  • Setup environment variables

    • Back-End

      cd server/
      cp .env.dev .env
      

      Set up necessary environment variables such as MONGO_URL, MONGO_USERNAME, REDIS_URL, etc.

    • Front-End

      cd web/
      cp .env.dev .env
      

      If you did not change the server default port you do not need to change anything. Otherwise, you need to set correct VITE_API_URL URL

  • Use docker-compose to start back-end server

    cd server/ && docker-compose up -d
    
  • Npm run dev After all containers start running, you can start web server.

    npm run dev
    

With default configs, back-end server will run on http://localhost:8090, and front-end server will run on http://localhost:5173/

System Design Overview

Sequence Diagram

sequenceDiagram
    actor Client
    Client->>Server: GET /shorturl
    activate Server
    Server->>Cache: get shorturl
    activate Cache
    alt Get original url form cache
        Cache-->>Server: original-url.com
        Server-->>Client: 302 Found / Location: original-url.com
    else Get original url form database
        Cache-->>Server: not found
        Server->>Database: get shorturl
        activate Database
        alt Short Url exist in database
            Database-->>Server: original-url.com
            Server-)Cache: set original-url.com
            deactivate Cache
            Server-->>Client: 302 Found / Location: original-url.com
        else  Short Url not exist in database
            Database-->>Server: not found
            Server-->>Client: 404 Not Found
        end
        deactivate Database
    end
    deactivate Server

Top categories

Loading Svelte Themes