Replicator
Replicator is a container you run in your own infrastructure. It holds a connection to Schematic’s datastream, loads all of your flag, company, and user data into a Redis instance you host, and keeps that copy current in real time. Backend SDKs in Replicator mode then evaluate flags from Redis without calling the Schematic API, so flag checks stay fast and keep working if Schematic is unreachable.
Setting it up takes three pieces:
- A Redis instance (single node or cluster) that both the Replicator and your application can reach.
- The Replicator container, configured with your Schematic API key and Redis address.
- Your backend SDK, configured for Replicator mode and pointed at the same Redis. See your SDK’s page: Go, Node.js, Python, Java, C#, or Ruby.
Image
The Replicator is published as a multi-architecture image (linux/amd64 and linux/arm64) to two registries:
Quick start
The Replicator exits at startup if it cannot connect to Redis, so make sure Redis is reachable from the container first. It also needs outbound HTTPS access to two hosts:
api.schematichq.com, for the initial load of companies and users.datastream.schematichq.com, for the datastream WebSocket (wss://).
Use a secret (backend) API key for SCHEMATIC_API_KEY, and the key for the environment whose data you want replicated. Store it in your platform’s secret manager rather than in plain configuration.
Deployment
One writer per Redis
Exactly one Replicator instance may write to a given Redis. A second writer would double-write the cache and corrupt the cursor the Replicator uses to resume after a reconnect.
The Replicator enforces this with a lease in Redis. An instance acquires the lease at startup, renews it while it runs, and releases it on shutdown. A crashed instance’s lease expires after WRITER_LOCK_TTL (15 seconds by default) so a replacement can take over.
A starting instance that finds the lease held waits up to WRITER_LOCK_ACQUIRE_TIMEOUT (5 minutes by default) for it to be released, then exits with an error. While it waits, /health returns 200. /ready returns 200 if Redis already holds a complete cache for the instance’s cache version, and 503 otherwise (see Health checks). In practice:
- Run one replica per Redis.
- Use a deployment strategy that stops the old instance before or while the new one waits. On Kubernetes, use
strategy: Recreate. The defaultRollingUpdatewaits for the new pod to become ready before stopping the old one. A waiting pod is ready only when the cache version is unchanged, so after an upgrade that changes the cache version, the new pod never becomes ready while the old pod holds the lease. - On platforms that drain and stop the old task once the new one passes a liveness check (for example, Amazon ECS with a load balancer health check on
/health), a rolling deploy hands the lease over within the acquire timeout. - For high availability, run Redis in a highly available configuration and let your orchestrator restart a failed Replicator promptly. Do not run several Replicators against the same Redis.
- To run more than one Replicator, for example one per Schematic environment, give each its own Redis, or its own
REDIS_DBon a single-node Redis, and point each environment’s SDKs at the matching one. ChangingWRITER_LOCK_KEYdoes not separate them: every Replicator writes the sameschematic:keys, so two Replicators in one Redis database overwrite each other’s data.
Docker Compose
Runs the Replicator alongside a Redis instance:
Kubernetes
The readiness probe keeps the pod in its Service only while /ready returns 200, which it does once the cache is complete. SDKs read Redis directly and reach the Replicator only to poll /ready, so the probe decides whether those polls get through. A pod that loses its datastream connection stays ready, because Redis still holds a complete cache.
Add resource requests and limits based on the usage you observe. Memory use grows with the number of companies and users, and with the buffer sizes in Performance tuning.
Health checks
The ready field in both responses carries the same value. It becomes true once the Replicator has written the full set of flags and finished loading companies and users. In the default asynchronous loading mode the datastream connects first and companies and users load in the background (see Initial load and reconnects), so /ready returns 503 until that background load finishes.
Once ready is true, it stays true while the datastream is disconnected, including through a Schematic outage, and while the Replicator reloads its cache, because Redis still holds a complete copy. The Replicator records each completed load in Redis under schematic:datastream:load_complete, tagged with the cache version. A restarted Replicator reads that record before it waits for the writer lease, so on a complete cache it reports ready right away. After an upgrade that changes the cache version, it reports not ready until it completes a load for the new version.
Both endpoints return the same JSON shape:
connected and components.datastream report the datastream connection on both endpoints, separately from ready. components.datastream is connected, disconnected, or unknown (still starting, for example while waiting for the writer lease). status is always healthy and components.redis is always connected; use the status code and ready, not these fields, to judge health. cache_version is an 8-character hash that forms the version segment of the Redis keys the Replicator writes (see Redis key layout).
The image has no HTTP client installed. For a container-level health check, use the binary’s built-in probe, which exits 0 when the endpoint returns 200 and respects HEALTH_PORT:
How SDKs use readiness
Backend SDKs in Replicator mode poll the Replicator’s /ready endpoint, every 30 seconds by default, and read ready and cache_version from the response body, including the body of a 503. Until the SDK has seen ready: true, and after it sees ready: false, single and bulk flag checks skip Redis and call the Schematic API, falling back to your flag defaults if that call fails. Once the cache is ready, flag checks evaluate from Redis, and a flag missing from Redis still falls back to the API.
Only an answer from the Replicator changes the SDK’s readiness. A poll that cannot reach the Replicator, times out, or gets a body without a boolean ready keeps the readiness and cache_version from the last answer, so a Replicator restart does not move flag checks off a complete cache. Before the first answer, the cache counts as not ready. Because the SDK polls on an interval, it can start serving from Redis up to one interval after /ready first returns 200.
Credit checks in client lease mode follow the same rule: while the cache is not ready, they run as plain checks through the API and hold no credits. The readiness check needs Replicator 0.3.0 or later and these SDK versions or later. Earlier SDK versions can evaluate checks from Redis while the Replicator is still loading, and treat a company that has not loaded yet as unknown.
Flag checks are safe to call before the cache is ready, because they go to the API in the meantime. If your app should not take traffic until it can evaluate checks from Redis, have its own startup or readiness check wait until the Replicator’s /ready returns 200. Most SDKs also expose the readiness they use for checks. See the cache readiness section of your SDK’s page: Go, Node.js, Python, Java, C#, or Ruby.
Configuration
The Replicator is configured entirely through environment variables. Durations use Go’s format: 500ms, 45s, 30m, 1h30m.
Core
Redis
Writer lease
Initial load and reconnects
By default the Replicator loads all companies and users from the Schematic API in the background, so the datastream connects quickly. It saves its position in the datastream to Redis, so after a reconnect or a restart it resumes from the last message it processed instead of reloading everything. It resumes only when Redis also holds a completed load for the current cache version (see Health checks). A full reload happens on a first start against an empty Redis, after an upgrade that changes the cache version, after a start whose initial load did not finish, and when the saved position is too old to resume from.
Connection keepalive
The Replicator pings the datastream to keep the WebSocket open through load balancers and proxies with idle timeouts.
The defaults suit an idle timeout of 60 seconds, which is common for cloud load balancers. For a 30-second idle timeout, use WS_PING_INTERVAL=15s and WS_PONG_WAIT=25s. For 120 seconds or more, 50s and 60s reduce traffic.
Performance tuning
These control how updates from the datastream are batched and written to Redis. The defaults favor low latency and suit most deployments.
Starting points for different environments:
Smaller batches and shorter timeouts lower latency; larger ones raise throughput. Reduce channel sizes if memory is constrained; total buffering is roughly NUM_WORKERS × (COMPANY_CHANNEL_SIZE + USER_CHANNEL_SIZE).
While the circuit breaker is open, updates arriving from the datastream are dropped, not queued, so Redis falls behind. They are not lost for good: the Replicator’s saved position never moves past an update it failed to apply, so the next reconnect or restart replays them, and if too many build up it starts a full reload on its own. If you see Circuit breaker open, dropping in the logs, fix the Redis problem, then restart the Replicator to catch up immediately.
Tracing
The Replicator can export traces over OTLP to any compatible collector or backend, such as the OpenTelemetry Collector, Datadog, Jaeger, or Honeycomb. Tracing is off until an endpoint is set, and it uses the standard OpenTelemetry environment variables:
The Replicator emits one trace per batch of updates: a root span (replicate company, replicate user, or replicate flags) with a child span for each Redis write or delete. Every span carries replicator.entity and replicator.batch.size. A batch dropped because the circuit breaker is open is recorded as a failed span with replicator.circuit_breaker.open. All spans are sampled; configure sampling in your collector.
Redis key layout
The Replicator writes, and SDKs in Replicator mode read, these keys. <version> is the cache_version reported by /health.
The schematic: prefix is fixed. If your SDK’s Redis cache is configured with a different prefix, it will never find these keys and will silently fall back to calling the Schematic API. Leave the SDK’s prefix at its default.
Troubleshooting
The container exits immediately. Check the logs with docker logs schematic-replicator. The two most common causes are a missing SCHEMATIC_API_KEY and an unreachable Redis.
The container exits after a few minutes with “Could not acquire writer lock”. Another Replicator is holding the lease on this Redis. Make sure only one instance runs, and on Kubernetes use strategy: Recreate. See One writer per Redis.
/ready stays at 503. The Replicator has not completed a load for its cache version. Check the logs first: it may be waiting for the writer lease (see above), or still loading companies and users from api.schematichq.com. If components.datastream is disconnected, the API key is wrong or the container cannot reach datastream.schematichq.com over wss://.
The connection drops every 30 or 60 seconds. A load balancer or proxy is closing idle connections. Lower WS_PING_INTERVAL and WS_PONG_WAIT; see Connection keepalive.
Your SDK still calls the Schematic API. Confirm the SDK is in Replicator mode, can reach the Replicator’s /ready endpoint and gets ready: true from it, uses the same Redis, and uses the default key prefix. Set LOG_LEVEL=debug on the Replicator to log each batch it writes to Redis.