I have used Node.js for my server side rendering, React as my frontend, MongoDB as my database and Redis to cache the shortened URLs.
- Clone the repository.
- Open a redis server.
- Go to the directory where you have installed mongodb and run
mongod
from your terminal. - Go to the cloned repository.
- Run
npm install
from your terminal to install all the dependencies - Run
nodemon server.js
from you terminal to start the server. - Go to the clients directory and run
npm install
. - run
npm start
to start the React app. - Open
localhost:3000
on your browser.
- I have assumed that we only need to show the requested shortened URL for the given original URL.
- Given a URL, our service should generate a shorter and unique alias of it.
- When users access a short link, our service should redirect them to the original link.
- The system should be highly available.
- URL redirections should happen in real-time with minimal latency. This is why I have used Redis to cache our data.
- Shortened links should not be predictable.
- Our system would be read heavy, this is the reason of me using a NoSQL database.
- Caching would be great if we could store 20% of our recently used data into the cache. I have not implemented this feature for our caching system due to time constraint.
- We can also use a NoSQL database like Cassandra for this system since it has faster writes and does not sacrifice read efficiency.
- To scale out our database, we need to partition it so that it can store information about billions of URL.
- After partioning we can also use consistent hashing to avoid overloading problems.
- We can also get same short url for different original url due to random hashing.