
Walk into almost any cafe or grocer near closing time and you will see it. A tray of unsold pastries, a crate of bruised fruit, a pan of prepared food that nobody bought, all heading for the bin. At the same time, on a busy Saturday, the same shop runs out of its best seller by lunchtime and turns customers away. Both of these are the same problem wearing two faces, and the answer to both is demand forecasting, which simply means using your own past sales to make a smart guess about how much you will sell tomorrow. This guide explains how it works in plain language, and then, for your developers, how to build a simple version step by step.
You do not need a data science team or expensive software to start. You already have the most valuable thing, which is your own sales history. The goal is to turn that history into a clear number each day: how much of each item to prepare or order, so you stock close to what you will actually sell.

Most cafes and small grocers decide how much to make or order based on a gut feeling and yesterday's numbers. That feels fine, but it quietly costs money in two directions at once.
When you prepare or buy more than you sell, the extra goes to waste. That is not just lost ingredients. It is the staff time to make it, the energy to store it, and cash that is now in the bin. For a tight margin business, a little waste every day adds up to a serious loss over a year.
The opposite hurts too. When you run out of a popular item, you lose the sale, and worse, you lose the customer who walked in for it and left empty handed. They may not come back. Empty shelves on your busiest day are some of the most expensive moments in the whole week.
The hard part is that guessing leaves you exposed on both sides. You can be wasteful and out of stock in the same day. A simple forecast narrows that gap.

Here is the whole idea in one breath. Look at how much of an item you sold on the same kind of day in the recent past, adjust for whether sales are trending up or down, and use that to suggest how much to make tomorrow. Add a small buffer so you rarely run out completely.
The key insight is that sales follow patterns. Saturdays are not Tuesdays. The start of the month may differ from the end. A rainy day is different from a sunny one. Your gut knows some of this, but a forecast applies it consistently to every item, every day, without forgetting. You do not need fancy AI to begin. A careful average by day of the week already beats guessing, and you can add smarter models later.
If you have a developer, here is a clear path. The examples use Python and PostgreSQL because they are a natural fit for working with data, but the same steps apply in any language.
Everything starts with your own data. Get the quantity sold per item per day from your sales table.
-- Daily quantity sold per item, the raw material for a forecast
SELECT item_id, sale_date::date AS day, SUM(quantity) AS qty
FROM sales
WHERE sale_date >= now() - interval '90 days'
GROUP BY item_id, sale_date::date
ORDER BY item_id, day;
The simplest possible forecast is "make the same as yesterday." It is a useful starting point, but it breaks quickly.
# Too simple: order the same as yesterday
def naive_forecast(history):
return history[-1] # ignores weekends, trends, and spikes
This fails because a quiet Tuesday cannot predict a busy Saturday. To do better, we need to respect the day of the week.
Average what you sold on the same weekday over the last several weeks. This single change captures most of the pattern in a cafe or shop.
import pandas as pd
def forecast_for(df, item_id, target_date):
# df has columns: item_id, day (date), qty
item = df[df["item_id"] == item_id].copy()
item["weekday"] = pd.to_datetime(item["day"]).dt.weekday
# Average sales for this weekday over the last several weeks
target_weekday = target_date.weekday()
same_weekday = item[item["weekday"] == target_weekday].tail(6) # last ~6 weeks
return round(same_weekday["qty"].mean())
Are sales drifting up or slowing down? Compare the last two weeks to the two before, and nudge the forecast in that direction. Then add a small buffer so you rarely sell out.
def suggested_quantity(df, item_id, target_date, buffer=0.1):
base = forecast_for(df, item_id, target_date)
item = df[df["item_id"] == item_id].sort_values("day")
last_two_weeks = item["qty"].tail(14).mean()
prev_two_weeks = item["qty"].tail(28).head(14).mean()
trend = (last_two_weeks / prev_two_weeks) if prev_two_weeks else 1
# Apply the trend, then a small buffer so you rarely run out
return round(base * trend * (1 + buffer))
Owners will only trust a forecast that has earned it. Compare past predictions to what actually sold, and track the average error so you can see it improve.
# How far off were the forecasts, on average?
def mean_abs_error(predictions, actuals):
errors = [abs(p - a) for p, a in zip(predictions, actuals)]
return round(sum(errors) / len(errors), 1)
A falling error number is the proof that the forecast is working, and it tells you when a fancier model is worth the effort.
A forecast is only useful if it reaches the people making decisions. Run it each evening and produce a simple prep or order list for the next day.
from datetime import date, timedelta
def build_prep_list(df, item_ids, target_date):
return [
{"item_id": item_id, "suggested_qty": suggested_quantity(df, item_id, target_date)}
for item_id in item_ids
]
tomorrow = date.today() + timedelta(days=1)
prep_list = build_prep_list(df, item_ids, tomorrow)
# Save it to a table, print it, or email it to the manager each evening
That is a working forecast in a handful of small functions. Start here, watch the accuracy, and only reach for AI models once the basics are paying off.
The code is the easy part. A few practical habits decide whether it actually helps.
Do not try to forecast every single product on day one. Begin with the ten or twenty items that make up most of your sales and most of your waste. You will get most of the benefit with a fraction of the effort.
Sales are shaped by things outside your sales table, like a heatwave, a local match, or a public holiday. Let staff adjust the suggested numbers up or down for known events. The forecast is a strong starting point, not a rigid rule.
The best setup pairs the forecast with the judgement of an experienced manager. The numbers handle the routine pattern, and the human handles the exceptions. Over time, as trust grows and accuracy improves, you can lean on the forecast more.
The payoff is direct and easy to feel. Less food in the bin means lower costs, week after week. Fewer stockouts on busy days means more sales and customers who leave happy. And your team spends less time agonising over how much to make, because a clear, trustworthy number is waiting for them each morning.
This is one of the clearest examples of modern technology smoothing a real business process. You are not chasing a trend. You are taking data you already create every day and turning it into less waste, steadier sales, and a healthier margin. For a cafe or grocer, that is a change you can measure in the bin and in the till.
Want to automate customer interactions without missing opportunities? An AI voice agent that answers your calls so you never miss a customer explores how AI voice agents can handle enquiries, qualify leads, and provide 24/7 support.
If you’re building AI-powered knowledge systems, How I Built an AI Document Assistant for a Client shares the architecture and lessons learned while creating a document search and retrieval assistant.
Curious about real-world AI deployments? How I Shipped Production-Ready AI Agents for a Client walks through the challenges, decisions, and best practices involved in moving AI agents from prototype to production.
Before implementing automation at scale, read Why Most AI Automation Pipelines Break in Production - The AI Workflows with n8n and OpenAI Architecture That Actually Works to understand common pitfalls and how to build reliable AI workflows.
Performance matters just as much as functionality. Why Most Next.js Apps Become Slow Over Time explains the architectural and development mistakes that gradually impact speed, scalability, and user experience.
If this maps to a problem in your business, tell me about it. I will tell you honestly whether software or AI can fix it, and how I would build it.

Every missed call can be a lost customer, and voicemail rarely gets returned. This guide explains how an AI voice agent answers every call, books appointments, and hands urgent calls to a human, plus how your developers can build one step by step.

A client's property team spent hours every day hunting through leases and policies to answer simple questions. Here is the real story, with full code, of how I built an AI document assistant that answers from their own files in seconds, with sources.

A client's support agent worked perfectly in the demo, then refunded three customers twice in its first week. Here is how I turned that flaky prototype into production-ready AI agents using idempotency, validation, guardrails, and full observability.