Code Monkey home page Code Monkey logo

auction_service's Introduction

Auction Service:

Auction and Bidding components are divided into two sub-services under root auction_service package.

Bidding Service:

APIs:

POST /bid

DTOs:

type BidRequest struct {
	MsgID         string `json:"MsgID"`
	AdPlacementId string `json:"AdPlacementId"`
}

type BidResponse struct {
	AdID     string `json:"AdID"`
	BidPrice int64  `json:"BidPrice"`
}

When bidding service receives a request on /bid API a random UUID is generated for AdID and a random integer is generated to be used as BidPrice.

And for generating failure scenarios I'm failing 1 out of 5 requests (pseudo random way) by generating random number from 0-4 and returning 204 in case value is 1.

Auction Service:

APIS:

POST /auction

DTOs:

type AuctionObject struct {
	AdID          string `json:"AdID"`
	BidPrice      int64  `json:"BidPrice"`
	AdPlacementId string `json:"AdPlacementId"`
}

type AuctionRequest struct {
	MsgID         string `json:"MsgID"`
	AdPlacementId string `json:"AdPlacementId"`
}

type AuctionResponse struct {
	Ads []*service.AuctionObject `json:"Ads"`
}

On getting a request on /auction API auction service hits bidding service concurrently BIDDING_COUNT times and returns the responses it go from all the calls combined in an array of responses.

A rate limiter middleware was enabled to this API to accept only 5 requests in a second and other requests will be returned an error with status code 429.

Instructions to run:

Assuming docker-compose, docker are already installed in the system

$ cd $GOPATH/src
$ git clone [email protected]:Prashant-Surya/auction_service.git
$ cd auction_service
$ docker-compose up -d

Once it's up, /auction API is available at port 8081.

Sample Curl:

curl -X POST \
  http://localhost:8081/auction \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' \
  -d '{
	"AdPlacementId": "123"
}'

For testing /bid of bidding service, it's reachable at localhost:8080

Sample Curl:

curl -X POST \
  http://localhost:8080/bid \
  -H 'Content-Type: application/json' \
  -H 'cache-control: no-cache' \
  -d '{
	"AdPlacementId": "tea",
	"MsgID": "ms"
}'

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.