Docs menu

You're reading the docs for dotwire 0.4. The latest release is 0.5. Upgrading? See Upgrading to 0.5.

Configuration

dotwire reads standard .NET configuration. As environment variables, replace each : with __, so Dotwire:Sse:Enabled becomes Dotwire__Sse__Enabled. For local runs with dotnet run, dotwire also loads a .env file.

Options without a default must be set. dotwire refuses to start if a required option is missing or invalid.

Connection strings

KeyDescription
ConnectionStrings:PostgresMigratorOwner role (dotwire). Used to run migrations and apply startup retention.
ConnectionStrings:PostgresWriteRuntime role (dotwire_app) for writes.
ConnectionStrings:PostgresReadRuntime role for reads, including authorization checks and history. Can point at a replica.

Postgres

KeyDefaultDescription
Postgres:MigratetrueRun the embedded migrations at startup. Set it on one node only.
Postgres:AppRolePassword—Password that the migration run sets for the dotwire_app role.

Auth

See Auth. Set Auth:Keys, Auth:JwksUrl, or both.

KeyDefaultDescription
Auth:IssuerRequiredExpected iss claim.
Auth:AudienceRequiredExpected aud claim.
Auth:Keys:<kid>—PEM-encoded RSA public key for key id <kid>, at least 2048 bits. Repeat for each key. A private key fails startup.
Auth:JwksUrl—JWKS endpoint to fetch public keys from. Must be https or a loopback host.
Auth:JwksRefreshMinutes5JWKS cache refresh interval.
Auth:AllowInsecureJwksUrlfalseAllow a plain http JWKS URL on a non-loopback host.
Auth:ClockSkewSeconds30Tolerance for exp, and for iat in the future.
Auth:MaxTokenLifetimeMinutes60Tokens with exp - iat above this are rejected. 0 disables the cap.

Node

KeyDefaultDescription
Dotwire:RoleAllAll, Api, or Gateway. See Node roles.
Dotwire:MaxContentBytes65536Maximum message content size in UTF-8 bytes.
Dotwire:MaxRequestBodyBytes262144Maximum request body size. Larger requests get 413.
Dotwire:MaxConnectionsPerUser100Hub plus SSE connections per user on one node. Above it, a hub connection is refused and SSE answers 429. 0 disables the cap.
Dotwire:MembershipSweepSeconds60How often each gateway re-checks live subscriptions against current roles and membership. 0 disables the sweep. See Rooms and membership.
Dotwire:HubSend:EnabledfalseLets members send over the hub with Send, on All and Gateway nodes. See Hub events.
Dotwire:AuthBatching:EnabledfalseGroups concurrent REST room authorization lookups into one database query. Who is allowed does not change. Opt-in. See "Tuning REST auth batching" below the Node table.
Dotwire:AuthBatching:MaxInFlight2How many batched auth queries one node runs at the same time. 1 to 64. A smaller number groups more requests.
Dotwire:AuthBatching:MaxBatchSize512Most lookups in one batched query. 1 to 4096.
Dotwire:AuthCacheSeconds0Keeps an allowed REST auth decision for this many seconds on each node. 0 turns the cache off, the maximum is 60. A revoked user can keep REST access for up to this long if a revocation message is lost or the database is edited directly. Keep it as low as your load allows.
Dotwire:DisableDebugLoggingfalseRaises the default log level to Warning, which drops Trace, Debug and Information logs. Logging costs CPU under load.
Dotwire:DisableAllLoggingfalseTurns all logging off, including warnings and errors. Wins over DisableDebugLogging.

Blank values in a .env file or in compose.yaml use the default, so an old .env with empty entries still starts. Values outside the stated ranges stop startup.

Tuning REST auth batching

By default every REST request checks the user's role and room membership with one database query. With batching on, requests that arrive while the node is busy share a query.

How the limit works. Dotwire:AuthBatching:MaxInFlight is how many of those queries can run at once. A request only joins a group when every slot is busy and it has to wait. With a small limit, requests often wait, so they are grouped and the database does less work. With a large limit, a request nearly always finds a free slot, goes alone, and nothing is grouped.

Which value to use

SituationSetting
Light or normal trafficLeave batching off. It makes no difference.
Steady heavy traffic and a fast databaseBatching on with MaxInFlight=2. At around 5,000 requests per second with sub-millisecond lookups only about 2 to 3 lookups run at once, so a higher limit would rarely group anything.
Hundreds of simultaneous requestsBatching on. It beat batching off at every level tried.
Slow database, for example on another networkTry MaxInFlight between 8 and 16. This is reasoning, not a measurement: each query takes longer, so a small limit would make requests wait too long.

