Skip to content

mittulmandhan/bidding-server

Repository files navigation

bidding-server

Overview

Bidding Server is a custom, high performance, auction server for this online car auction company's web based auctions. Biding Server manages all the aspect of the whole auction process, from creating an auction to announcing a winner.

The server allows following capabilities to their web-based auction clients:

  • Only admin must be able to create auction
    • If there already exists a running auction for the given item then auction will not be created
  • user can bid on a running auction
    • Only logged in users are allowed to place bid
    • Accepted or rejected all user bids must be recorded
    • User must not be able to bid on an item which has no running auction or the auction is expired
  • user must be able to get the list of running auction
    • If user gave an invalid auction status system must return null response
  • Bid Accept Scenarios
    • If there exists no bid against the item and bid amount greater than or equal to base price
    • If there exists a bid against the item and upcoming bid must be greater than or equal to sum of highest bid and step rate
  • Bid Rejected Scenarios
    • If there exists no bid against the item and bid amount is less than base price
    • If there exists a bid against the item and upcoming bid is less than the sum of highest bid and step rate
  • Auction not found scenarios
    • If auction is expired
    • If auction is null
    • If item does not have running auction
  • As soon as the auction is over winner receives email
  • Auction automatically gets over once duration completes

Teck Stack

  • Java
  • Spring Boot
    • Web
    • Lombok
    • Netflix eureka
    • Data JPA
    • Config server
    • AMQP
    • MySQL Connector
  • Tomcat
  • MySQL
  • RabbitMQ
  • Graddle

Setup Guide

  • Must Have:

    • Java 11
    • MySQL 8.0.33
    • Docker 23.0.5
  • Run the RabbitMQ instance using following command:
    docker run -d --hostname auction-rabbit --name auction-rabbit-container -p 15672:15672 -p 5672:5672 rabbitmq:3-management

  • Run MySQL instance on localhost:3306 and set username and password accordingly in the properties file.

  • Now, create a database with name auction_db

  • Now run all the services security-service, cloud-config-server, cloud-gateway, security-service, auction-service in the exact sequence as mentioned.

  • Import API collection in PostMan using this link https://api.postman.com/collections/8756666-938eaa2d-ae47-460c-b58a-91d3b4f7536f?access_key=PMAT-01H2V28EZ0F2V2MC234HTF9Q2R

  • Register Users and authenticate them to get the JWT Token and add jwts with the request

  • Now you can start auctions, start bidding on them and get running auctions by status.

Architecture

Microservices

alt text

Workflow

alt text

REST APIs

POST /auction/

URL: http://localhost:9002/auction/

Request Parameters
Request Body: itemCode, basePrice, stepRate, duration

Response
Response Body: auctionId

GET /auction/?status=RUNNING

URL: http://localhost:9191/auction/?status={RUNNING/OVER}

Request Parameters
Query Parameters: status(running/over)

Response
Response Body: list of auctions

POST /auction/{itemCode}/bid

URL: http://localhost:9191/auction/{itemCode}/bid

Request Parameters
Path Variable: itemCode
Request Body: bidAmount

Response
Response Status:
201 - Bid is accepted
404 - Auction not found
406 - Bid is rejected

ER Diagram

alt text

Problems Resolutions

⭐ Auction Closing

Problem: Close auction as soon as duration ends and produce winner email message from auction service using a messaging queue because only security service has the capability to send email to users

Possible Solutions

1. MongoDB + Kafka

Using Mongo db and kafka together and set ttl to so that when auction duration ends it will be deleted from database and send message to kafka to send email message to email service

Reason to Reject: This approach will delete the auction from database once the duration ends

2. RabbitMQ

Passing messages to RabbitMQ with delayed execution parameter so that it initiates when auction is over

Reason to Reject: Auctions can last for hours and storing messages in message broker is not a good practice

3. AWS Lambda + RabbitMQ

Using lambda delayed execution and RabbitMQ together so that when ends lambda will start its operation make necessary changes in the database and send message to RabbitMQ to send winner email.

Reason to Reject:

4. Async + RabbitMQ

Executing asynchronous threads that will wait till auction duration ends and then close the auction and send message to RabbitMQ to send winner email.

Reason to reject: Closing the program will terminate all the asynchronous threads that are waiting to close their corresponding auctions.

5. Spring Scheduler + RabbitMQ

Scheduling a job every 20 sec to close all the running auctions that are expired and send message to rabbitmq to send winner email. In this approach, situation might occur where auction duration has ended but still the status is Running so to cop up with that we can add an additional condition in bidding service to check if the auction has expired or not.If the auction is expired no bid can be placed against this auction.

Reason to Accept: Every auction will be closed sooner or later even if one job fails next job will compensate. Additional condition will prevent users to bid on an expired auction even if it is not closed.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published