zero-cache package provides the server-side cache and sync engine that maintains a SQLite replica of your PostgreSQL database and handles real-time synchronization with clients.
Starting zero-cache
Command Line
Start the zero-cache server:Programmatic Usage
Configuration
Configure zero-cache via environment variables or command-line flags. All flags can be set using theZERO_ prefix.
Core Options
The upstream PostgreSQL database connection string.
The port for sync connections.
Unique identifier for the app. Multiple zero-cache apps can run on a single upstream database, each isolated with its own permissions and metadata.Must contain only lowercase letters, numbers, and underscores.
Replication Options
PostgreSQL publications that define the tables and columns to replicate. Publication names may not begin with an underscore.If unspecified, zero-cache creates an internal publication for all tables in the
public schema.File path to the SQLite replica that zero-cache maintains.
Performs a VACUUM at server startup if the specified number of hours has elapsed since the last VACUUM. The VACUUM operation requires double the database size in disk space.
Database Connections
Maximum number of connections to the upstream database for committing mutations. Divided evenly among sync workers.Must allow at least one connection per sync worker.
PostgreSQL database for storing CVRs (client view records). CVRs track data synced to clients to determine diffs on reconnect.If unspecified, uses
upstream-db.Maximum number of connections to the CVR database. Divided evenly among sync workers.
PostgreSQL database for storing recent replication log entries to sync multiple view-syncers without requiring multiple replication slots.If unspecified, uses
upstream-db.Performance Options
Number of processes to use for view syncing. Leave unset to use maximum available parallelism.Set to 0 to run as a replication-manager without sync workers.
Maximum time in milliseconds a sync worker spends in IVM before yielding to the event loop. Lower values increase responsiveness at the cost of reduced throughput.
Enable the query planner for optimizing ZQL queries. The query planner determines the most efficient join strategies.
CVR Garbage Collection
Duration after which an inactive CVR is eligible for garbage collection.
Initial interval for checking and garbage collecting inactive CVRs. Increased exponentially (up to 16 minutes) when nothing to purge.
Initial number of CVRs to purge per interval. Increased linearly if new CVRs exceed purged CVRs.Set to 0 to disable CVR garbage collection.
Rate Limiting
Maximum mutations per user within the specified window. If unset, no rate limiting is enforced.
Sliding window in milliseconds over which the mutation limit is enforced.
Multi-Node Setup
URI of the change-streamer. In multi-node setups, view-syncers should point to the replication-manager URI (runs on port 4849).
Alternative to
change-streamer-uri. Set to discover to connect to the IP address registered by the replication-manager.Ignored if change-streamer-uri is set.Port on which the change-streamer runs. Internal protocol between replication-manager and view-syncers.If unspecified, defaults to
port + 1.Development Options
Delay zero-cache startup until the first client connection. Useful for development.
Track and log the number of rows considered by slow query hydrations. Useful for debugging and performance tuning.
Globally unique identifier for the zero-cache instance. Useful for debugging.If unspecified, attempts to extract the TaskARN from AWS ECS or uses a random string.
Environment Variables
All command-line flags can be set via environment variables with theZERO_ prefix:
Production Deployment
For production deployments:- Set explicit database connections for
upstream-db,cvr-db, andchange-db - Configure rate limiting with
per-user-mutation-limit-max - Enable CVR garbage collection with appropriate thresholds
- Set connection pool sizes based on your workload
- Use a persistent volume for
replica-file - Configure multi-node setup if running multiple instances