Configuration

Configure apps, adapters, cache, queues, rate limits, history, recovery, webhooks, and push notifications.

8 min read
View .mdEdit on GitHub

This page walks through the runtime shape of a Sockudo deployment: where app credentials live, how nodes fan out to each other, which shared stores carry state, and which protocol features are on. Read it before your first production deploy, or whenever you add a node, a backend, or a V2 feature. For TOML versus JSON, file discovery, --config, environment precedence, and secret placement, start with Static configuration. Every key is listed in the configuration reference.

How the pieces fit

Sockudo configuration should describe the runtime shape explicitly: app storage, fanout adapter, cache, queue, protocol features, security controls, metrics, webhooks, and push notification providers. Each top-level section owns one concern:

SectionOwnsSingle nodeMulti-node
[app_manager]App credentials and per-app policymemory is fineA shared database driver
[adapter]Cross-node fanout and cluster-wide countslocalA horizontal driver such as redis or nats
[cache]Idempotency claims, token revocations, coordinationmemoryredis or redis-cluster
[queue]Webhook and background jobsmemoryA broker-backed driver
[rate_limiter]HTTP API and WebSocket connect limitsmemoryredis
[connection_recovery], [history]Reconnect replay and durable historymemory history backendA shared history backend
[push]Push storage, queue, and workersMemory drivers in dev onlyDurable storage and queue
[database]Connection details the drivers above reuse

The rule of thumb: anything a second node must see (a claimed idempotency key, a revoked token, a replay position, a queued webhook) must live in a shared backend, not in process memory.

Minimal local config

A single process with one static app. Good for development and tests.

config.toml
port = 6001
host = "0.0.0.0"
debug = true
[app_manager]
driver = "memory"
[app_manager.array]
[[app_manager.array.apps]]
id = "app-id"
key = "app-key"
secret = "app-secret"
enabled = true
[app_manager.array.apps.policy.limits]
max_connections = 1000
[app_manager.array.apps.policy.features]
enable_client_messages = false

Production shape

Every node points at the same app database, adapter, cache, and queue. Metrics are served on a separate port so you can keep it off the public listener.

config.toml
port = 6001
host = "0.0.0.0"
debug = false
[app_manager]
driver = "pgsql"
[adapter]
driver = "redis"
[cache]
driver = "redis"
[queue]
driver = "redis"
[database.redis]
host = "redis"
port = 6379
[metrics]
enabled = true
host = "0.0.0.0"
port = 9601
[metrics.tcp_exporter]
enabled = false
host = "127.0.0.1"
port = 5000
buffer_size = 1024

[database.redis] is the Redis connection reused by the Redis adapter, cache, queue, and rate limiter. Sentinel, TLS, and Redis Cluster topology are covered in Redis connections, Sentinel, and TLS.

App manager

The app manager stores app credentials and app-level policy (limits, features, allowed origins, channel namespaces, webhooks). Memory is useful for local development; persistent managers are preferred for production because they let you add, rotate, and disable apps without a restart.

DriverUse when
memoryCredentials are static and local to one process.
pgsql (aliases postgres, postgresql) or mysqlYou need relational app records and standard operational tooling.
dynamodbYou run on AWS and want managed key-value storage.
scylladbYou need wide-column scale.
surrealdbYou use SurrealDB 4 for app metadata.
config.toml
[app_manager]
driver = "postgres"
# Close live connections of disabled/deleted apps (seconds, 0 = off).
availability_check_interval_seconds = 15
[app_manager.cache]
enabled = true
ttl = 300

The MySQL and PostgreSQL managers can encrypt app secrets at rest; see App secrets at rest. How disabling an app reaches live connections is covered in Disabling an app.

Adapter

The adapter controls cross-node fanout. When a publish lands on node A, the adapter carries it to every other node so each one can deliver to its own sockets. It also answers cluster-wide questions such as “how many sockets are subscribed to this channel”.

config.toml
[adapter]
driver = "redis"
enable_socket_counting = true
aggregate_counts = false
fast_presence_transitions = false
[adapter.redis]
prefix = "sockudo_adapter:"
requests_timeout = 5000
pubsub_ping_interval_ms = 10000

Use a shared adapter for every multi-node deployment. The local adapter is intentionally process-local: a second node never sees the first node’s publishes. Available drivers are local, redis, redis-cluster, nats, pulsar, rabbitmq, google-pubsub, kafka, iggy, and omq; see Scaling for how to choose.

