GithubHelp home page GithubHelp logo

callback's Introduction

Github CI/CD Go Report Repository Top Language Scrutinizer Code Quality GitHub go.mod Go version Codacy Grade Github Repository Size Github Open Issues Lines of code License GitHub last commit GitHub contributors Simply the best ;)

Callback service

Task description

Write a rest-service that listens on localhost:9090 for POST requests on /callback.

Run the go service attached to this task. It will send requests to your service at a fixed interval of 5 seconds.

The request body will look like this:

{
    "object_ids": [1,2,3,4,5,6]
}

The amount of IDs varies with each request. Expect up to 200 IDs.

Every ID is linked to an object whose details can be fetched from the provided service. Our service listens on localhost:9010/objects/:id and returns the following response:

{
    "id": <id>,
    "online": true|false
}

Note that this endpoint has an unpredictable response time between 300ms and 4s!

Your task is to request the object information for every incoming object_id and filter the objects by their "online" status. Store all objects in a PostgreSQL database along with a timestamp when the object was last seen.

Let your service delete objects in the database when they have not been received for more than 30 seconds.

Important: due to business constraints, we are not allowed to miss any callback to our service.

Write code so that all errors are properly recovered and that the endpoint is always available.

Optimize for very high throughput so that this service could work in production.

Bonus: some comments in the code to explain the more complicated parts are appreciated it is a nice bonus if you provide some way to set up the things needed for us to

Test your code.

Issues found in task description and fixed

  • POST /callback request could send zero object IDs
  • GET /objects/<id> route didn't work (incorrect strings.TrimPrefix)
  • signal.Notify tried to catch SIGKILL which was impossible
  • http.Client had a timeout = 1 second which was not enough to wait for POST /callback response

Solution notes

  • ๐Ÿ”ฑ clean architecture (handler->service->repository)
  • ๐Ÿ“– standard Go project layout (well, more or less ๐Ÿ˜Š)
  • ๐Ÿ’ฟ github CI/CD + docker compose + Makefile included
  • ๐Ÿ—ƒ๏ธ PostgreSQL migrations included
  • โœ… tests with mocks included
  • ๐Ÿ’ฅ rate limiter for object details requests included

HOWTO

  • run with make run
  • test with go test -v ./... (github scrutinizer doesn't like make test for some reason)

A picture is worth a thousand words

callback's People

Contributors

evt 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.