Fabriq
Reference

Configuration Reference

Exhaustive reference for the Fabriq Config struct, functional Options, environment variables, and validation rules.

This is the exhaustive reference for every Config field, functional Option, and FABRIQ_* environment variable. For the task-oriented walkthrough of how to assemble and pass configuration, see Getting Started · Configuration.

Config is Fabriq's declarative configuration: which stores exist and which projections run. It carries yaml and json struct tags (the same schema the fabriq binary loads from YAML). Entities are not configured here — they are registered in code via the registry.

type Config struct {
	Postgres      PostgresConfig
	Shards        []ShardConfig
	Redis         RedisConfig
	FalkorDB      FalkorDBConfig
	Elasticsearch ElasticsearchConfig
	Projections   ProjectionsConfig
	Subscriptions SubscriptionsConfig
}

PostgresConfig

Locates the source of truth. Required unless shards is set (a single postgres block is the one-shard shorthand). YAML/JSON key: postgres.

FieldTypeyaml/json keyDefaultMeaning
DSNstringdsn""Postgres connection string. Required when shards is empty (the single-shard case).
PoolSizeintpool_size0Connection pool size passed to the adapter via postgres.WithPoolSize. Zero leaves the adapter default.

ShardConfig

Locates one source-of-truth shard. YAML/JSON key: shards (a list). When shards is non-empty, tenants are routed across these shards and the top-level postgres block is ignored. See Sharding.

FieldTypeyaml/json keyDefaultMeaning
IDstringid""Stable shard identifier. Required and unique within shards.
DSNstringdsn""Postgres connection string for this shard. Required.
PoolSizeintpool_size0Connection pool size for this shard. Zero leaves the adapter default.

shards is a list of structs and cannot be set through the FABRIQ_* environment overlay — multi-shard deployments must mount a config.yaml, and the shard count is fixed at deploy time. See Sharding.

RedisConfig

Locates the event fan-out / cache store. YAML/JSON key: redis. Required when any projection is enabled and for live subscriptions.

FieldTypeyaml/json keyDefaultMeaning
Addrstringaddr""Redis address. Empty disables Redis (no live subscriptions, no projection event stream).
DBintdb0Redis logical database number.
Usernamestringusername""Redis ACL username.
Passwordstringpassword""Redis password.

FalkorDBConfig

Locates the graph projection engine. YAML/JSON key: falkordb. Required when projections.graph is enabled.

FieldTypeyaml/json keyDefaultMeaning
Addrstringaddr""FalkorDB address. Empty leaves Graph() returning ErrStoreNotConfigured.
Usernamestringusername""FalkorDB username.
Passwordstringpassword""FalkorDB password.

ElasticsearchConfig

Locates the search projection engine. YAML/JSON key: elasticsearch. Required when projections.search is enabled.

FieldTypeyaml/json keyDefaultMeaning
Addrs[]stringaddrsnilElasticsearch node addresses. Empty leaves Search() returning ErrStoreNotConfigured.
Usernamestringusername""Elasticsearch username.
Passwordstringpassword""Elasticsearch password.

ProjectionsConfig

Switches projection planes on. YAML/JSON key: projections.

FieldTypeyaml/json keyDefaultMeaning
GraphboolgraphfalseEnable the graph projection. Requires falkordb.addr and redis.addr.
SearchboolsearchfalseEnable the search projection. Requires elasticsearch.addrs and redis.addr.

SubscriptionsConfig

Tunes the delta plane. YAML/JSON key: subscriptions. Each non-zero field is translated into a functional Option by Config.Options() (see below).

FieldTypeyaml/json keyDefaultMeaning
ConflationWindowtime.Durationconflation_window0 (unset → option default 150ms)Hub last-write-wins flush window. When > 0, applied via WithConflationWindow. Must be >= 0 (validated).
StreamMaxLenint64stream_max_len0 (unset → option default 500)Approximate MAXLEN for per-channel Redis streams. When > 0, applied via WithStreamMaxLen; also passed to the Redis adapter as redis.WithChannelMaxLen.
SubscribeBufferintsubscribe_buffer0 (unset → option default 64)Per-subscriber delta buffer. When > 0, applied via WithSubscribeBuffer.

