跳到正文
DEV Community· AppStruct·· 53 分鐘前AI 評分44

用純 JavaScript 建立九種情境的 SaaS 損益平衡檢查

Build a nine-scenario SaaS break-even check in plain JavaScript

AI 導讀

這篇教學以純 JavaScript 建立九種情境的 SaaS 損益平衡檢查,對照價格與每位用戶的變動成本。虛構基準情境設定為每月 40 位付費用戶、每位 $12 收費、$3 變動成本及 $180 固定成本,損益平衡點為 20 位用戶。程式以斷言檢查計算結果,但不驗證定價或需求。

正文

A single break-even result can hide how sensitive a small SaaS model is to price and service cost. Try a three-by-three comparison before treating one number as a target.

For a fictional monthly subscription, start with:

  • 40 paying users;
  • $12 price per user;
  • $3 variable cost per user;
  • $180 fixed monthly costs.

Contribution per user is $9, so 20 paying users cover the listed fixed costs. At 40 users, the operating result for those listed costs is $180.

Change price to $9.60 and variable cost to $3.60. Contribution falls to $6: the break-even target becomes 30 users, and the operating result at the same 40 users becomes $60. Neither scenario tells us how many people will accept the offer.

Disclosure: I work on AppStruct. This article was prepared with AI assistance; the runnable example below was executed and its assertions checked. All prices, costs and user counts are fictional teaching assumptions.

Keep the units explicit

The function accepts money as integer USD cents and user count as a whole number. It rejects fractional users, negative values and values beyond the stated bounds. Within these bounds, its largest monetary intermediate stays inside JavaScript's safe-integer range.

For a positive contribution, round the required user count upward. For zero or negative contribution, return null rather than a misleading target of zero users. With positive fixed costs, increasing user count cannot cover them when each additional user contributes nothing or loses money.

The comparison holds user count and fixed cost constant. It tries 80%, 100% and 120% of the base price against the same three levels of variable cost. Each adjusted amount rounds to cents before calculating the result.

Run the nine-scenario check

Save this as break-even-check.mjs and run node break-even-check.mjs. It uses Node's built-in assertion module; there are no packages, network calls, credentials or payment operations.

import assert from 'node:assert/strict';

function model({ users, priceCents, variableCents, fixedCents }) {
  for (const [name, value, max] of [
    ['users', users, 1_000_000],
    ['priceCents', priceCents, 10_000_000],
    ['variableCents', variableCents, 10_000_000],
    ['fixedCents', fixedCents, 10_000_000_000],
  ]) {
    if (!Number.isSafeInteger(value) || value < 0 || value > max) {
      throw new RangeError(`Invalid ${name}`);
    }
  }
  const contributionCents = priceCents - variableCents;
  return {
    contributionCents,
    operatingResultCents: users * contributionCents - fixedCents,
    breakEvenUsers: contributionCents > 0
      ? Math.ceil(fixedCents / contributionCents)
      : null,
  };
}

const base = { users: 40, priceCents: 1200, variableCents: 300, fixedCents: 18000 };
const scenarios = [80, 100, 120].flatMap(pricePercent =>
  [80, 100, 120].map(costPercent => {
    const priceCents = Math.round(base.priceCents * pricePercent / 100);
    const variableCents = Math.round(base.variableCents * costPercent / 100);
    return { priceCents, variableCents, ...model({ ...base, priceCents, variableCents }) };
  })
);

assert.deepEqual(model(base), {
  contributionCents: 900, operatingResultCents: 18000, breakEvenUsers: 20,
});
assert.deepEqual(scenarios.map(s => s.breakEvenUsers), [25, 28, 30, 19, 20, 22, 15, 16, 17]);
assert.equal(scenarios[2].operatingResultCents, 6000);
assert.equal(model({ ...base, priceCents: 300 }).breakEvenUsers, null);
assert.equal(model({ ...base, priceCents: 300 }).operatingResultCents, -18000);
assert.equal(model({ ...base, priceCents: 200 }).operatingResultCents, -22000);
assert.equal(model({ ...base, priceCents: 200 }).breakEvenUsers, null);
assert.equal(model({ ...base, fixedCents: 0 }).breakEvenUsers, 0);
assert.throws(() => model({ ...base, users: 1.5 }), RangeError);
assert.throws(() => model({ ...base, users: 1_000_001 }), RangeError);

console.table(scenarios);
console.log('Passed: 10 assertions over nine scenarios and boundary cases.');

The base scenario produces breakEvenUsers: 20. The lower-price, higher-cost scenario produces 30; the higher-price, lower-cost scenario produces 15.

The test also keeps a negative result negative and distinguishes two cases: zero fixed cost with positive contribution gives a zero target; nonpositive contribution gives an unavailable target under this model.

The assertions check this particular implementation and its chosen fixtures. They do not test a billing integration, validate a price or establish demand. Change one return value and confirm that a relevant assertion fails before reusing the exercise.

Reconcile the model with a spreadsheet

Build one row using price, variable cost, fixed cost and paying users. Keep the unit labels next to the inputs. For the base case, check $9 contribution per user, 20 break-even users and $180 operating result. Then set price equal to variable cost: the growth-based break-even target should become unavailable, and the result should be minus $180.

Public AppStruct Sheets example showing nine fictional monthly price and service-cost scenarios

Our free browser calculator and public nine-scenario Sheets example let you compare these values and download a CSV without entering an email. Creating and editing your own AppStruct workbook requires an account and applicable access. The published example is read-only; its exports contain calculated values, rather than the editable formulas in our source workbook.

Give the assumptions an owner

Record where each cost came from and when you checked it. Include acquisition, support work, payment fees, refunds and taxes in your own cost definitions where applicable. Initial development cost and cash collected from annual subscriptions need separate treatment; the monthly operating result above does not measure either.

If demand, churn or cost changes with user count, model that relationship explicitly. A fixed $3 per user is an assumption to investigate, not a promise that service cost stays linear. Testing nine combinations shows sensitivity to the two chosen inputs; it does not estimate the probability of any outcome.

Implementation references: Node strict assertions and JavaScript safe integers.

來源:DEV Community · dev.to