Why the default is 2 and batching is off. The default follows the steady-load benchmark, where batching only engages with a small limit. Batching stays opt-in because it only pays off under load.

What local tests showed. These were short single runs on one laptop, with the app, Postgres, NATS and the load generator on the same machine, against a read-only room route. Treat them as a rough guide, not a benchmark.

Concurrent clientsResult
8 and 32No real difference between off and MaxInFlight=16. MaxInFlight=2 was as good or slightly better.
128MaxInFlight=16 gave about 44% more requests per second than off.
512About 63% more requests per second.
1024About 38% more. Replies took around half a second with or without batching, which points at the 100-connection read pool, not at batching.

MaxInFlight=2 was not compared at 128 clients and above. Run your own load, ideally with 2 and 16 side by side, before relying on either number.

Recommended settings by scenario

Pick the row that matches your expected traffic. No benchmarking is needed. Change only what your row says. Values marked untested are guidance, not benchmark results.

ScenarioSet
Local development, or most apps: up to about 100 concurrent REST clients and a few thousand messages per secondDefaults. Nothing else. The v0.4.1 benchmark reached about 7.5k messages per second with none lost, before batching existed.
Production, single nodeCors__AllowedOrigins__0, the real AllowedHosts, TLS in front, a short Auth__MaxTokenLifetimeMinutes such as 15, and Dotwire__DisableDebugLogging=true.
About 100 to 1,000 concurrent REST clientsDotwire__AuthBatching__Enabled=true. The default compose read pool (Maximum Pool Size=100) is enough. Keep MaxInFlight=2; try 8 to 16 only if the database is on another network (untested).
1,000+ concurrent REST clientsBatching on, plus a larger Maximum Pool Size on PostgresRead, for example 200 (untested), with Postgres max_connections above all pools combined.
Read-heavy, delayed revocation is acceptableDotwire__AuthCacheSeconds of 1 to 5 (untested range). A revoked user can keep REST access that long if a revocation message is lost. The node's NATS user needs subscribe permission on room.*.ephemeral.revoked.
Load testingRaise Dotwire__RateLimits__Send__PermitLimit and TokensPerPeriod so the per-user limit is not what you measure. Keep rate limits on in production.
Beyond one node: sustained above about 7,000 messages per second, or about 100,000 connectionsDotwire__Role=Gateway on socket nodes and Api on REST and admin nodes. Point the read pool at the primary or a synchronous replica if demotions must apply at once.
Compliance-strictDotwire__Retention__MessagesDays, managed here or through the admin API, not both. Dotwire__Encryption__AllowLegacyEnvelopes=false on new installs, or once no legacy rows remain. Archive audit_checkpoints off the database.
Agents and harnessesSSE is on by default. Raise Dotwire__Sse__BufferSize if consumers are disconnected as laggards.
Moderation webhooksSet Dotwire__Webhooks__Secret and use https URLs. Presend__FailPolicy=Closed if unmoderated content is unacceptable, Open if availability matters more. Size Presend__TimeoutMs to your endpoint's p99.

Keep these at their defaults in every scenario: Nats__RoomsSubjectFilter, NATS stream, subject and consumer names, the encryption keys, the AllowInsecure* switches, and the nofile, GC and socket backlog settings.

CORS and hosts

KeyDefaultDescription
Cors:AllowedOrigins:<n>EmptyBrowser origins allowed to call dotwire, for example Cors__AllowedOrigins__0=https://app.example.com. Empty allows any origin. Credentials are never allowed.
AllowedHosts*Host names dotwire answers to, separated by semicolons. Set it to your real host names in production.

Encryption

See Encryption and retention.

KeyDefaultDescription
Dotwire:Encryption:ActiveKeyIdRequiredKey id new messages are encrypted under. Must name a configured key.
Dotwire:Encryption:Keys:<id>RequiredBase64-encoded 32-byte AES key. Keep old ids configured after rotation.
Dotwire:Encryption:AllowLegacyEnvelopestrueDecrypt messages written before 0.3, which use the older envelope format. Set it to false once those rows have aged out.

Retention

KeyDefaultDescription
Dotwire:Retention:MessagesDaysUnsetPostgres history retention in days, applied at startup by the node that runs migrations. Unset leaves the value last set through the admin API. Manage retention here or through the API, not both.

JetStream retention is Nats:RoomsMaxAgeHours, below.

Webhooks

See Moderation webhooks.

