Clavem

Should you build your own license server, or use a service?

Build your own if you sell one product with simple rules and already run a backend you trust. Use a service once you need device limits, subscriptions, refunds, downloads and self-service, because the work is in the edge cases, not the happy path.

A fair answer first

Building your own license server is a reasonable choice for some sellers. If you sell one product, charge once, do not limit devices and already run a small backend, a table of keys and one endpoint is enough. You control everything, there is no third party in the validation path, and nothing to migrate away from later.

The trouble starts when the rules grow. This article lists what is inside a license server, shows where it gets hard with a failure I reproduced, and then says when each choice fits.

What a license server contains

Each line below is something a buyer or a webhook eventually exercises. The effort and risk columns are my own judgement, not measurements: relative sizes from small to large, for one developer who has not done this before.

Component What it does Effort Risk if done badly
Key generation Random, unguessable, easy to read aloud Small Guessable keys, see license key security mistakes
Validate endpoint Look up a key, return status Small Trusting the wrong thing in the answer
Activation with a device limit Count devices atomically Medium Limit bypass under concurrent requests
Signed tokens Sign answers so apps can verify offline Medium Private key leak, no rotation plan
Rate limiting Slow down key guessing and abuse Small to medium Key enumeration, or lockout of honest users
Stripe fulfilment Verify webhooks, issue keys, deduplicate events Medium Duplicate or missing keys
Subscriptions and renewals Extend or expire on invoice.paid and status changes Medium Paying customers locked out, or lapsed customers kept
Refunds Disable keys on full refund Small Refunded keys keep working
Downloads Store files and gate them by license Medium Public links, no resume, storage costs
Email Deliver keys reliably Small to medium Keys land in spam, no resend
Buyer self-service Lost key, move to a new computer Medium Support load
Export and backup Get your data out Small Single copy of every key
Uptime and monitoring Stay up when launches and sales spikes happen Ongoing Every app that checks at launch fails at once

Most of these are individually small. The cost is that there are thirteen of them, and every buyer finds the one you skipped.

Where it gets hard: the activation race

The device limit looks simple: count the activations for this license, and if the count is under the limit, add one. That is two steps, and two requests can interleave. Both read a count of 2, both see “under 3”, and both insert. Now the license has 4 devices.

I tested this with Python and SQLite. Five devices activate one license at the same moment. The limit is 3. Each device does check, wait 50 ms, insert.

limit 3, 5 simultaneous activations
check then insert, no lock: 5 devices stored
begin immediate + check + insert: 3 devices stored

Without a lock, all five were stored. With the check and the insert inside one transaction that takes the write lock first, exactly three were. The 50 ms stands for the network and code between the two steps, and a real server has the same gap.

On Postgres, the same fix is to lock the license row inside a transaction. This is a sketch. I ran the SQLite version above, not this one:

begin;

-- Serialise concurrent activations of the same license.
select id, activation_limit
  from licenses where key = $1 for update;

-- Idempotent re-activation: the same device keeps its seat.
select id from instances
  where license_id = $2 and fingerprint = $3 and removed_at is null;

select count(*) from instances
  where license_id = $2 and removed_at is null;

-- Only if the count is below the limit and no seat matched:
insert into instances (license_id, name, fingerprint)
  values ($2, $4, $3) returning id;

commit;

Two things are easy to miss here. The lock must cover both the count and the insert. And you need the idempotent branch, or a buyer who reinstalls the app uses a second seat for the same computer.

The other places edge cases live

Webhooks arrive more than once and out of order. A correct fulfilment endpoint verifies the signature on the raw body, deduplicates by event id, and tolerates invoice.paid arriving before the license exists. See Stripe webhooks for license fulfilment.

Subscriptions have more states than paid and unpaid. past_due, unpaid, paused, canceled and a late renewal each need a decision, and a renewal that settles three days late should not lock someone out.

Signing keys have a lifecycle. You generate a key per product, keep the private half encrypted, ship the public half in the app and plan for the day you have to rotate it.

Installed apps outlive your server. Once an app with your hostname is on a thousand machines, moving the server means updating every one of them, or keeping the old hostname running for years.

What an afternoon gets you

