Why We Moved Inventory and Balance Calculations Directly into the Database
Plain-language summary: In a busy retail store, letting a website screen calculate order totals and stock can cause mistakes when multiple cashiers sell items at the same time. This article explains how moving that math directly into the database guarantees accurate numbers every time.
When building the Perfect Traders point-of-sale system for retail and wholesale counter operations, the most critical decision was where to calculate money totals and inventory numbers.
The Problem with Doing Math in the Web Browser
In many simple websites, when a customer buys an item, the web page itself calculates the total, sends an update to change the stock, and figures out the customer's remaining balance. In a real shop with fast-paced counter sales or multiple open registers, this easily leads to mistakes. If the internet drops for two seconds, or two cashiers sell the last bag of rice at the exact same moment, the numbers in the system no longer match what is on the shelf.
Letting the Database Guard the Numbers
For the POS Shop, we moved all balance math and stock deductions directly into the database system (using PostgreSQL triggers in Supabase). When an order is entered, the database itself recalculates the cash collected, updates remaining customer credit, and deducts the inventory items in a single, protected step. Even if a cashier's browser window closes abruptly, the recorded numbers remain completely accurate.
If a business system cannot guarantee that stock counts and cash balances match reality, fancy screen animations will not help. The database must remain the single source of truth.
Instant Receipts without Monthly Storage Bills
Another practical choice was how to handle customer receipts. Instead of creating PDF files on a remote server and storing thousands of invoice files on expensive cloud storage, we programmed the web browser to build and format the receipt on demand using jsPDF. The receipt prints immediately at the counter, and the business pays zero monthly file-storage fees.
Custom software for local businesses works best when it is straightforward, durable, and inexpensive to run. Putting the core rules into the database and keeping the interface fast gave this store a dependable register that runs all day without hiccups.