How I accidentally printed inflation in a Discord bot and redesigned betting odds

General News

Summary

The article describes how a Discord bot for parimutuel-style betting was built with Java 21, Spring Boot, JDA, PostgreSQL, and Flyway. It explains the payout logic, including commission handling, rounding rules, and preventing inflation bugs caused by floating-point calculations. It also walks through concurrency fixes such as pessimistic locking, unique constraints, transactional settlement, and recovery jobs for failed payouts. The author adds tests with Testcontainers and verifies that only one bet is accepted under concurrent clicks. The piece ends with deployment details, stack choices, and operational safeguards for running the bot reliably.

AskAI Classifications

Sectors
No sectors detected
Functions
No functions detected

Linked Companies