The smallest useful server is a table of keys and one endpoint. In SQL and a handler:

create table licenses (
  id bigserial primary key,
  key text not null unique,
  email text not null,
  status text not null default 'active',  -- active, expired, disabled
  activation_limit int,                   -- null means unlimited
  expires_at timestamptz
);
app.post('/v1/licenses/validate', async (req, res) => {
  const row = await db.licenses.findByKey(String(req.body.license_key ?? '').trim().toUpperCase());
  if (!row) return res.status(404).json({ valid: false, error: 'license_key not found.' });
  const valid = row.status === 'active' && (!row.expires_at || row.expires_at > new Date());
  res.json({ valid, error: valid ? null : 'This license key is not valid.' });
});

That is enough for one product and no device limits. It also has everything this article warned about: an unsigned answer, no rate limit, no revocation hook, no Stripe link and no way for a buyer to fix anything alone. Treat it as a prototype. The decision is whether the next dozen features are worth building yourself.

A cost sketch with stated assumptions

The honest cost of building is your time, not the hosting. Here is the arithmetic, with assumptions you should replace with your own.

Assumption Value
Hours to build components 1 to 13 above, to a standard you would put in front of paying customers 60
Your hourly value $50
Hours per month of maintenance (Stripe API changes, a stuck webhook, a support thread about a lost key) 2
Price of the Clavem Indie plan, for comparison $29 a month

Building costs 60 × $50 = $3,000 up front, which equals about 103 months of the Indie plan. The ongoing 2 hours a month is $100, which already exceeds $29. On these numbers the service is cheaper for years. Change the inputs and the answer changes: if you value your hours at $10, or you already have most of the components in a backend you run, building wins. If you are a solo developer whose time goes to the product, the sum rarely favours building.

The calculation leaves out two things that cut in opposite directions: the risk of a bug in your own server that locks customers out, and the risk of depending on a vendor. Neither has a clean price.

When building is the right call

Your situation Build Use a service
One product, one-time price, no device limit Fits Works, but you may not need it
You already run a backend and database you trust Fits Optional
You need all licensing data inside your own infrastructure Fits Does not fit
Several products, device limits, subscriptions and downloads Possible, with a long list of work Fits
You are a solo developer and want to spend time on the product Rarely worth it Fits
You sell through Stripe and want refunds and renewals handled You write the webhook handlers Fits

Building also has a cost that does not show up until later: you are now running a service that every installed copy of your app depends on. If it is down at launch time, your customers see an error, and they email you, not your hosting provider.

What a service does not fix

A service does not remove the need to design what your app does when the network is down or a check fails. That logic lives in your app either way. Nor does it remove vendor risk. Lemon Squeezy’s announced shutdown on 31 March 2027 is a recent reminder that a vendor can disappear. The defence is portability: keys that verify offline, a plain export, and an API whose shape you can reproduce.

Doing this with Clavem

Clavem is the licensing and delivery layer for software sold through Stripe: key generation, activation with an atomic device limit, signed tokens, Stripe fulfilment, renewals and refunds, downloads, order pages, a buyer device page, CSV export and a management API. It is a flat monthly price with no cut of sales, and it does not handle tax or act as a merchant of record.

Two things make it safe to leave. Every token verifies offline with a public key you hold, so a license outlives the service. And the License API uses the paths and response shape of the Lemon Squeezy License API, so an app that calls it can be pointed at another server that implements the same shape, including your own. If you already have a homemade server, moving from a homegrown license server covers the import. The full comparison lists the trade-offs in more detail.

Questions

How hard is it to build a license server?

The first version, which generates keys and answers valid or not, is an afternoon of work. Device limits without race conditions, Stripe webhook handling, renewals, refunds, buyer self-service and signing key management are where the weeks go.

Is a homemade license server cheaper than a service?

The hosting is cheap. The cost is your time to build it, and your time every time Stripe, your app or an edge case changes. Count that time before comparing it with a monthly price.

Can I move from my own server to a service later?

Yes, if you keep the key strings, buyers, limits, expiry dates and activations in a plain export. Importing existing keys is routine. The harder part is updating the apps that are already installed.

Sources

  1. Lemon Squeezy migration documentation, shutdown date (as of November 2026)