Decoupling software licensing from your application

Search almost any mature codebase for if (edition == "PRO") and you’ll find it in more places than anyone expected. In the UI. In the export service. In a background job someone wrote four years ago. In a hotfix with a comment that says “temporary”.

That’s licensing logic that grew organically, and it’s one of the most expensive kinds of technical debt, because it sits right where your revenue is. This post is for architects and developers who’d like to pull it out into one well-defined place.

Key takeaways

  • Embedded licensing scatters business rules through the code; centralized licensing keeps them in one service your application asks.
  • Your application should ask one question, “what may this customer use?”, and act on the answer.
  • Authentication, authorization and licensing are three separate concerns. Keep them apart.
  • A licensing API needs caching, signed responses and an offline story to be production-ready.
  • Decoupled licensing scales independently of your application and supports many products at once.

Embedded vs. centralized licensing

Before and after: three features each read a hard-coded plan table; after, they ask one entitlement component that validates against NetLicensing, where plans and prices live

 Embedded licensingCentralized licensing
Where the rules liveIn application code, often in many placesIn a licensing service
Changing a price or planCode change and releaseConfiguration change
Adding a licensing modelNew code paths everywhereA new rule in the service
Multiple productsEach product reinvents licensingOne service for all products
VisibilityHard to say who has whatOne record of every customer’s licenses
TestingEvery combination of edition and flagTest the entitlement check once

Embedded licensing is fine for a product sold once, in one way, that never changes. Most products stop being that product within their first year.

The one question your application should ask

A decoupled design reduces licensing to a simple contract. Your application sends an identifier for the customer, installation or tenant, and gets back what that customer may use: is the subscription active, until when, which features are on, how many seats or credits are left.

With NetLicensing that’s one HTTPS request:

curl --request POST \
  --header "Accept: application/json" \
  --header "Content-Type: application/x-www-form-urlencoded" \
  --user apiKey:YOUR_API_KEY \
  --data "productNumber=YOUR_PRODUCT_NUMBER" \
  https://go.netlicensing.io/core/v2/rest/licensee/CUSTOMER-123/validate

The response contains one entry per product module, for example a subscription entry with valid and expires, and a feature entry listing which features are enabled. Some models need extra parameters, numbered per module: a device fingerprint for node-locked licenses, a session to check out for floating licenses, or the credits used for pay-per-use.

Your application should ask exactly one licensing question: what may this customer use?

The important part is what your code doesn’t contain: prices, plan definitions, trial lengths or feature-to-edition mappings. Those live in the licensing service, where product managers can change them.

Separate authentication, authorization and licensing

These three get tangled more often than any other concerns in a business application:

ConcernQuestionTypical owner
AuthenticationWho is this user?Your identity provider (SSO, OAuth, login)
AuthorizationWhat may this user do in this account?Roles and permissions, managed by the customer’s admin
LicensingWhat has this account paid for?Your licensing service, driven by purchases and contracts

A request passes authentication, authorization and a licensing check before a feature is used

A request passes all three: the user is authenticated, has the right role, and the account is entitled to the feature. Keeping them separate means a role change never accidentally grants a paid feature, and a plan change never breaks someone’s permissions. We cover the entitlement side in more depth in Entitlement-Based Access Control.

Best practices for a licensing integration

Wrap the check in one place. Create a small entitlement component in your application, for example entitlements.isEnabled("advanced-reporting"), and let everything else call that. When something changes, you change one class.

Cache with the TTL. Don’t call the licensing API on every page view or function call. NetLicensing returns a ttl with every validation; reuse the result until then. Your application stays fast and short network outages go unnoticed. In SaaS, discard the cached result when a tenant upgrades, so the new plan applies immediately.

Use the right credentials. Never ship your account password. Use API keys, and for keys inside client software, use the narrowest role, which can validate and little else. Server-side code can use a role with more rights to create customers and licenses from your sign-up flow.

Sign the response. On a machine you don’t control, someone could redirect the API host to a fake server. With response signing, each response is signed with your private key and the client library checks it with the public key built into your application.

Have an outage policy. If the service can’t be reached, keep working from the cached result while it’s valid. After that, decide: a grace period, read-only mode or a prompt to reconnect. NetLicensing also provides a backup host name in case DNS fails.

React to events. Licensing changes happen outside your application: a purchase, a renewal, an expiring license. Webhook notifications tell your systems when to clear a cache or send an email.

Multiple products and platforms

One of the biggest wins of decoupling shows up when you have more than one product, or one product on several platforms. A desktop app, a web app and a mobile companion can all ask the same licensing service about the same customer. A suite of products can be managed in one account, sold through one shop and packaged into bundles.

NetLicensing has client libraries for common languages, including Java, C#, PHP, JavaScript and Python. And because it’s a plain REST API, anything that can make an HTTPS call can integrate.

Offline agents and local validation

Decoupling doesn’t have to mean “always online”. The same contract works with a local decision point:

  • Cached results cover hours or days without a connection.
  • Signed offline files let a single machine validate locally for as long as the file is valid.
  • A local agent inside the customer’s network answers the same API calls as the cloud. Your application only changes its base URL.

The offline validation guide explains each option. Our post on monetizing offline and on-premises software covers the business side.

Scaling licensing independently

A licensing check sits on the hot path of your application. When it’s embedded, it scales with your code, shares your database and goes down with your deployments. When it’s decoupled and cached, your application makes one call per customer per TTL interval, and licensing load stays small and predictable however many requests your users make.

It also scales organizationally. Product managers change pricing without waiting for a release. Sales configures an enterprise deal without a custom build. Support sees each customer’s licensing state without reading code.

Questions people ask

What is licensing as a service? A hosted service that stores your products, licensing rules and customer licenses, and answers your application’s question “what may this customer use?” through an API.

What’s the difference between licensing and entitlement management? Licensing covers the rules and the commercial side: what’s sold, at what price, under what terms. Entitlement management covers the result: what a specific customer is entitled to right now. A licensing API typically delivers both.

Should I build my own licensing server? Only if licensing is core to what you sell. Otherwise you’ll be maintaining billing edge cases, offline support and security for years. We compared the options in Buy vs. Build.

Does a licensing API protect my code from cracking? No. It decides what’s licensed and can protect its own responses with signatures, but protecting the binary itself is a separate concern.

Start with one call

You don’t need to rewrite your application to decouple licensing. Start with one entitlement check in one place, back it with NetLicensing, and move the rest over feature by feature. The Getting Started guide gets you to a first validation quickly, and the free plan is enough to try it.

Happy Licensing!

Image Credits: NetLicensing