Skip to main content
By default, the Node.js SDK and Sidecar store entitlements data in a local in-memory cache for fast and instant entitlement checks. If you restart the host process of the SDK or re-initialize the SDK, the local cache data will be lost. Usually, this behavior is acceptable because if the entitlements data is missing, the SDK will fetch it from the Stigg API over the network.
The in-memory cache is available only in the Node.js SDK and Sidecar. Other backend SDKs (Python, Ruby, Go, Java, .NET) perform direct API calls for every entitlement check and do not maintain a local cache.
Alternatively, you can provide an external store to persist the customer entitlements data which can survive restarts and be accessed by multiple processes. If your application is a fleet consisting of dozens of servers, or if you have a serverless infrastructure where each process is transient and can be de-provisioned after a limited period of time, a persistent cache can significantly reduce cache misses. Stigg offers a persistent cache setup for backend SDK users (currently supported in the Node SDK and Sidecar), providing several advantages over in-memory cache for high-scale services:
  • Redundancy - data is available on your Redis cluster even in case of an API outage
  • Low latency - including < 10ms credit balance retrieval via getCreditEntitlement()
  • Fewer requests from your services to the Stigg API
  • Reduce the memory footprint of the SDK in your services
  • Reducing cache coherence issues
  • Increased cache hits/misses ratio
To enable persistent cache in your environment, please contact the Stigg Support Team.

Overview

Stigg’s persistent cache relies on a running persistent-cache-service as part of your app deployment process. The service connects to a dedicated AWS SQS queue (owned and managed by Stigg), consumes messages that carry the state changes from the originating environment, and keeps your Redis cache instance with up-to-date data. The service can be scaled horizontally to keep up with the rate of arriving messages. In case of a cache miss, the SDK will fetch the data over the network directly from API, and update the cache to serve future requests.

Running the service

In order for the persistent cache to be updated properly in near real-time, you’ll need to install and run at least one instance of persistent-cache-service.
Version 3.0.0 breaking change: persistent-cache-service v3.0.0 introduces a new Redis data structure for credit entitlements. Once v3.0.0 writes data to Redis, older SDK/sidecar versions will return incorrect entitlement data.You must upgrade in this order:
  1. Upgrade @stigg/node-server-sdk to v4.12.1+ or sidecar-service to v5.194.5+
  2. Deploy all updated SDK/sidecar instances
  3. Only then deploy persistent-cache-service v3.0.0
See the persistent-cache-service changelog for details.

Prerequisites

  • An SQS provisioned by Stigg, to consume messages originating from your environment
  • Redis cluster to persist entitlements and usage for a future read operation

Usage

Run the service, replacing <tag> with the latest version in the ECR Public Gallery:
Starting from version 2.37.0, the service uses IAM role-based authentication for SQS access. AWS_ACCESS_KEY_ID and AWS_SECRET_ACCESS_KEY are no longer required - the service will automatically use the IAM role attached to the host (EC2 instance, ECS task, EKS pod, etc.).
Available options: *Required fields

Health

The service exposes the following HTTP endpoints:

GET /livez

Returns 200 if the service is alive. Healthy response: {"status":"UP"}

GET /readyz

Returns 200 if the service is ready to receive messages. Healthy response: { "status": "UP", "consumers": 10, "redis": "CONNECTED" } Unhealthy response: { "status": "DOWN", "consumers": 0, "redis": "DISCONNECTED" }

GET /metrics

Returns service metrics in Prometheus format. This endpoint includes both system-level and cache specific metrics. These metrics are helpful for monitoring the health and performance of the service.

Configure the SDK

To configure the SDK to use the Redis cache, provide the redis config during initialization:
Please make sure that the SDK and the persistent-cache-service are configured to use the same Redis instance, DB number, and the same environment prefix.
Disabling Redis expiration must be set on both sides. If you want cache entries to persist indefinitely (e.g. to keep serving entitlements through extended Stigg Cloud outages), the negative TTL must be configured on both the reader side and the writer side:
  • Node SDK: redis.ttl: -1
  • Sidecar: REDIS_KEYS_TTL_IN_SECS=-1
  • persistent-cache-service: KEYS_TTL_IN_SECS=-1
Both components write to Redis (the persistent-cache-service from SQS messages, the SDK/Sidecar on cache misses), so whichever writes a given key last decides whether it carries a TTL. Setting the negative value on only one side leaves the cache inconsistent — some entries will expire, others won’t. With expiration disabled, the persistent-cache-service pipeline remain responsible for keeping cache entries fresh.
During initialization, the SDK will try to connect to the Redis instance. Once connected, all the entitlement checks will be evaluated against data from the persistent cache instead of fetching it over the network. The persistent cache is updated the same way the in-memory cache does - if customer data is missing, it will be fetched over the network and persisted in the cache.

Deploying the Service in Kubernetes

You can install the Service using either helm or kustomize. For detailed instructions, resources, and examples, visit our GitHub repository.

Benchmarks

Based on internal benchmarks, a single instance of the persistent-cache-service runs efficiently with the following configuration:
  • CPU and memory: 1 vCPU and 512MB RAM.
  • CPU usage: Averages around 60%, with a range between 30% and 90% under constant load (i.e., when messages are consistently present in the queue).
  • Memory footprint: Approximately 250MB.
  • Throughput: Handles up to 100 messages per second, depending on message type and processing complexity.
  • Storage: Does not use any disk storage. The minimal container image size is sufficient.
  • Scalability: The service is stateless and can be horizontally scaled as needed to meet higher throughput demands.