A zero value in SubscriptionsConfig means "leave the default". Config.Options() only emits an Option for a field that is strictly greater than zero, so the option defaults in defaultSettings() apply otherwise.

Functional Options

Option values customize a Fabriq and are passed to Open or New. They mutate the internal settings struct. Defaults below come from defaultSettings().

OptionSignatureDefaultEffect
WithConflationWindowWithConflationWindow(d time.Duration) Option150msTunes the hub's LWW flush window (spec range 100–250ms). Ignored when d <= 0.
WithSubscribeBufferWithSubscribeBuffer(n int) Option64Sets the per-subscriber delta buffer; full buffers drop (clients refetch + resume by Last-Event-ID). Ignored when n <= 0.
WithWaitPollIntervalWithWaitPollInterval(d time.Duration) Option25msTunes WaitForProjection's poll cadence. Ignored when d <= 0.
WithStreamMaxLenWithStreamMaxLen(n int64) Option500Approximate MAXLEN for per-channel Redis streams (catch-up depth before clients must refetch). Ignored when n <= 0.
WithAuthzWithAuthz(fn subscribe.AuthzFunc) OptionnoneInstalls the subscribe-time authorization hook.
WithDocumentAuthzWithDocumentAuthz(fn func(ctx context.Context, docID string) error) OptionnoneInstalls the document-plane authorization hook, consulted for both ApplyUpdate (writes) and SubscribeDocument (reads). Without it, any authenticated member of the tenant may touch any of the tenant's documents.
WithUpcastersWithUpcasters(chain *event.UpcasterChain) OptionnilRegisters the event payload upcaster chain. Projection engines apply it at decode, so appliers only see the latest payload shape.
WithTraceparentWithTraceparent(fn func(context.Context) string) Optionotel.TraceparentFromContextSupplies the W3C traceparent extractor stamped into event envelopes. Appended to the executor options.
WithClockWithClock(now func() time.Time) Optionsystem clockOverrides the command-plane clock (tests). Appended to the executor options.

withTailer is an internal option (wires the hub pump from the Redis transport) and is not part of the public Option surface — Open selects it automatically when redis.addr is set. By default the executor is configured with command.WithTraceparent(otel.TraceparentFromContext) so one trace spans command → outbox → relay → projection apply.

Environment Variables

The fabriq binary (cmd/fabriq) is environment-first: the deployment injects a secret plus configmap. The --dsn global flag overrides FABRIQ_POSTGRES_DSN for ad-hoc operator use.

VariableRead byDefaultMeaning
FABRIQ_POSTGRES_DSNserve + every operator commandnonePostgres DSN. Required to serve. Overridden by --dsn.
FABRIQ_REDIS_ADDRservenoneRedis address. Required to serve.
FABRIQ_FALKORDB_ADDRserve, rebuild, reconcile (inspect)""FalkorDB address. Optional: enables the graph projection.
FABRIQ_ELASTICSEARCH_ADDRSserve, rebuild, reconcile (inspect)""Comma-separated Elasticsearch addresses. Optional: enables the search projection.
FABRIQ_HTTP_ADDRserve:8081HTTP listen address for the worker (health, metrics).
FABRIQ_RECONCILE_INTERVALserve5mGo duration string for the reconcile loop cadence. "0" disables it. Unparseable values are ignored (default kept).

To serve, both FABRIQ_POSTGRES_DSN and FABRIQ_REDIS_ADDR must be set — the worker extension fails its start otherwise. Operator commands (migrate, inspect, rebuild, reconcile) need only the DSN (via --dsn or FABRIQ_POSTGRES_DSN), plus the relevant store flag/env for graph or search work.

Validation Rules

Config.Validate() checks cross-field consistency only — it does not dial any store. Open calls it before opening adapters. The rules:

  • postgres.dsn must be non-empty unless shards is set. When shards is set, every shard needs a non-empty, unique id and a non-empty dsn.
  • If projections.graph is enabled, falkordb.addr must be non-empty.
  • If projections.search is enabled, elasticsearch.addrs must be non-empty.
  • If either projection is enabled, redis.addr must be non-empty (projections need the event stream).
  • subscriptions.conflation_window must be >= 0.

Each failed rule returns a fmt.Errorf with a fabriq: config: ... prefix; none are typed sentinels.

On this page