pubsub_ping_interval_ms (under [adapter.redis] and [adapter.cluster], default 10000) is how often each node PINGs its Redis subscriber connection. A subscriber connection only reads, so when Redis goes away without closing it (a network partition, or a managed instance resized or replaced behind the same address) it would otherwise wait forever while publishing keeps working, and the node silently stops receiving events from its peers. When a PING fails or gets no answer within one interval, the node logs a warning, increments sockudo_horizontal_transport_reconnections_total, and resubscribes. Set it to 0 to disable the probe.

Redis Cluster broadcast bucketing

Without bucketing every broadcast is published to one channel, which hashes to a single slot and therefore a single shard primary. That primary carries the whole fleet’s broadcast egress.

broadcast_buckets (under [adapter.cluster], 1–64, default 3) splits each broadcast across that many channel variants, each pinned to a different slot range with a hash tag, and every node subscribes to exactly one bucket. Set it to the cluster’s shard count. Bucketing requires use_sharded_pubsub = true and a prefix without { or }; configure the same values on every node.

broadcast_mode sequences a live migration, one rollout at a time:

ModePublishes toSubscribes to
legacy (default)the single #broadcast channel#broadcast
publish_both#broadcast and every bucket#broadcast
subscribe_bucket#broadcast and every bucketthis node’s bucket
bucketedevery bucketthis node’s bucket

Any adjacent pair of modes delivers each broadcast exactly once to every node, so move legacy → publish_both → subscribe_bucket → bucketed and let each rollout finish fleet-wide before the next. To change broadcast_buckets, step back to publish_both, change the count, then move forward again. Both knobs have environment overrides, ADAPTER_CLUSTER_BROADCAST_MODE and ADAPTER_CLUSTER_BROADCAST_BUCKETS.

enable_socket_counting keeps the adapter’s request/reply socket-count path enabled by default. aggregate_counts is off by default; enable it when you want each node to maintain gossiped cluster-wide channel counts for local count reads. fast_presence_transitions is off by default. Enabling it uses the replicated presence registry for first-join and last-leave checks, which avoids request/reply fanout but makes presence webhook/history transition decisions eventually consistent.

For high-churn benchmark runs that should avoid distributed count fanout, use:

Terminal window
ADAPTER_ENABLE_SOCKET_COUNTING=false
ADAPTER_AGGREGATE_COUNTS=true
# Optional: enables eventual-consistency presence transition checks.
ADAPTER_FAST_PRESENCE_TRANSITIONS=true

Cache and queue

The cache holds short-lived shared state such as idempotency claims and capability-token revocations. The queue carries background work such as webhook delivery.

SectionDrivers
[cache]memory, redis, redis-cluster, none
[queue]memory, redis, redis-cluster, nats, pulsar, rabbitmq, google-pubsub, kafka, iggy, sqs, sns, none

Retry, lease, and dead-letter behavior for queue jobs lives under [queue.reliability]; see Queue v2 reliability.

Recovery and history

Sockudo keeps two separate stores for past messages. They answer different questions, so size and back them separately.

Hot replay bufferDurable history
Section[connection_recovery][history]
PurposeFill the gap after a short disconnectAPI reads, rewind, cold recovery, versioned messages, inspection
Lifetimebuffer_ttl_seconds (default 120)retention_window_seconds (default 86400)
Size boundmax_buffer_size messages per channel (default 100)max_messages_per_channel, max_bytes_per_channel
StorageIn processbackend: postgres, mysql, dynamodb, surrealdb, scylladb, or memory
config.toml
[connection_recovery]
enabled = true
buffer_ttl_seconds = 120
max_buffer_size = 100
[history]
enabled = true
backend = "postgres"
retention_window_seconds = 86400
max_messages_per_channel = 10000

Recovery buffers are for reconnect continuity. Durable history is for API reads, rewind, versioned messages, and operational inspection. Keep those concerns separate.

max_buffer_size bounds both the per-channel hot buffer and a single durable fallback replay, so a client that missed more than that many messages on one channel gets position_expired and must backfill from history. The full recovery model is in History and recovery.

Push notifications

Push is a core Sockudo subsystem. Configure it with a queue, provider credentials, retention, admission limits, and metrics before sending production traffic.

config.toml
[push]
storage_driver = "postgres"
queue_driver = "redis"
publish_status_ttl_days = 30
analytics_retention_days = 30
scheduler_interval_secs = 5
cleanup_interval_secs = 300
cleanup_batch_size = 1000
cleanup_max_deleted_per_tick = 100000
# Runtime env for FCM monolith workers:
# PUSH_FCM_ENABLED=true
# PUSH_FCM_SERVICE_ACCOUNT_JSON_PATH=/var/run/secrets/fcm-service-account.json
# PUSH_FCM_PROJECT_ID is optional when the service account JSON has project_id.
# Runtime env for APNs monolith workers (token auth):
# PUSH_APNS_ENABLED=true
# PUSH_APNS_TOPIC=com.example.app
# PUSH_APNS_TEAM_ID=ABCDE12345
# PUSH_APNS_KEY_ID=KEY123ABCD
# PUSH_APNS_PRIVATE_KEY_PATH=/var/run/secrets/apns-auth-key.p8

