zy1p's blog

Activation Code Licensing System Design (Part 2): Constraints & Code Generation

2 min read

Learn how to design activation code constraints that define license plans, and how to generate, manage, and enforce codes in a backend and portal system.

Contents

Introduction

Activation code constraints are the foundation of the licensing system.
They define the rules under which activation codes can be created and used.
From there, users generate codes that eventually bind to devices.

Activation Code Constraints

Definition

A constraint represents a license plan. It determines:

Examples:

Backend Enforcement

The backend enforces constraints by:

Portal UX

This ensures users clearly see what they can and cannot do.

Activation Code Generation

Process

  1. User selects a constraint in the portal.
  2. Frontend requests a new code from the backend.
  3. Backend checks validity:
    • Constraint is still active.
    • Code limit not reached.
  4. Backend creates a new row in activation_codes linked to the constraint.

Code Lifetime

Code Management

For example, a user with a 3-code plan may generate 2 codes. If they delete one, they can generate another, keeping total generated codes ≤ 3.

Abuse and Guardrails

Allowing deletion and regeneration makes the system flexible, but could be abused (e.g., cycling codes infinitely).
Simple guardrails include:

These measures increase fairness without complicating the user experience.

Design Justification