Skip to content

ishantanu/go-urlshortener

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Overview of URL shortener service

  1. Programming language: go
  2. Fast in-memory K/V store: BBoltDB
  3. HTTP router: httprouter
  4. Logging library: logrus

Inspirations

  1. https://github.com/pantrif/url-shortener
  2. https://github.com/pankajkhairnar/goShort
  3. https://github.com/xcoulon/go-url-shortener

REST endpoints

  1. [POST] - http://localhost:8080/url : It accepts POST form data with parameter "url" and returns json response with short URL and the original URL.
  2. [GET] - http://localhost:8080/{SHORT_CODE}/ : If SHORT_CODE is valid and found in BBoltDB request will be redirected to original URL.
  3. All other non-existent endpoints will return 404.
  4. In case invalid json payload gets supplied, it'll return 422.

Routing

Endpoint Method Payload Response Feature
/url POST {"url": "https://google.com"} JSON url validation, mandatory param
/{short_code} GET 301 Redirection redirects to original URL
/invalid_ep GET 404 endpoint validation
/url POST {"uaarl": "https:///google.com"} 422 Invalid payload

Design decisions made while selecting libs:

  1. logrus:

    1. Structural design of logrus makes user to think really hard about the important areas of the application where logging is absolutely required.
    2. Added benefits while doing log analysis with tools like ELK stack.
  2. BBoltDB:

    1. For an app like URL shortener it made sense to use fast in-memory KV store instead of going for relational way.
    2. BBoltDB is the fork of BoltDB and both of them are widely used.
    3. Ease of use.
  3. httprouter:

    1. Lightweight high performance HTTP request router.
    2. Scales better.
    3. Best Performance. Check Benchmarks.

Benchmarking:

  1. Tools used: vegeta,ab
  2. Head over to benchmark directory in the repository for exploring the above two options with detailed guide on running them.

About

URL shortener service in golang

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published