Skip to main content
2025-11-12

Building a Next Best Action Engine for SFMC Using DigitalOcean Droplets (via SFTP Integration)

2025-11-12

It was almost eight years ago — one of my first Salesforce Marketing Cloud (SFMC) projects — when I was asked to build an AMPscript email for a Next Best Action (NBA) campaign. Back then, AI wasn’t a buzzword, and “automation” basically meant a bunch of Python scripts someone had to run manually every week. 

The process was painfully manual: the data science team would crunch numbers, export a CSV with customer recommendations, and then hand it off to me for upload into SFMC. Only then could the platform send the “best” message to each person. It worked — sort of — but it always felt like there was something missing. 

That project stuck with me. The idea of Next Best Action — using data to decide what message each person should see next — has been spinning in the back of my mind ever since. I always wanted to build a smarter, automated, and more scalable version of it. Now, it’s finally time.

What is Next Best Action?

A Next Best Action model predicts the most relevant message, offer, or action for each customer at a given time. Instead of relying on static journeys or predefined rules (“if clicked, send discount”), NBA uses data and AI to evaluate multiple signals — such as email engagement, purchase behavior, and timing — to decide what should happen next. 

For example: 

  • A customer who opened three product emails but didn’t buy might get a personalized “compare features” message. 
  • Someone who clicked a discount link but didn’t complete checkout could get a reminder or product review email. 
  • A subscriber showing declining engagement — based on lower open and click rates — might be flagged by the model and routed into a re-engagement journey (sometimes called a churn-prevention flow) to win them back before they unsubscribe. 

This approach boosts engagement, improves conversion, and helps marketing teams move from campaign-centric to customer-centric communication.

Why Next Best Action Matters

At its core, Next Best Action (NBA) is about relevance. It’s about listening to what customers actually do — what they open, click, and buy — and using that to guide what happens next. Instead of blasting the same message to everyone, NBA helps you respond intelligently to each customer’s journey in real time. 

The beauty of it is that it turns marketing from a one-way broadcast into an ongoing, personalized dialogue. You’re not just asking, “What should we send next?” — you’re asking, “What does this person need next?”

Why File Drop

You might be wondering — why not just use APIs to move data between SFMC and the engine? The short answer: simplicity and cost

File drop (SFTP-based integration) may sound old-school, but it’s incredibly reliable, secure, and scalable for the type of data NBA needs to process. We’re talking about large datasets — engagement logs, product catalogs, and behavior history — which can easily reach hundreds of thousands of rows. 

Sending that much data over API calls every day would be both expensive and unnecessary. With file drops, we simply exchange CSVs once a day — predictable, auditable, and cost-efficient. 

It’s not fancy, but it’s the perfect match for high-volume marketing systems like SFMC, where automation and affordability matter more than real-time API calls.

Why Digital Ocean

Fast-forward to today, and we finally have the tools to make that early vision effortless. DigitalOcean provides a scalable, low-cost compute layer that can host AI models or data pipelines without the need for expensive servers or over-complicated infrastructure.

Why Digital Ocean

To be fair, there wasn’t a grand technical reason behind choosing DigitalOcean — it’s simply easier to work with. For quick testing, demos, and lightweight production use cases like this, DigitalOcean is refreshingly simple compared to larger clouds like Google Cloud or AWS. You spin up a droplet, drop in your scripts, and you’re up and running in minutes.

The Plan

Here’s what we set out to build: 

  1. Three Data Extensions in SFMC to act as the foundation of the NBA engine. 
  2. An AI-powered NBA engine running on a DigitalOcean Droplet, which analyzes these daily files, predicts the next best action for each contact, and sends the scored results back into SFMC. 
  3. An SFTP-based integration to keep everything simple, reliable, and cost-efficient — no APIs, no middleware, just clean file exchanges. 

By the end, we’d have a fully functional, affordable, and intelligent Next Best Action system for SFMC — built entirely with tools marketers and developers already use every day.

Phase 1: Setting Up SFMC

Before we touch Digital Ocean, we need to prepare Salesforce Marketing Cloud (SFMC) — the foundation of our Next Best Action setup. This phase is all about defining what data we’ll send out and what we expect to receive back from the NBA engine. When you think about NBA in marketing, the data always tells the story. So, let’s make sure SFMC is ready to tell it properly. 

Step 1: Create the Core Data Extensions and Automations

We’ll start by creating three main Data Extensions (DEs): 

Three main Data Extensions (DEs)

We’ll start by creating three main Data Extensions (DEs):

  • CustomerActivity_DE → captures how customers behave on the website — browsing, clicks, and purchases. 
  • EmailEngagement_DE → keeps track of how they interact with your emails — opens, clicks, and timing. 
  • ProductCatalog_DE → provides context about what they’re engaging with — all the products, categories, and prices. 

Each of these DEs will export daily via SFTP, becoming the engine’s “eyes and ears.” They help the AI understand who’s engaged, what they’re looking at, and what’s available to promote.

Data Extensions (DEs)

Once these exports are flowing, SFMC has everything it needs to tell the story — and Digital Ocean will soon become the part that listens, learns, and predicts.

Step 2: Receive and Store the AI Outputs

Once SFMC has shared its daily data with the NBA engine, the magic starts. The engine analyzes every click, view, and purchase, then sends four new files back to SFMC — each one built to drive smarter personalization. Here’s what comes back: 

  • ContactAffinity_DE → shows what each customer currently cares about most — the categories or products they’re “leaning toward.” 
  • ContactEngagement_DE → classifies engagement levels, from New to Active, Cooling, or Dormant. 
  • NBA_ActionScores_DE → scores every possible action (like product emails or category journeys) by predicted impact. 
  • NBA_Recommendations_DE → delivers the final “next best actions” — ready to plug directly into Journeys, Email Studio, or Decision Splits. 

