Production Patterns

Production patterns for Highflame — singleton client, rollout stages (monitor→alert→enforce), graceful degradation, environment variables, logging, and a go-live checklist.

Recommended patterns for running Highflame Shield and ZeroID in production environments.

Client Initialization

Create one Highflame client per process and share it across requests. The client maintains an internal token cache and connection pool — creating a new instance per request wastes resources and loses token caching.

Python — module-level singleton:

# highflame_client.py
import os
from highflame import Highflame

_client: Highflame | None = None

def get_client() -> Highflame:
    global _client
    if _client is None:
        _client = Highflame(
            api_key=os.environ["HIGHFLAME_API_KEY"],
            account_id=os.environ.get("HIGHFLAME_ACCOUNT_ID"),
            project_id=os.environ.get("HIGHFLAME_PROJECT_ID"),
        )
    return _client

TypeScript — module-level singleton:

Async Context Managers

Use async context managers when you need guaranteed resource cleanup (connection pool teardown) at process shutdown:

Enforcement Rollout Strategy

Roll out enforcement in stages to avoid blocking legitimate traffic while policies are being tuned:

Stage 1 — Monitor: observe decisions without blocking. Review the observatory to understand what your traffic looks like.

Stage 2 — Alert: allow traffic but trigger your alerting pipeline on violations. Tune your response playbooks before enforcement.

Stage 3 — Enforce: block violations. Roll out to a subset of traffic first (canary), then expand.

Non-Blocking Guardrails in Critical Paths

If your latency budget cannot absorb a Shield call in the hot path, evaluate in the background and use the result asynchronously:

Graceful Degradation

When Shield is unavailable (network partition, service outage), decide whether to fail open or fail closed based on your risk tolerance:

For high-security applications, fail closed:

Environment Variable Reference

Configure the SDK through environment variables to keep credentials out of code:

Variable
Description

HIGHFLAME_API_KEY

Service key (hf_sk_...)

HIGHFLAME_ACCOUNT_ID

Account ID for multi-tenant setups

HIGHFLAME_PROJECT_ID

Project ID for multi-tenant setups

For self-hosted deployments, also configure:

Variable
Description

HIGHFLAME_BASE_URL

Guard service base URL

HIGHFLAME_TOKEN_URL

Token exchange endpoint URL

The Python SDK reads these automatically if you pass api_key=None:

Logging

The TypeScript SDK accepts a logger object with standard debug/info/warn methods:

Pass your existing logger (Winston, Pino, etc.) to route SDK logs through your application's logging pipeline.

Token Caching (ZeroID)

The Highflame SDK exchanges service keys for short-lived JWTs and caches them automatically. The cache refreshes 60 seconds before expiry (TOKEN_REFRESH_BUFFER_MS = 60_000). Concurrent requests share a single in-flight token exchange — there is no thundering-herd problem at startup.

For ZeroID clients, the same behavior applies: tokens.verify() fetches the JWKS once and caches the signing keys. The cache is invalidated when the JWKS rotates (detected via kid rotation).

Production Checklist

Last updated