Skip to content

phhoang98a/Shortify

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A distributed and highly available URL Shortener.


Introduction

  • Shortify is a distributed and highly available URL Shortening service, following the guidelines of efficient System Design and builting on the Reactjs as front-end and Spring boot as back-end.
  • It uses Redis as a cache, and MongoDB as a NoSQL database.
  • It uses Nginx that acts as a load balancer, and a reverse proxy for the backend server.
  • It uses an Unique ID generator inspired by Twitter snowflake for id and hash generation.
  • The application is containerized by Docker.
  • This is a project demonstrating the entire development process and is meant to be run in a local environment.

Usage

  • Install Docker Desktop for a quick setup.
  • Clone this repository
  • Open the terminal and start the container with docker compose:
docker compose up --build

# We can also scale instances of an image for higher scalability or distribution.
Example: docker compose up --build --scale spring-boot-server=3

Demonstration

Screen.Recording.2023-12-29.at.6.14.21.AM.mov

Unique Id and Hash generation

You can read about Twitter snowflake and this blog (Generating unique IDs in a distributed environment at high scale) to understand the Id generator I used in this application

I use the base 62 convention which is referred to in System Design Interview by Alex Xu to convert Id to shortURL.

Base 62 conversion is used as there are 62 possible characters for hashValue. Let us use an example to explain how the conversion works: Convert 1115710 to base 62 representation (1115710 represents 11157 in a base 10 system).

• From its name, base 62 is a way of using 62 characters for encoding. The mappings are: 0-0, ..., 9-9, 10-a, 11-b, ..., 35-z, 36-A, ..., 61-Z, where ‘a’ stands for 10, ‘Z’ stands for 61, etc.

• 1115710 = 2 x 62^2 + 55 x 62^1 + 59 x 62^0 = [2, 55, 59] -> [2, T, X] in base 62 representation.

• Thus, the short URL is https://tinyurl.com/2TX

System Design

URL shortening

1

URL redirecting

Screenshot 2023-12-29 at 7 10 25 AM

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published