Personal project
CricLot
Run private IPL-style cricket auctions with team budgets, live bidding, and separate screens for the host, the teams and a big display. The server is the only source of truth, and it pushes every update to every screen over WebSockets. End-to-end tests in CI cover the tricky rules, and it deploys with one command.
The problem
A live auction is only fun if everyone sees the same thing at the same moment.
In a private cricket auction, a host runs the room and each team bids for players with a fixed budget. The UI is not the hard part. Keeping everyone in sync is. Several people bid on the same player within milliseconds, a countdown is running, and three kinds of screen (host controls, team bidding and the big display) all have to agree on the current player, the top bid, each team's remaining budget and each squad's size.
Simple approaches break quickly. Timers in the browser drift apart, polling shows old data, and letting the browser decide anything leads to double bids, overspending and squads that are too big.
The approach
I made the server the single source of truth. Browsers never make important decisions. They send requests ("place bid", "start next player") and show whatever the server sends back. One process owns the timer, the current player, every budget and every squad.
- The server runs the auction. A state machine moves each player through the auction. The countdown resets on every valid bid, and only the server decides when a player is sold.
- Bids that can't clash. Every bid is checked against the team's budget, the minimum raise and the squad limit before it's accepted and saved. Two bids at almost the same moment can't break anything.
- Instant updates. A WebSocket hub pushes every change to every connected screen at once, so the host, team and display screens always match without a refresh.
Architecture
Key decisions
The timer lives on the server
Browsers only show the countdown the server sends. The real timer resets on every accepted bid, so last-second bids work the way players expect, and no two screens ever show a different time.
Check first, then broadcast
A bid is checked against budget, minimum raise and squad limit before it counts. Only accepted bids are saved and sent out, so an invalid bid never flashes up on other screens.
One message format for every screen
Host, team and display screens all listen to the same stream of updates and show the part they need. The protocol stays small, and adding a new kind of screen only needs front-end work.
The server decides who can do what
The server works out whether you are the host, a team or the display from a JWT or an access key. A read-only display can join without logging in, and host-only actions return 403 for a team key. The front end just hides buttons you could never use anyway.
One instance, on purpose
The timer and the WebSocket hub run inside one process. A second worker would split one live auction into two versions that disagree, so the deploy configs pin one instance and one worker. Scaling out would first need a shared timer and a message broker. I wrote that trade-off down instead of hiding it behind an autoscaler.
Tests that pass every time, not most of the time
Ending an auction used to cancel its timer tasks without waiting for them. A timer caught in the middle of a database query was still cleaning up when the event loop closed, and the end-to-end tests froze about half the time. Now the code waits for cancellation, shuts the test database down while its loop is still running, and reads WebSocket messages through a bounded queue. A missing message now fails the test instead of hanging it.
Delivery and testing
You can only trust a real-time system if its rules are tested, so the tricky parts are covered end to end:
- End-to-end tests. The full host flow, updates to many clients at once, timer resets and automatic selling, the budget, minimum raise and squad limit rules, and who is allowed to do what as host, team or display.
- WebSocket load test. 50 connections stay open, and each one gets every bid within about 5 ms (p50) and 16 ms (p95) of the first.
- CI on every push and pull request. The tests run on GitHub Actions, so timer and update bugs show up before merging.
- Easy to host. A Dockerfile, Fly and Railway configs for the API, and Vercel for the front end. Or run it on your home network or through a Cloudflare Tunnel for an auction in the living room.
Outcome
Measured with the included load test on a single instance, which is how the deploy configs run it.
- 5 / 16 msto update 50 screens, p50 / p95
- 3roles (host, team, display) checked on the server
- 0page refreshes needed, and money is stored in whole lakhs
Stack
FastAPINext.js 15WebSocketsSQLAlchemyTypeScriptJWTSQLite / PostgresDockerFly / RailwayVercelGitHub Actionspytest