Both storage_driver and queue_driver default to memory, which is node-local and loses push state on restart. Production mode rejects memory push storage and queues unless allow_memory_drivers = true is set explicitly.

Use the queue backend for push fanout. Direct synchronous provider delivery is only suitable for tests and can hide production latency.

APNs token auth needs a team ID, a key ID, and the private key (PUSH_APNS_PRIVATE_KEY_PATH or PUSH_APNS_PRIVATE_KEY). Prefer the FCM service account JSON over PUSH_FCM_PROVIDER_TOKEN: a static provider token cannot be refreshed and is only suitable for short-lived legacy dispatch.

Channel push rules are top-level entries. They trigger the existing push pipeline after matching realtime publishes:

config.toml
[[push_rules]]
enabled = true
channel_pattern = "notifications:*"
event_filter = ["agent-complete"]
rate_limit_per_second = 100
[push_rules.payload_mapping]
title_field = "title"
body_field = "body"
template_data_field = "data"
include_remaining_fields = true

channel_pattern accepts an exact name, *, or a single trailing wildcard such as notifications:*, up to 256 bytes. The payload mapping values shown are the defaults. See Push notifications for providers, templates, and status.

Presence

config.toml
[presence]
max_members_per_channel = 100
max_member_size_in_kb = 2
update_rate_limit_per_member_per_second = 10
ungraceful_timeout_seconds = 0
v2_ungraceful_timeout_seconds = 15

ungraceful_timeout_seconds = 0 preserves Protocol V1/Pusher’s legacy immediate member_removed behavior. Protocol V2 defaults v2_ungraceful_timeout_seconds to 15, retaining presence through short abnormal disconnects without leave/enter flaps. Clean unsubscribe and clean WebSocket close remove presence immediately for both protocol versions.

Webhooks

Webhook endpoints are configured per app under policy.webhooks. The server-wide [webhooks] section controls timeouts, batching, and retries for every app:

config.toml
[webhooks]
request_timeout_ms = 10000
[webhooks.batching]
enabled = true
duration = 50
size = 100
[webhooks.retry]
enabled = true
max_attempts = 5
max_elapsed_time_ms = 300000
initial_backoff_ms = 1000
max_backoff_ms = 60000

batching.enabled defaults to true when omitted (the shipped config/config.toml sets it to false). batching.duration is the flush interval in milliseconds and batching.size the maximum events per request. Webhooks are delivered through [queue]; with queue.driver = "none" they are disabled.

Webhook consumers must validate signatures with the raw request body. Configure retry behavior and dead-letter visibility before relying on webhooks for workflows. Endpoint setup and payloads are in Webhooks.

Rate limits

The server-wide rate limiter has two buckets: signed HTTP API requests and new WebSocket connections. Each limit allows max_requests per window_seconds per client IP.

config.toml
[rate_limiter]
enabled = true
driver = "redis"
[rate_limiter.api_rate_limit]
max_requests = 100
window_seconds = 60
trust_hops = 0
[rate_limiter.websocket_rate_limit]
max_requests = 20
window_seconds = 60
trust_hops = 0

The values shown are the built-in defaults. trust_hops = 0 ignores forwarding headers and keys limits on the socket peer; behind a trusted proxy, set it as described in Rate limiter client IP. Per-app ceilings such as max_client_events_per_second and max_backend_events_per_second live under [app_manager.array.apps.policy.limits].

Keep limits close to product intent. A collaboration app, trading dashboard, and push-heavy mobile app need different ceilings.

Environment variables

Use environment variables for secrets and deployment-specific settings:

Terminal window
SOCKUDO_DEFAULT_APP_ID=app-id
SOCKUDO_DEFAULT_APP_KEY=app-key
SOCKUDO_DEFAULT_APP_SECRET=app-secret
REDIS_URL=redis://redis:6379/0
PUSH_FCM_PROJECT_ID=project-id
PUSH_FCM_SERVICE_ACCOUNT_JSON_PATH=/run/secrets/fcm-service-account.json

Avoid putting app secrets, encryption master keys, webhook secrets, and push provider credentials in committed config files.

Every runtime environment override is listed in the environment variable reference.

Next steps