Giter VIP home page Giter VIP logo

shorturl's Introduction

ShortURL: A URL Shortening service ๐Ÿ”—

Project Logo

A distributed and highly available URL Shortener.


๐Ÿ“š | Introduction

  • ShortURL is a distributed and highly available URL Shortening service, built on the MERN stack.
  • 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 Apache ZooKeeper to provide tokens for hash generation, and eliminates race conditions between nodes.
  • The entire application is containerized by Docker, and orchestrated by k8s.

Disclaimer

  • This is a demo application of a URL Shortener following the guidelines of efficient System Design.
  • This is a project demonstrating the entire development process and is meant to be run in a local environment.

๐Ÿš€ | Usage

  • Install Docker Desktop and enable Kubernetes for a quick setup.
  • Clone this repository:
git clone https://github.com/muKaustav/ShortURL.git
  • Create a .env file with the following variables:
REACT_APP_MONGODB_URI="<enter your MongoDB URI>"
REACT_APP_REDIS_PORT=1111 (defaults to 6379)
REACT_APP_REDIS_HOST='redis-server' (name it as you like, but change the same in the docker-compose.yml file)
  • Open the project folder 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 node-server=3
  • Enjoy the project! ๐Ÿ˜‰

๐ŸŒ | API Endpoints

GET:
    /url/:identifier : Get the shortened URL from DB
    /del : Delete the Zookeeper token
POST:
    /url [body : {"OriginalUrl" : "url"}] : Shorten the URL and store in DB


Access the API using the following URLs:
    Client: http://localhost:3000/
    Load Balanced Server: http://localhost:4000/

๐Ÿ“บ | Demonstration

trim


๐Ÿ“˜ | System Design Schematic

getURL redirect


โŒ› | Architectural Discussion

  • The availability of the application can be improved by using multiple Zookeeper instances, replicas of the DB, and a distributed cache, thus increasing the fault tolerance of the architecture.
  • Adding load balancers in between the following improves the performance of the application, and reduces the load on any particular instance:
    • client and server
    • server and DB
    • server and cache
  • CAP Theorem:
    • We opt for an eventually consistent approach, as in case of a network partition, a URL Shortener should have low latency and high throughput at all times.
    • Redirection of the user to the original URL should always have low latency as it directly impacts the business aspect of the application.
    • We don't opt for a strongly consistent approach, as we would have to wait for the data to be replicated across the cluster, which decreases the availability and increases the latency of the application, thus impacting the user experience negatively.

๐Ÿ’ป | References


๐Ÿป | Contributing

Contributions, issues and feature requests are welcome.
Feel free to check issues page if you want to contribute.


๐Ÿง‘๐Ÿฝ | Author

Kaustav Mukhopadhyay


๐Ÿ™Œ | Show your support

Drop a โญ๏ธ if this project helped you!


๐Ÿ“ | License

Copyright ยฉ 2021 Kaustav Mukhopadhyay.
This project is MIT licensed.


shorturl's People

Contributors

mukaustav avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

shorturl's Issues

location of .env is unclear

maybe replace:
Create a .env file with the following variables:
with:
Create a .env file in ShortURL/server/ with the following variables:

will make it clear.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.