You load-test the paths you already respect as load-bearing: the checkout, the login, the search box. Then there is the one call that decides whether the software is allowed to run at all — the license verification — and it almost never sees a load test. It works fine in development, where exactly one instance activates exactly once. The first time it meets real concurrency is in production, at the worst possible moment: a deploy or a restart brings the whole fleet back at once, every instance with a cold cache, all of them reaching for a license in the same two seconds.
A license check is a dependency call like any other, and the activation path has a capacity. This post puts it under load with k6, and the first job is to be precise about which part you are actually testing.
What is local, and what is on the wire
The common mistake is to picture every license check as a round-trip to a server. With Keyright it is not. The steady-state verification is a local operation: the SDK holds a signed license, and Validate() checks its signature against the embedded public key and reads its claims. No socket, no DNS, microseconds.
// Steady state: no network at all. Validate() checks the signature on the
// cached, signed license with the embedded public key, then reads claims.
LicenseInfo info = _client.Validate(licenseKey);
if (info.Status != LicenseStatus.Valid)
throw new LicenseException(info.Status); // fail closed
Load-testing that call is pointless — it is CPU-bound signature math with no shared resource to contend over. What touches the network, and therefore has a capacity you can exhaust, is two things:
- Activation. The first time an instance runs, or the first time after its cache is gone, it calls the issuing service to obtain a signed license for its machine identity. This is the expensive call, and it is the one that happens in a thundering herd after a deploy.
-
Refresh. On an interval the SDK revalidates, so a revocation or an entitlement change propagates. This is a conditional request — it sends the current version tag and usually gets back a cheap
304 Not Modified.
So the real load test is not "verify a license a million times." It is "what happens to the activation endpoint when 300 instances come back from a deploy at the same instant, and then settle into a steady hum of conditional refreshes."
The HTTP calls under test
Activation is a plain POST. The client sends the product it is activating, the license key, and a stable machine identity; it gets back a signed license document.
POST /v1/activate HTTP/1.1
Host: license.example.com
Content-Type: application/json
{ "productKey": "prod_designer", "licenseKey": "KR-7Q2F-...", "machineId": "a1b2c3d4" }
A refresh is a conditional GET. The client sends the version tag it already has; when nothing has changed it gets an empty-bodied 304, which is the whole point — a healthy fleet generates mostly 304s, not full license documents.
GET /v1/license/lic_8f3a HTTP/1.1
Host: license.example.com
If-None-Match: "v7-2026-11-01"
→ HTTP/1.1 304 Not Modified
Those are the two requests k6 will generate.
Modelling the activation storm
The default k6 executor holds a fixed number of virtual users, but that is not the shape of the risk here. The risk is a ramp: zero to a few hundred instances in seconds, as a rollout restarts the fleet. Use ramping-vus and make each virtual user a distinct machine coming online.
import http from 'k6/http';
import { check, sleep } from 'k6';
import { Trend, Rate } from 'k6/metrics';
const activateLatency = new Trend('activate_latency', true);
const activateFailed = new Rate('activate_failed');
export const options = {
scenarios: {
// A deploy brings the fleet back with a cold cache: everyone activates at once.
activation_storm: {
executor: 'ramping-vus',
startVUs: 0,
stages: [
{ duration: '30s', target: 300 }, // ramp to 300 concurrent clients
{ duration: '1m', target: 300 }, // hold the herd
{ duration: '30s', target: 0 }, // drain
],
},
},
thresholds: {
// Activation is on the critical path of a cold start. If p95 crosses
// 800ms, a fleet restart visibly stalls; fail the run if it does.
activate_latency: ['p(95)<800'],
activate_failed: ['rate<0.01'], // under 1% may fail under the storm
checks: ['rate>0.99'],
},
};
const BASE = __ENV.KEYRIGHT_URL; // e.g. https://license.staging.example.com
export default function () {
// Each VU/iteration is a distinct machine identity.
const machineId = `load-${__VU}-${__ITER}`;
const res = http.post(`${BASE}/v1/activate`, JSON.stringify({
productKey: __ENV.PRODUCT_KEY,
licenseKey: __ENV.LICENSE_KEY,
machineId,
}), { headers: { 'Content-Type': 'application/json' } });
activateLatency.add(res.timings.duration);
activateFailed.add(res.status !== 200);
check(res, {
'status is 200': (r) => r.status === 200,
'body is a signed license': (r) => {
try { return (JSON.parse(r.body).signature || '').length > 0; }
catch { return false; }
},
});
sleep(1);
}
Two details carry the weight. The check on the body matters because an activation endpoint under stress can return 200 with a truncated or error payload; counting only status codes would call a broken response a success. And the thresholds are the test: a k6 run with no thresholds just prints numbers, but thresholds make it pass or fail, which is what lets you wire it into CI and catch a regression before it ships.
Run it with the target and credentials in the environment, never baked into the script:
k6 run \
-e KEYRIGHT_URL=https://license.staging.example.com \
-e PRODUCT_KEY=prod_designer \
-e LICENSE_KEY=KR-7Q2F-TEST \
activation-storm.js
Exercising the cheap path too
A second scenario proves that steady-state refresh stays cheap. Here the interesting assertion is that most responses are 304 — if your fleet is paying for a full license document on every refresh, something upstream is not honouring the version tag, and that quietly multiplies your steady-state cost.
export function refresh() {
const res = http.get(`${BASE}/v1/license/${__ENV.LICENSE_ID}`, {
headers: { 'If-None-Match': __ENV.ETAG },
});
check(res, {
'not-modified fast path': (r) => r.status === 304,
});
}
Add it alongside the storm as a second scenario with a constant-arrival-rate executor, so it models a fixed request rate independent of how slow the responses get — which is exactly how a fleet of timers behaves.
Reading the result, and what it does not tell you
A green run means your deployment absorbs the herd within your latency budget and overwhelmingly serves refreshes from the 304 fast path. That is the number you want before the next big rollout.
Be honest about the limits.
- You are testing your deployment, not the verification math. The signature check is local and constant-time-ish; nothing you do in k6 stresses it. The capacity you are measuring belongs to the issuing service you stand up.
-
Abuse protection will fight your load generator, correctly. An activation endpoint worth deploying has rate-limiting and anti-abuse rules. A load test can trip them, and a
429is not a capacity failure — it is the service doing its job. Test against a staging deployment and a product configured with limits that let the run through, or you are measuring the rate-limiter, not the service. -
Re-activation should be idempotent, so model fresh machines. Activating the same
machineIdtwice should be cheap and must not consume a second seat. That is why the script derives a distinct identity per iteration — a load test that re-activates one machine measures the idempotent fast path, not the storm. - Never aim it at a shared or live service. Point it only at a deployment you own and can reset, with a dedicated test license. Keyright self-hosted Community Edition is enough to stand up a realistic target for this.
Takeaway
The license check is a load-bearing dependency, and the half of it that touches the network has a capacity like any other endpoint. k6 lets you find that capacity on your terms — modelling the synchronized cold-start burst that a deploy really causes, asserting on p95 and failure rate rather than eyeballing a graph, and confirming the refresh path stays on its cheap 304 lane. Do it once in staging and the next fleet-wide restart stops being the moment you discover the limit.
Top comments (0)