This is a link shortener application built using Ruby on Rails that has test coverage and uses Postgres. The application takes into account scalability and is built to handle 1k new urls a day, where each url gets hit 20k times a day. Try out the application at this Heroku link.
- Run
bundle install
from the root directory to install ruby dependencies - Run
rails db:setup
to setup the database - Run
bin/rails server
orrails s
to start a web server on your development machine to see/start the Rails application - Navigate your browser to localhost:3000
- Run
rake db:test:load
to recreate the test database from the current db/schema.rb - On subsequent attempts, first run
rake db:test:prepare
to check for pending migrations - Run
rails test
to run tests
- Root renders a form in which you can drop a URL. When you do, you'll get redirected to a page with its shortened URL and an admin URL.
- When you go to a shortened URL, you get redirected to the original URL that was submitted, as long as the URL is active. Usage is also counted.
- When you go to the Admin URL, you are given the ability to expire the shortened link and see how many times your link has been used. When a link has been expired, an empty 404 gets rendered.
The database layer is very simple. It only has one table: it stores information about the URL mappings. To keep things simple, there is no user table to keep track of registered users. Meaning, there is no user registration implemented for this app.
This diagram shows the request flow for creating a new shortened link. The user sends a request to the link shortener application, computes the business logic, which then writes to the postgreSQL database the new URL mapping/record.
This diagram shows the request flow to request for the original URL from a shortened URL. The user sends the request to the application, which reads the original URL based on the unique shortened URL. If the shortened URL existed, then the client will receive an HTTP 302 Redirect Response. If the shortened URL did not exist, the user will receive an HTTP 404 Not Found response.
Some of the most interesting aspects of software engineering is figuring out the system design for the application and taking into account scalability as well. Some of the thoughts regarding these aspects of software engineering has been documented; see the System Design Considerations document for more information.