2024 • 5 min read

BizzGrow: Connecting Mobile POS
 to XGBoost Demand Forecasting

How I bridged everyday counter sales with on-demand inventory forecasting using Flutter, React, Firestore, Flask, and incremental XGBoost.

BizzGrow: Connecting Mobile POS to XGBoost Demand Forecasting

The Guesswork Dilemma

Most small grocery stores and food stalls in Indonesia manage inventory through guesswork. An owner orders three extra crates of cooking oil because last weekend felt busy, only to find the cash tied up in dead stock while bestselling snacks run out by Wednesday afternoon.

Enterprise supply chain software exists, but a neighborhood shop cannot afford dedicated database administrators or five-figure license fees.

For our Platform-Based Application capstone at Telkom University, I wanted to build an accessible alternative: BizzGrow. The platform connects a fast Flutter counter app on Android with a React back-office dashboard, synchronized through Cloud Firestore and backed by an incremental XGBoost forecasting service running on Flask.

Shop Counter (Flutter Mobile App)
               │
               ▼  Logs Sales & Deducts Stock
     Cloud Firestore (Real-Time Sync)
               │
               ▼  Fetches Daily History
       Flask REST API (Python)
               │
               ▼  Feature Engineering
        XGBoost Regressor
   (Incremental Warm-Start Fit)
               │
               ▼  Serves Day-by-Day Forecast
   Back Office Portal (React.js Web App)

The Data Leakage Trap in Sales Forecasting

When I first set up the XGBoost demand forecasting pipeline, I did what most developers do in introductory machine learning tutorials:

# Naive approach: Random train-test split
X_train, X_test, y_train, y_test = train_test_split(
    features, target, test_size=0.1, random_state=42
)

The model achieved an impressive R² score above 0.92. But when I checked the timestamps of the test set, rows from a Sunday were being used to evaluate predictions for the preceding Thursday.

In retail forecasting, you can never know the future. By shuffling transactions randomly, the model was essentially memorizing demand spikes across a given week instead of learning how to predict forward in time. It looked great on a test chart, but would fail completely in a real shop.

How do we simulate real retail conditions where the model must forecast tomorrow without seeing tomorrow’s data?

Chronological Sliding-Window Evaluation

To test the model honestly, I replaced random shuffling with a chronological sliding-window split.

I partitioned historical transactions so that the earliest 90% formed the training history, while the subsequent 10% remained strictly in the future:

Historical Transactions
─────────────────────────────────────────────► Time

|────────────── 90% ──────────────|─── 10% ───|
        Training History              Future Holdout

Evaluating on the holdout window dropped our nominal score slightly, but gave us a true indicator of forecasting performance.

The model was configured with:

from xgboost import XGBRegressor

model = XGBRegressor(
    n_estimators=500,
    learning_rate=0.05,
    max_depth=5,
    objective="reg:squarederror"
)

Feature engineering turned raw transaction logs into calendar signals: day of week, day of month, rolling 7-day average sales, and lag indicators from previous weeks.

How do we keep demand forecasts fresh when counter staff log new sales every twenty minutes without maxing out our server CPU?

Incremental Updates with Warm-Start Learning

In a busy shop, transactions occur throughout the day. If the Flask backend had to retrain all 500 decision trees from scratch on thousands of historical rows after every batch of sales, server response times would slow down and CPU usage would spike.

To solve this, I configured XGBoost’s incremental learning mechanism:

# Updating existing tree weights with recent transactions
model.fit(
    X_new_batch,
    y_new_batch,
    xgb_model=existing_model
)

By passing xgb_model=existing_model, the algorithm uses the existing tree structure as its baseline and updates weights based only on the new batch of rows. Updating on 20 to 50 new sales takes milliseconds rather than seconds.

The trade-off with warm starts is concept drift. If customer habits change radically over a month, an incrementally updated model can be slow to prune outdated splits. To balance this, we kept daily updates on warm start and scheduled a full clean retrain once a week during off-hours.

Real-Time Synchronization Across Counter and Back Office

A forecasting model is only useful if it sees up-to-date sales data.

Instead of setting up custom WebSocket servers, we used Cloud Firestore to link the mobile and web clients:

Cashier Rings Up Order (Flutter)
               │
               ▼ Writes new transaction doc
      Cloud Firestore
               │
               ├── Real-time snapshot triggers Flutter UI update
               └── Real-time snapshot triggers React back-office chart

When a cashier records a purchase on an Android phone, Firestore updates the product inventory document and pushes the delta to the React management portal in under 500 milliseconds.

When the manager opens the demand forecast tab on the web portal, React calls our Flask endpoint:

POST /predict
{
  "product_id": "PRD-COFFEE-01",
  "future_days": 7
}

Flask loads the active SKU model, projects the next seven calendar days, and returns an array of daily quantity estimates that render directly into a reordering schedule.

What I Learned

Building BizzGrow taught me that the hardest part of applied machine learning is rarely the algorithm itself. It is designing the pipeline around how data actually arrives.

Random splitting can trick you into thinking an ordinary model is brilliant when it is actually leaking future data. Switching to a chronological split and implementing incremental warm-start retraining made our predictions realistic and lightweight enough to run on modest hosting.

Most importantly, small business owners do not want abstract statistical metrics. They want a practical answer to a daily question: “How many units should I reorder before Thursday?” Making our architecture serve that simple operational need was the real engineering lesson.