These four outputs close the loop: SFMC sends raw behavior, and the AI returns clear, prioritized next steps — all through the same secure SFTP connection.

Receive and Store the AI Outputs

The files end up in our Import folder,

At this stage, SFMC becomes more than a marketing platform; it becomes the action layer of your AI system.

Phase 2: Building the Engine on Digital Ocean

With Salesforce Marketing Cloud (SFMC) ready to send and receive data, the next step was to bring the intelligence to life — to actually decide what each customer should see next. 

That’s where our NBA engine comes in. We deployed it on a small Digital Ocean Droplet, a lightweight cloud server that runs entirely on open-source Python. Every day, it connects to SFMC via SFTP, downloads the latest CSV exports, analyzes them, and pushes back the results — all automatically. 

At the heart of it lies a simple but powerful loop: 

  1. Read the data — the engine loads three CSV files from SFMC: 
  2. Blend it with business logic — the engine looks at an actions catalog, a small reference file that defines every possible journey or message type (for example, “re-engagement journey,” “cart recovery,” “price-drop alert”). 
  3. Decide the Next Best Action — using a mix of data science and configurable weights, the engine evaluates each customer’s intent and engagement level. It then scores which action makes the most sense at that moment — whether it’s sending a product recommendation, re-engagement email, or holding out entirely. 
  4. Generate recommendations — finally, it writes four output files: 

Everything happens inside a single script, with no manual triggers, no extra tools, and no APIs. It’s the marketing equivalent of a digital autopilot — always on, always learning, always optimizing who gets what next.

Building the Engine on Digital Ocean

And because it’s built on Open Source Python, the logic is completely transparent — you can see how decisions are made, retrain the model anytime, or even add your own business rules.

Phase 3: Automating the Workflow

Once everything is in place, the goal is simple — make it run on its own. No manual uploads, no waiting for someone to press a button. 

That’s where the automation loop comes in. Every day, at a scheduled time, the Digital Ocean droplet: 

  1. Connects securely to the SFMC SFTP 
  2. Downloads the latest CSV files — engagement, activity, and product catalog 
  3. Runs the Next Best Action engine to analyze patterns, predict behavior, and refresh recommendations 
  4. Uploads the updated results right back to SFMC — ready for use in email journeys, decision splits, and personalization 

The best part? It’s completely self-sustaining. If the model doesn’t exist yet, the engine automatically trains itself using the historical data. If it’s already trained, it just keeps learning from the new data — improving a little bit every day.

Automating the Workflow

What used to take a full team (data science, marketing ops, QA) can now happen quietly in the background. Every morning, SFMC wakes up to a fresh, data-driven set of next best actions — personalized, prioritized, and ready to send.

Phase 4: Bringing It All Together

With everything connected — SFMC, the NBA engine, and the automated file flow — the entire system runs quietly in the background, constantly learning from real customer behavior. Every click, open, and purchase becomes a signal. Every product viewed, every journey entered, every message skipped — it all feeds back into the model, helping it make slightly better decisions the next time around. 

The result? A marketing engine that actually listens. Instead of sending generic “catch-all” messages, your campaigns start to feel like real conversations — adapting to what each person is doing right now. No more guessing who should get what. 

No more endless journey branches or static rules. Just clean data in, intelligent recommendations out, and SFMC doing what it does best — delivering personalized, relevant experiences at scale. 

And the best part? It’s all powered by tools you already have: Salesforce Marketing Cloud, simple CSV exports, and an affordable cloud droplet on Digital Ocean. No APIs. No heavy integrations. No black-box AI. 

Just a smarter way to market — one prediction at a time.

Important Considerations

While the setup works beautifully in practice, there are a few things worth keeping in mind before bringing it into production: 

  • Data Quality Matters Most — The NBA engine is only as smart as the data you feed it. Make sure your email engagement and web activity feeds are clean, deduplicated, and refreshed daily. 
  • Start Simple, Then Scale — You don’t need every signal or channel on day one. Start with email + web behavior, prove value, then expand to SMS, push, or loyalty data later. 
  • Human Oversight is Key — The model can predict, but marketing still decides. Use the engine’s confidence scores to guide — not replace — your human intuition. 
  • Governance and Privacy — Ensure customer data stays secure. Since this solution runs outside of SFMC, align with your internal data protection and compliance policies. 
  • Tone = Strategy — Your choice of tone (Aggressive vs. Chill) impacts how assertively the model pushes actions. It’s not just a technical toggle — it’s a marketing philosophy.

Conclusion

What started years ago as a manual spreadsheet exercise is now a fully automated, intelligent marketing engine — one that reacts to customers in real time, learns from every engagement, and helps marketers focus on strategy instead of spreadsheets. 

This isn’t just a technical project. It’s a shift in mindset. A move from campaign-centric to customer-centric marketing — powered by simple, transparent AI. 

And the best part? You don’t need a data science team or enterprise AI budget to make it happen. Just good data, clear logic, and a little curiosity to experiment.

Want to Dive Deeper?

If you’re curious about the technical side — including the full Python code, data flow, and automation setup — I’ve published the complete project on GitHub: https://github.com/selimsevim/SFMC_NBA 

It includes the NBA engine script, orchestrator, and sample dataset structure so you can adapt it to your own SFMC setup.

Written by Selim Sevim