KeyDefaultDescription
Dotwire:Webhooks:SecretUnsetWhen set, both call-outs carry X-Dotwire-Timestamp, X-Dotwire-Signature-V2 and the legacy X-Dotwire-Signature. The host SDKs require it by default. See Signing.
Dotwire:Webhooks:AllowInsecureUrlsfalseAllow plain http webhook URLs on a non-loopback host.
Dotwire:Webhooks:Presend:UrlUnsetPresend call-out URL. Presend is off when unset.
Dotwire:Webhooks:Presend:TimeoutMs500How long dotwire waits for an answer.
Dotwire:Webhooks:Presend:FailPolicyClosedClosed fails the send with 503 presend_unavailable. Open accepts the original content.
Dotwire:Webhooks:Presend:IncludeAdminSendsfalseAlso run presend for admin message injection.
Dotwire:Webhooks:PostSend:UrlUnsetPostsend call-out URL. Postsend is off when unset.
Dotwire:Webhooks:PostSend:TimeoutMs2000Timeout per delivery attempt.
Dotwire:Webhooks:PostSend:MaxAttempts3Delivery attempts per message.
Dotwire:Webhooks:PostSend:QueueCapacity1000Queue size. When full, the newest item is dropped with a warning.
Dotwire:Webhooks:PostSend:MaxQueueBytes67108864Queue size in bytes (64 MiB). When exceeded, the newest item is dropped with a warning.
Dotwire:Webhooks:PostSend:IncludeAdminSendsfalseAlso run postsend for admin message injection.

SSE

See Stream room events.

KeyDefaultDescription
Dotwire:Sse:EnabledtrueWhen false, the events endpoint returns 404.
Dotwire:Sse:KeepAliveSeconds15Interval between keep-alive comments.
Dotwire:Sse:BufferSize256Events buffered per connection. A connection that falls further behind is closed.
Dotwire:Sse:ReplayPageSize100Rows per page when replaying history on resume.
Dotwire:Sse:MaxReplayRows1000Messages replayed per connection on resume. Past it, the stream ends and the client resumes again with Last-Event-ID.

Rate limits

See Rate limits. Each bucket has three settings: PermitLimit (bucket size), TokensPerPeriod (tokens added each period), and PeriodSeconds.

BucketKeyed byCoversPermitLimitTokensPerPeriodPeriodSeconds
Dotwire:RateLimits:SendUserMember message sends, over REST and hub Send2051
Dotwire:RateLimits:ReadUserHistory, participants, hub and SSE connects, /audit30101
Dotwire:RateLimits:AdminUserEvery /admin route200501
Dotwire:RateLimits:HubUserHub Subscribe and Unsubscribe30101
Dotwire:RateLimits:UnauthenticatedClient IPEvery request without a valid token100501

Dotwire:RateLimits:Enabled (default true) turns all buckets on or off. For example, Dotwire__RateLimits__Send__PermitLimit=40 doubles the send bucket.

NATS

KeyDefaultDescription
Nats:Urlnats://localhost:4222NATS server URL. Separate several URLs with commas. For an authenticated server, include the credentials: nats://<user>:<password>@host:4222. See Securing NATS.
Nats:EnabledtrueProvision streams and run the NATS consumers at startup.
Nats:RoomsStreamROOMSJetStream stream for room messages.
Nats:RoomSubjectPrefixroom.Prefix of each room's subject, room.{roomId}.
Nats:RoomsSubjectFilterroom.*Subject filter of the rooms stream. Don't widen it to room.>; see Ephemeral traffic.
Nats:RoomLiveSubjectSuffix.liveSuffix of the core subject used for live fanout.
Nats:RoomsMaxAgeHours48How long the rooms stream keeps messages.
Nats:BatchMaxMessages500Postgres writer: maximum messages per batch.
Nats:BatchLingerMs1000Postgres writer: wait before flushing a partial batch.
Nats:PostgresWriterConsumerpostgres-writerDurable consumer name for the Postgres writer.
Nats:AuditStreamAUDITJetStream stream for audit events.
Nats:AuditSubjectaudit.eventsSubject for audit events.
Nats:AuditWriterConsumeraudit-writerDurable consumer name for the audit writer.
Nats:AuditWriter:BatchMaxMessages200Audit writer: maximum events per fetch.
Nats:AuditWriter:BatchLingerMs1000Audit writer: wait before flushing a partial batch.
Nats:AuditWriter:StandbyRetrySeconds5How often a standby node retries for the audit writer lock.

Runtime

compose.yaml sets these .NET runtime variables, which suit connection-dense workloads:

VariableValueEffect
DOTNET_gcServer1Server garbage collector.
DOTNET_GCDynamicAdaptationMode1Dynamic adaptation of the server GC (DATAS).