Giter VIP home page Giter VIP logo

url-shortener's Introduction

This is a URL Shortener

Architecture

  • Angular and Bootstrap frontend.
  • Jetty for the webserver (both frontend and api hosted there).
  • Redis as a database (optional).
    • It was chosen because of my familiarity however there are a couple downsides.
    • I also use a Bloom Filter in addition to Redis in order to pre-filter calls to it. This saves time and resources, knowing if the key has already been seen or not.
    • It takes a snapshot of the database every 60s which I think is acceptable.
    • It is a in memory database so the amount of KV pairs is limited by RAM which is not ideal for a use case where there might be billions of entries.
    • If I had more time I would have used a database like LevelDB or Cassandra. Or implemented a custom solution using SSTables.
      • SSTables are used in LevelDB, however since I don't need to write over entries in the database ever, and LevelDB has more functionality than I need (and it isn't easily used with Java). SSTables are great for read heavy workloads from a disk.
  • Standalone mode w/o Redis available (no persistence).
    • This mode just uses a ConcurrentHashMap to store the key value pairs. It will not survive a restart or crash.
  • The short URLs are generated randomly even for the same input. BaseX encoding schemes could have been used, however I noticed sites like tinyurl.com and bit.ly generate random keys for duplicate entries.

Note

This project is also hosted on my server in my apartment. I went a bit overboard with this implementation than was probably expected, but I have been wanting to create a URL Shortener for myself for a while now and this was just a good opportunity. My server environment is exclusively in Docker so it didn't take too long to set up.

How to run/build

There are two Bash scripts.

  • The first one is run_docker.sh which builds the docker container and then runs it with docker-compose. It contains Redis by default as well and the configuration options can be changed in the docker-compose.yml.
    • If the persistency is tested with the Redis database. Please wait at least 60s after creating the short URL to stop the docker services. This allows Redis to make a snapshot.
  • The second one is run_standalone.sh which requires npm and maven to be installed on the system. The maven build targets Java 11+. The script has environment variables at the top which can be modified.
    • Java 11 or greater is required

Sources/Third Party Libraries:

url-shortener's People

Contributors

dependabot[bot] avatar stealthbadger747 avatar

Stargazers

 avatar

Watchers

 avatar  avatar  avatar

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.