AI & E-Commerce Automation Global / E-Commerce

The Predictive Replenishment Engine

Naturavest (Health & Wellness E-Commerce)

An event-driven WhatsApp retention engine that pre-computes product depletion dates at checkout and triggers hyper-personalized, 2-step re-engagement sequences via Meta WABA.

24/7
Automated retention
$5/mo
Hosting cost
0
Operational friction
100%
WABA deliverability
The Predictive Replenishment Engine - Architecture & Flow
System Flow & Infrastructure Visualization

The Challenge

The Silent Killer of E-Commerce: The "Empty Bottle" In the wellness industry, customer churn doesn’t happen because of a bad product. It happens because of bad timing. A customer buys a 30-day supply of premium supplements. Life gets busy. Thirty days pass, they run out, and their daily routine is broken. By the time they remember to reorder, they’ve already moved on to a competitor. Naturavest came to us with a deeply human problem: How do we reach through the noise of daily life and tap our customer on the shoulder at the exact right moment—before their habit breaks? They wanted to automate WhatsApp reminders, but they were hitting a wall. Basic automation tools couldn’t handle complex date math, and custom enterprise integrations were quoted at tens of thousands of dollars.

Our Solution

An Event-Driven "Pre-Compute" Architecture We didn’t just connect a messaging app to their store. We engineered a predictive backend system that calculates the exact depletion date of every single product a customer buys—and triggers a hyper-personalized WhatsApp sequence at the precise moment of need. Here is how we transformed their customer retention loop:

System Architecture & Deep Dive

1. The "Pre-Compute" Math Engine (The Innovation)

Most automation platforms try to hold thousands of orders in active memory for 60 days waiting to send a message. This crashes servers and costs a fortune in software subscriptions. Instead, we built a "Pre-Compute" engine. The exact millisecond a customer checks out on Shopify, our backend engine reads the product’s lifespan, calculates the exact future date the customer will run out, and writes that date back into the Shopify database. • Smart Multiplier Logic: If a customer buys a "Pack of 2", our script automatically multiplies the lifespan accordingly. • Zero Server Load: We calculate the future once, and forget it.

2. The Daily Oracle (Lightning-Fast Delivery)

Every morning at 8:00 AM, our custom n8n automation engine wakes up and asks Shopify a single, highly optimized question: "Who has a depletion date of today?" For the handful of customers whose time has come, the engine instantly fires off their personalized WhatsApp messages, then securely deletes the trigger so they are never spammed twice.

3. The Two-Step Psychological Sequence

We didn’t just send a "buy more" text. We designed a two-part retention sequence that touches the heart of the customer's journey: • Message 1 (The Pre-Runout Nudge): Sent 2 days before they run out. "Hi [Name], running low on [Product]? Don't let your routine slip." • Message 2 (The Post-Runout Re-engagement): Sent 2 days after they run out. "Hi [Name], we hope you enjoyed your [Product]! To maintain the best results, we recommend continuing without a break."

4. Hyper-Dynamic Media at Scale

WhatsApp requires strict, pre-approved templates to prevent spam. We navigated Meta’s complex WABA (WhatsApp Business API) compliance to build dynamic templates that inject: • The customer's first name. • The clean product name (automatically stripping messy SEO keywords from Shopify). • A dynamically fetched, high-resolution image of the exact product they bought. • A 1-tap "Reorder Now" button linking directly to the product page.

Technical Architecture (No SaaS Bloat)

We believe in decoupled architecture. We separated the "Brain" from the "Mouth." • The Brain: A self-hosted, open-source n8n engine running on a secure, dedicated cloud VPS. It handles all the logic, GraphQL API queries, and JavaScript date arithmetic. The Cost: Instead of paying $100+ per month for restrictive SaaS middleware like Zapier or Make, the client pays just $5/month for raw DigitalOcean cloud hosting. We own the infrastructure, giving us complete control, zero vendor lock-in, and enterprise-grade computing power for the price of a cup of coffee. • The Mouth: The official WhatsApp Business API via Messaging.digital, ensuring 100% deliverability and compliance.
Proven Results

The Business Impact

Passive Revenue Loop

Naturavest now has a 24/7 automated system that passively recovers revenue by catching customers right before they churn.

Zero Operational Friction

The Naturavest team never has to manually export CSVs, check dates, or send texts. The system is entirely invisible to them.

Infinite Scalability

Whether they have 4 products or 4,000, the system automatically fetches the correct images, links, and lifespans. They never have to touch the automation as they scale.

The Technology Stack

We engineered this solution using a decoupled, API-first architecture. By separating the logic engine from the data source and the messaging gateway, we built a system that is infinitely scalable, highly secure, and completely free of recurring SaaS middleware fees.

Data Source & State Management: Shopify Admin API

Utilized Custom Metafields to store product lifespans and calculated reminder dates directly on the Shopify order, leveraging Shopify as our system of record. Used Order Tags and Webhooks for real-time event triggering.

Backend Logic & Orchestration: n8n (Cloud-Hosted on DigitalOcean)

Replaced expensive, restrictive tools like Zapier with an open-source automation engine hosted on dedicated cloud infrastructure. Executed complex JavaScript (Node.js) for date arithmetic, string manipulation (regex), and JSON payload transformation.

API Communication Layer: GraphQL & REST

Fetching daily reminders via highly optimized GraphQL queries (filtering by tags to reduce API load). Safely appending and removing order tags via GraphQL Mutations (tagsAdd / tagsRemove) to prevent destructive REST API overwrites.

Messaging Gateway & Compliance: WhatsApp Business API (WABA) via Messaging.digital

Navigated strict Meta anti-spam compliance to design and deploy dynamic, pre-approved Message Templates. Orchestrated complex JSON payloads featuring dynamic image headers, variable body text, and 1-tap URL buttons.

Infrastructure & DevOps: DigitalOcean Droplet, Docker, Nginx

Deployed the automation engine on a secure DigitalOcean cloud VPS with SSL encryption, ensuring 24/7 uptime, high availability, and secure webhook transmission for just $5/month.

Want to build an automated retention engine? Stop letting your best customers silently run out of your products. We design custom, backend-grade automations that bridge the gap between your e-commerce platform and your customers' pockets.