Giter Club home page Giter Club logo

go-urlshortener's Introduction

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.

go-urlshortener's People

Contributors

ishantanu avatar

Watchers

 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.