Skip to content

smart-developer1791/go-live-auction

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

🔨 Live Auction — Real-Time Auction Platform Built with Go and Server-Sent Events

A lightweight real-time auction web application written entirely in Go.
Live bids, countdown timers, and auction state changes are streamed instantly to all connected clients using Server-Sent Events (SSE) — no WebSockets, no databases, no external services.

Go SSE Tailwind CSS Render

This project demonstrates how to build a production-style real-time system in Go using only the standard library.
All auctions and bids are managed fully in-memory and synchronized across clients in real time.


🚀 Features

  • Real-time bidding powered by Server-Sent Events (SSE)
  • Instant bid propagation to all connected clients
  • Live countdown timers with server-side time synchronization
  • Automatic auction extension for last-minute bids
  • Automatic auction finalization and notifications
  • Minimum bid increment enforcement
  • Thread-safe auction engine (mutex-protected)
  • Modern, responsive Tailwind CSS UI
  • Toast notifications and live connection status
  • Zero external Go dependencies
  • No database, no message broker, no frameworks

🧱 Tech Stack

  • Go 1.21+
  • Standard library only (net/http, sync, time, etc.)
  • Server-Sent Events (SSE) for real-time updates
  • Tailwind CSS (via CDN)
  • Vanilla JavaScript frontend
  • In-memory application state

Pure Go backend.
Pure browser-native frontend.


📂 Project Structure

go-live-auction/
├── main.go                 # Go server, auction engine, SSE hub
├── templates/
│   └── index.html          # Tailwind UI + vanilla JS
├── render.yaml             # Render deployment configuration
├── go.mod
├── .gitignore
└── README.md

Clear separation between backend logic and frontend presentation.


▶️ Run Locally

go run .

Open your browser:

http://localhost:8080

Multiple browser tabs will stay perfectly synchronized in real time.


🌐 HTTP API

GET /

Serves the auction UI.

GET /api/auctions

Returns the current state of all auctions.

POST /api/bid

Places a bid on an auction.

{
  "auction_id": "auction-1",
  "bidder": "Alice",
  "amount": 250
}

GET /events

Server-Sent Events stream broadcasting:

  • initial — initial auction state
  • new_bid — new bid placed
  • auction_ended — auction completion
  • time_sync — server time synchronization

This endpoint keeps the HTTP connection open and continuously streams real-time updates to connected clients using Server-Sent Events (SSE).


⚠️ Note About cURL and Server-Sent Events (SSE)

When using curl with Server-Sent Events, output is buffered by default.
This means events will not appear immediately and may only be printed after the connection closes.

To receive SSE events in real time, disable output buffering using the -N (--no-buffer) flag:

curl -N http://localhost:8080/events

Without disabling buffering, Server-Sent Events will not stream properly in curl.

Browsers handle SSE correctly by default via the native EventSource API.


📡 Real-Time Architecture

  • Clients connect via browser-native EventSource
  • Each client receives a live event stream from /events
  • Auction state is managed centrally in memory
  • All updates are broadcast to connected clients instantly
  • Slow clients are skipped to avoid blocking
  • Automatic cleanup on client disconnect
  • Fully thread-safe using sync.RWMutex

This architecture scales cleanly for read-heavy real-time workloads.


🧠 Auction Rules

  • Minimum bid increment: $5.00
  • Bids placed in the final minute extend the auction by 30 seconds
  • Auction end is enforced server-side
  • All validation happens on the backend

Clients cannot cheat the system.


☁️ Deployment (Render)

The project is ready for one-click deployment on Render using the included render.yaml.

services:
  - type: web
    name: go-live-auction
    env: go
    plan: free
    buildCommand: |
      if [ ! -f go.mod ]; then
        go mod init live-auction
      fi
      go mod tidy
      go build -o live-auction .
    startCommand: ./live-auction

💡 Use Cases

  • Learning real-time systems in Go
  • Understanding SSE as a WebSocket alternative
  • Prototyping auction or bidding systems
  • MVP foundation for marketplaces
  • Teaching concurrency and state management

🔮 Ideas for Improvement

  • Persistent storage (PostgreSQL / Redis)
  • User authentication
  • Auction creation via API
  • Bid history per auction
  • Admin dashboard
  • WebSocket support (optional)
  • Docker support
  • Horizontal scaling with pub/sub

🚀 Deploy in 10 Seconds

Deploy to Render

About

Real-time auction platform built with Go and Server-Sent Events (SSE). Live bidding, countdown timers, and instant state synchronization — no WebSockets, no database, standard library only.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors