Skip to content

putra4648/flashbid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

FlashBid

FlashBid is a high-concurrency bidding/auction server built with Go. It is designed to handle thousands of concurrent bids efficiently and accurately without data race issues. The system leverages RabbitMQ for asynchronous message queuing, Redis for distributed locking and caching, and PostgreSQL for persistent storage with row-level locking.

Architecture

  1. Fiber HTTP Server: Receives incoming bid requests (POST /api/bids) and immediately pushes them to a RabbitMQ queue. This ensures fast response times (HTTP 202 Accepted) and prevents the HTTP server from blocking during traffic spikes.
  2. RabbitMQ: Acts as a message broker to queue the incoming bids. It decouple the HTTP handlers from the actual database processing logic.
  3. Worker Service: Consumes messages from RabbitMQ one by one (configured via QoS prefetch count).
  4. Redis Distributed Lock: Before processing a bid for a specific item, the worker attempts to acquire a distributed lock in Redis to prevent multiple workers from processing bids for the same item concurrently.
  5. PostgreSQL & GORM: Executes a transaction to verify the current highest bid using a FOR UPDATE row-level lock. If the new bid is higher, it updates the database and caches the new highest bid back in Redis.

Tech Stack

  • Language: Go (Golang) 1.25.6
  • Web Framework: Fiber v3
  • Message Broker: RabbitMQ (amqp091-go)
  • Caching & Locking: Redis (go-redis/v9 and bsm/redislock)
  • Database: PostgreSQL (via GORM)
  • Load Testing: k6

Prerequisites

  • Go 1.25 or higher
  • PostgreSQL Server
  • Redis Server
  • RabbitMQ Server
  • k6 (for load testing)

How to Run

  1. Clone the repository and navigate into the directory.
  2. Ensure that PostgreSQL, Redis, and RabbitMQ are running and accessible. Note: You may need to update the connection strings in cmd/worker/main.go and internal/config/db.go to match your environment.
  3. Install dependencies:
    go mod tidy
  4. Run the worker and HTTP server:
    go run ./cmd/worker/main.go
  5. The API will be available at http://localhost:8080/api/bids.

Load Testing

This project includes a k6 script (script.js) to simulate a high-concurrency environment.

  1. Ensure your FlashBid server is running.
  2. Install k6.
  3. Run the load test:
    k6 run script.js

The script will simulate 10,000 virtual users making concurrent bids for 3 seconds.

About

Bidding system with Concurrency (usecase)

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors