Keeplinkin

A Redis and Flask based, feature rich url shortener.

: python

Concepts Used

  • REST API
  • NoSQL
  • Web Framework

Features

  • 3 Modes
  • Website
  • API

Code Link


Introduction

I had heard about Redis Database in a forum somehwere. So I dived into a rabbit hole and some considerable time later, I got out having made this project.

I really like working with Redis. It is simple to use and set up, has limited but very useful features and works well with most small apps.

I also liked using Flask, this was the first time I had actually used it, not just experimented with. Flask is lightweight and gets out of your way, allowing flexibility to use what I want to work with.

Working

The site front-end is based on a Bootstrap default theme which had to be adjusted alooot for making it responsive.

The client side JS with Jquery was a bit of a pain to work with, but once I got all pieces together, the code was managable.

This was my first time experimenting with Flask, I had combed through the docs and adjusted it enough to just work.

The algorithms are actually pretty simple :

  • The first one to generate a default short link with random characters.It uses a base64-ish algorithm, but with a few characters removed, like + and ? to make it URL friendly , hence it is actually base62. The index or position of the long URL entry in the database is returned as a base62 string. The same is decoded while resolving the short URLS.
  • The second algorithm generates strings wich are pronouncable, Fake Words. This uses the random module to generate words with specified number of syllables. And since syllables are made up of either:
    • A consonant and vowel
    • A vowel and consonant
    • a consonant , vowel and then consonant

Thus the Fake word is generated.

Flask is actually pretty cool, it is very flexible, unlike Django, so I can mix and match with components to replace if need be. I used the redis module for the first time.

Redis is actually pretty awesome, it is simple and straightforward and a breeze to install and use. Locally it was simple, but on Heroku it needed some adjustment.

The database has just two data types:

  • A Sorted Set of default values is stored , with the index used to identify as shown before.
  • A Hash Table is used to store custom URLS and Fake Words with the Long URL.

I deployed the whole thing on Heroku with the Free Plan. It is a very useful service.

Heroku doesnt have native support for Redis, but it does have an addon provided from the makers themselves. It was still much easier to set up than any MySQL database.

Features

What the site does is, it takes a long URL and shortens it. Simple.

The site has 3 modes of operation:

  • Default Mode: generates short string of base62 string

Default Mode

  • Custom Mode: There is an option to select your short url, but its based on availability.

Custom Mode

  • Fake Word: So I had noticed that it was much more difficult to remember random characters as compared to words. Since it would be an overkill to use a huge db of words, I made this tool which will generate words which mean nothing, but are still pronouncable.

Fake Word Mode

The result is based on the option chosen. The link is generated and sent back via AJAX as shown below..

Result

There is also an API for use, but it allows default mode only.

Conclusion

I enjoyed working on this project and I learned quite a few things like :

  • Deploying site on Heroku (CLI and GitHub)
  • Flask
  • Redis
  • String Based Algorithms