Skip to main content

Software That's Different for Every Customer

CJ Cummings
Creator and maintainer of Stof, co-founder & CEO of Limitr

For as long as most of us have written software, it has meant one build for everyone. Customers could change settings, toggle features, and pick a plan, but the logic underneath was the same for all of them. If a customer needed something different, it became a feature flag, an if on their customer ID, or a ticket.

That made sense when code was expensive to write. It isn't anymore. A model can draft a rule, a filter, or a pricing term in seconds. So the interesting question isn't whether we can write a different version of the logic for each customer. It's whether we can trust running it.

It's already happening​

Look at any B2B product with real customers and you'll find logic that's different per customer, already:

  • Pricing. Every enterprise contract is custom: a discount past some volume, a free tier that resets on a different day, a cap that only one customer has.
  • Rules and workflows. Approval rules, routing, scoring, alerts. Each customer wants them a little different.
  • Agent tools. An agent working for one customer needs tools that fit that customer's data and limits.
  • Automations users build. Every "when this happens, do that" a user sets up is a small program.

Today we handle these with flags, config that slowly grows conditionals, a homegrown rules engine, or a fork. Each one works until there are a few hundred customers, and then it's the part of the codebase nobody wants to touch.

Writing the code isn't the hard part​

If a model can write each customer's logic, what's left is everything around it:

  1. Where does it run? Not a container per customer. It has to run inside your app, on every request, fast.
  2. What can it touch? Only what you hand it. Not your files, network, or other customers' data.
  3. How do you check it? Before it ships, against the cases that matter, not by reading it and hoping.
  4. How does a person review it? A diff a person can read in a minute, not a pull request into your main codebase.
  5. How does it change? Your product keeps moving, and every customer's logic has to keep working with it.

None of these are about writing code. They're about trust, and they're why per-customer logic has stayed a pile of if statements.

The shape that works​

Not everything should be different per customer. Most of your app is the same for everyone, and it should stay that way. The shape that works is a stable core you wrote and trust, with per-customer edges that are written on demand, checked, and run in a sandbox.

The edges are where customers actually differ: their pricing terms, their rules, their tools. And each edge wants three things in one place:

  • The customer's data: their plan, limits, and state.
  • The logic for that data: their rules, as functions.
  • The checks: the shape the data must have, and tests for what the logic must do.

That's a document. Not a program in your repo and not rows in a database, but a self-contained unit you can version, diff, review, check, and run anywhere.

A customer, as a document​

This is what Stof is for. Here's one customer's pricing, with a term only they have, and the contract written as a test. Press Run:

acme.stofPlayground ↗
// acme.stof: Acme's pricing. One document per customer.
plan: {
  rate: 0.02         // per unit
  included: 1000     // free units each month
}

// Only Acme has this one. A model drafted it from their contract.
fn discount(units: int) -> float {
  units > 50_000 ? 0.2 : 0
}

fn price(units: int) -> float {
  const billable = units - self.plan.included;
  if (billable <= 0) return 0;
  billable * self.plan.rate * (1 - self.discount(units))
}

#[test]
fn contract_terms() {
  assert_eq(self.price(800), 0);
  assert_eq(self.price(5_000), 80);
  assert_eq(self.price(60_000), 944);
}

#[main]
fn main() {
  pln(self.price(5_000));
  pln(self.price(60_000));
}
Output

Your app loads it, hands it only the functions it may call, and calls price on every request, in-process:

const doc = await StofDoc.new(acme);
doc.setMaxExecutionTime(50); // ms
const total = await doc.call('price', units);

When Acme renegotiates, a model drafts the change and a person reviews this:

fn discount(units: int) -> float {
- units > 50_000 ? 0.2 : 0
+ units > 50_000 ? 0.3 : 0
}

stof test acme.stof fails until the contract test is updated to match, so the new terms can't ship by accident. No deploy, and no other customer is affected.

This isn't hypothetical. It's how Limitr works: every customer's pricing is a Stof document, evaluated in-process on every call.

What's still hard​

Individualized software has real problems, and a runtime doesn't make them disappear. Here's how they look, and what helps:

  • Every customer can have a different bug. You need to reproduce exactly what one customer ran. A Stof document runs the same in the browser, on a server, and on your laptop, so you can export a customer's document (bstf keeps the functions) and run it locally.
  • The core changes, and the edges have to keep up. Types and schemas live in the document, so you can check every customer's document against the new shape before you ship the core, and fix the ones that fail first.
  • Deciding what each edge may do. This becomes part of the product. A document starts with no access. You give it narrow functions, not permissions, and you can seal your engine and confine code you didn't write to exactly what it needs.
  • Not everything should be individualized. Your own application code, heavy compute, and long-running services belong in your main language. Hand them to documents as functions.

Where this goes​

Software has been one build for everyone because writing it was expensive. That constraint is going away, and the products that win will fit each customer instead of making every customer fit them. Getting there takes a place for per-customer logic to live where it can be written by a model, read by a person, checked before it runs, and run safely by your app.

That's what we built Stof to be. Try it in the playground, or read how to run logic you didn't write. Questions or ideas? Find us on Discord or GitHub.