Giter Site home page Giter Site logo

go_code_challenge_v1's Introduction

Go Coding Challenge v1

Context

We have a website on the Internet and we would like to get some very simple indication of how visitors navigate the pages. For that purpose, we managed to configure our website to send an event every time a visitor navigates to a page. Our website is capable of generating unique identifiers for visitors as a string of characters.

The system generating that event is able to talk to a REST HTTP interface and represents each individual event as a JSON document containing two attributes: the unique identifier of the visitor and the URL of the visited page.

Our product team is starting a new sprint. We are picking the following user story: As a digital marketeer, I need to know how many distinct visitors navigated to a page, knowing its URL.

Task

Build a GoLang web service capable of:

  • Ingesting user navigation JSON events via a REST HTTP endpoint. Each event is to be ingested via a separate HTTP request (i.e. no batch and no streaming ingestion).

  • Serving the number of distinct visitors for any given page via another REST HTTP endpoint. The page URL we are interested in should be a query parameter of the HTTP request. The number of distinct visitors for that URL is returned in a JSON object.

Constraints

  • There is no need for persistence to a database. Everything can be kept in memory.
  • The web service must be capable of handling concurrent requests on both endpoints.
  • Don't solve the data access concurrency problem using an external library

Implementation

The visit counter service provides the following HTTP endpoints:

  • /visits/new

    • Method: POST
    • Payload: json message containing the visitor ID and the page URL. For example:
    {
        "url": "/products/42",
        "visitor_id":"53847aa8-f5ab-4b8a-844c-f1bb1241ab55"
    }
  • /visits/stats

    • Method: GET
    • Query: url=/products/42
    • Response: json payload containing the distinct visitors for the page
    {
        "unique_visitors": 1719
    }

To build the program from source run make build and to start the program typing ./counter. The program accepts the following optional arguments:

Usage of ./counter:
  -cors
        Enable CORS support
  -debug
        Increases logging verbosity to DEBUG level
  -listen string
        TCP Address to listen to incoming connections (format IP:Port)
  -trace
        Increases logging verbosity to TRACE level

go_code_challenge_v1's People

Contributors

angiglesias avatar

Watchers

 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.