Configuration
FCQRS starts from an embedded Akka.NET configuration and merges application configuration over it. This page lists the defaults, FCQRS runtime keys, persistence providers, and the settings required to move from one local process to a cluster.
Minimal configuration
Fcqrs.connect supplies the persistence provider and connection string. An empty IConfiguration
accepts the rest of the embedded defaults:
open FCQRS.FSharp
let connection = Fcqrs.connect FCQRS.Actor.DBType.Sqlite "Data Source=app.db;"
// An empty IConfiguration accepts the embedded Akka.NET defaults.
let config = Microsoft.Extensions.Configuration.ConfigurationBuilder().Build()
let loggerFactory = Microsoft.Extensions.Logging.LoggerFactory.Create(fun _ -> ())
let api = Fcqrs.actor config loggerFactory (Some connection) "MyCluster"
FCQRSFCQRS.FSharpIdiomatic-F# functional facade for FCQRS. Gives F# consumers the same one-call ergonomics the C# host-builder (HostExtensions.fs) gives C#, but with F# idioms: records-of-functions for the definitions, typed handles for the results, an explicit wiring pipeline, and plain helpers for saga side effects. It is a *pure addition* that wraps only the existing primitives (IActor.InitializeActor / SagaBuilder.initSimple / Query.init / InitializeSagaStarter / CreateCommandSubscription / Actor.api) and changes nothing in the C# interop layer or the core. open FCQRS.FSharp let api = Fcqrs.actor config loggerFactory (Some (Fcqrs.connect DBType.Sqlite conn)) "Cluster" let documents = Fcqrs.aggregate api { Name="Document"; Initial=...; Decide=...; Fold=... } let slugs = Fcqrs.aggregate api { Name="Slug"; Initial=...; Decide=...; Fold=... } let publication = Fcqrs.saga api (publicationDef documents.Factory slugs.Factory) Fcqrs.wireSagaStarters api [ publication ] let subs = Fcqrs.projection api (Projection.single 0 updateReadModel) // (Projection.multi when you must control which notifications publish) // send a command and await the matching aggregate reply: let! ev = documents.Send (Fcqrs.newCid()) (Fcqrs.aggregateId id) cmd (fun e -> ...)
connection: FCQRS.Actor.ConnectionFCQRS.FSharp.Fcqrsconnect: FCQRS.Actor.DBType -> string -> FCQRS.Actor.ConnectionBuild a SQLite/etc. Connection from a raw connection string (ShortString hidden).
SqliteSQLite using Microsoft.Data.Sqlite provider
FCQRS.ActorFCQRS.Actor.DBTypeRepresents the type of database connection
config: Extensions.Configuration.IConfigurationRootMicrosoft``.ctor``: unit -> unitExtensionsConfigurationBuild: unit -> Extensions.Configuration.IConfigurationRootBuilds an with keys and values from the set of providers registered in . An with keys and values from the registered providers.
loggerFactory: Extensions.Logging.ILoggerFactoryCreate: System.Action<Extensions.Logging.ILoggingBuilder> -> Extensions.Logging.ILoggerFactoryCreates new instance of configured using provided delegate. A delegate to configure the . The that was created.
LoggingMicrosoft.Extensions.Logging.LoggerFactoryProduces instances of classes based on the given providers.
api: FCQRS.Common.IActoractor: Extensions.Configuration.IConfiguration -> Extensions.Logging.ILoggerFactory -> FCQRS.Actor.Connection option -> string -> FCQRS.Common.IActorCreate the actor system from plain values (cluster name as a string).
SomeThe representation of "Value of type 'T" The input value. An option representing the value.
var builder = Host.CreateApplicationBuilder(args);
builder.Services.AddFcqrs(
connectionString: "Data Source=app.db;",
clusterName: "MyCluster");
The supported DBType values are listed in Configure the database.
The C# host-builder overload creates the same setup with SQLite.
What the defaults set up for you
The embedded configuration provides:
- a SQL journal for persisted events;
- a SQL read journal consumed by projections;
- a SQL snapshot store;
- automatic persistence-table initialization;
- FCQRS and Akka.NET serializers;
- the Akka.NET cluster actor provider and distributed pub/sub;
- cluster sharding with remembered entities;
- a localhost transport on a dynamic port;
- a one-node cluster formed by joining the process to itself.
The query journal polls for new events every 100 ms by default. Those persistence-plugin settings may be overridden with HOCON.
FCQRS runtime keys
The .NET configuration path uses colons. The equivalent HOCON path uses nested objects.
| .NET configuration key | Default | Purpose |
|---|---|---|
config:akka:persistence:snapshot-version-count |
30 |
Snapshot interval used by SnapshotPolicy.Default |
config:akka:fcqrs:saga-start-timeout |
30 |
Maximum seconds allowed for the saga-start handshake before fail-fast |
config:akka:fcqrs:command-timeout |
30s |
Deadline from command subscription setup to its matching aggregate reply; nonmatching events do not extend it |
config:akka:fcqrs:notification-buffer |
1024 |
Maximum queued notifications per subscriber; a full subscriber queue drops its oldest notification |
config:akka:fcqrs:max-worker-threads |
1024 |
Ceiling on the thread-pool floor the saga starter raises to cover concurrent saga-start handshakes |
config:akka:loglevel |
OFF |
Akka.NET internal log level |
config:akka:stdout-loglevel |
OFF |
Akka.NET standard-output log level |
The two timeout keys share one unit rule: a bare number means seconds. command-timeout also
accepts HOCON durations such as 500ms or 1m (beware: a bare number would mean milliseconds to
HOCON's duration parser — FCQRS parses bare numbers as seconds deliberately, matching
saga-start-timeout). The command timeout is an idle timeout: receiving a non-matching event on the
same correlation topic restarts it. Correlation topics are quiet in practice, but it is not a hard
deadline. The same key bounds the projection wait in the F# facade's sendAwaiting: a projection
that suppresses the matching notification raises TimeoutException instead of hanging the caller.
The notification buffer is not a durable queue. Notifications without an active subscriber may be dropped, which is correct for the request-scoped read-your-writes mechanism.
Transactional projections use TransactionalProjectionOptions for background discovery
(PollInterval, default 1s), per-identity batch size (BatchSize, default 500), and the complete
catch-up deadline (CatchUpTimeout, default 30s). These are registration options rather than HOCON
keys. See Catch up projections for their transaction and snapshot
boundaries.
The saga-start handshake is synchronous, so each concurrent start holds the thread its aggregate runs
on until the starter acknowledges. The saga starter therefore raises the CLR thread pool's minimum
worker count to cover the handshakes it has outstanding, up to max-worker-threads. A minimum is a
floor rather than a reservation: threads are created only as work demands them, so raising the ceiling
costs nothing until a burst of saga starts arrives. The floor is captured once per process and only
ever raised, never lowered or restored.
max-worker-threads is a real limit, not a tuning hint. Past it, saga-start handshakes time out and
fail-fast the process, exactly as they did before the floor was adaptive. On a 12-core machine at the
default ceiling, 1000 simultaneous saga starts across distinct aggregate instances complete and 1500
do not. The starter logs a warning the first time demand exceeds the ceiling, and an error if the
runtime refuses the raise outright (a lower process maximum). Values below the captured baseline are
ignored — the floor is never lowered. This bounds concurrent saga starts, not command throughput:
commands to one aggregate serialize through one entity. See
Sagas: durable coordination for why the handshake blocks.
Snapshot policy resolves in this order:
- the aggregate or saga's
Every norNoSnapshotssetting; - the C# builder's
WithDefaultSnapshotPolicyvalue; config:akka:persistence:snapshot-version-count;- the fallback value
30.
See Deferring, snapshots, and passivation before tuning the cadence. A snapshot changes replay cost, not the events that define recoverable state.
Set config:akka:scheduler to FCQRS's ObservingScheduler only in tests that control delayed saga
commands with a virtual clock.
Passivation timing
An aggregate actor that receives no message for akka.cluster.sharding.passivate-idle-entity-after
is stopped and releases its in-memory state. Akka.NET's default is 120s. Raise it for aggregates
whose replay is expensive relative to their idle memory, lower it for a large keyspace touched once,
and set 0 to disable idle passivation entirely.
config.akka.cluster.sharding.passivate-idle-entity-after = 30m
Keys nested under the entity name override the shared block for that entity type alone:
config.akka.cluster.sharding {
passivate-idle-entity-after = 30m # every aggregate type
Order.passivate-idle-entity-after = 2h # the Order aggregate only
Session.passivate-idle-entity-after = 30s
}
The override key is the Name in the aggregate definition, the same string used to build the
persistence id, so renaming an aggregate moves this key along with its journal contract.
An aggregate whose idle policy belongs to the domain rather than to the deployment can carry it in its definition, where it outranks both configuration levels:
Shared setup
module Account =
open FCQRS.Common
open FCQRS.FSharp
type RegisterUser = RegisterUser of name: string
type UserRegistered = UserRegistered of name: string
let decide (command: Command<RegisterUser>) (state: string option) =
let (RegisterUser name) = command.CommandDetails
persistIf state.IsNone (UserRegistered(defaultArg state name))
let fold (event: Event<UserRegistered>) (_state: string option) =
let (UserRegistered name) = event.EventDetails
Some name
open System
open FCQRS.Model.Data
open FCQRS.Common
open FCQRS.FSharp
open Account
let initial: string option = None
Fcqrs_502-configuration.md_page.AccountFCQRSFCQRS.CommonContains common types like Events and Commands Functionality for Write Side.
FCQRS.FSharpIdiomatic-F# functional facade for FCQRS. Gives F# consumers the same one-call ergonomics the C# host-builder (HostExtensions.fs) gives C#, but with F# idioms: records-of-functions for the definitions, typed handles for the results, an explicit wiring pipeline, and plain helpers for saga side effects. It is a *pure addition* that wraps only the existing primitives (IActor.InitializeActor / SagaBuilder.initSimple / Query.init / InitializeSagaStarter / CreateCommandSubscription / Actor.api) and changes nothing in the C# interop layer or the core. open FCQRS.FSharp let api = Fcqrs.actor config loggerFactory (Some (Fcqrs.connect DBType.Sqlite conn)) "Cluster" let documents = Fcqrs.aggregate api { Name="Document"; Initial=...; Decide=...; Fold=... } let slugs = Fcqrs.aggregate api { Name="Slug"; Initial=...; Decide=...; Fold=... } let publication = Fcqrs.saga api (publicationDef documents.Factory slugs.Factory) Fcqrs.wireSagaStarters api [ publication ] let subs = Fcqrs.projection api (Projection.single 0 updateReadModel) // (Projection.multi when you must control which notifications publish) // send a command and await the matching aggregate reply: let! ev = documents.Send (Fcqrs.newCid()) (Fcqrs.aggregateId id) cmd (fun e -> ...)
Fcqrs_502-configuration.md_page.Account.RegisterUserRegisterUsername: stringstringAn abbreviation for the CLI type . Basic Types
Fcqrs_502-configuration.md_page.Account.UserRegisteredUserRegistereddecide: Command<RegisterUser> -> string option -> EventAction<UserRegistered>command: Command<RegisterUser>FCQRS.Common.Command`1Represents a command to be processed by an aggregate actor. <typeparam name="'CommandDetails">The specific type of the command payload.</typeparam>
state: string optionoptionThe type of optional values. When used from other CLI languages the empty option is the null value. Use the constructors Some and None to create values of this type. Use the values in the Option module to manipulate values of this type, or pattern match against the values directly. 'None' values will appear as the value null to other CLI languages. Instance methods on this type will appear as static methods to other CLI languages due to the use of null as a value representation. Options
CommandDetails: 'CommandDetailsThe specific details or payload of the command.
persistIf: bool -> 'e -> EventAction<'e>Persist the event when `shouldPersist`, else defer it (published and folded but not journalled). The deferred fold should preserve state, because it cannot be replayed. This is the idempotent "emit this verdict, write it only once" shape.
IsNone: boolReturn 'true' if the option is a 'None' value.
defaultArg: 'T option -> 'T -> 'TUsed to specify a default value for an optional argument in the implementation of a function An option representing the argument. The default value of the argument. The argument value. If it is None, the defaultValue is returned. type Vector(x: double, y: double, ?z: double) = let z = defaultArg z 0.0 member this.X = x member this.Y = y member this.Z = z let v1 = Vector(1.0, 2.0) v1.Z // Evaluates to 0. let v2 = Vector(1.0, 2.0, 3.0) v2.Z // Evaluates to 3.0
fold: Event<UserRegistered> -> string option -> string optionevent: Event<UserRegistered>FCQRS.Common.Event`1Represents an event generated by an aggregate actor as a result of processing a command. <typeparam name="'EventDetails">The specific type of the event payload.</typeparam>
_state: string optionEventDetails: 'EventDetailsThe specific details or payload of the event.
SomeThe representation of "Value of type 'T" The input value. An option representing the value.
SystemModelFCQRS.Model.Datainitial: string optionNoneThe representation of "No value"
Fcqrs.aggregate api
{ Name = "Order"
Initial = initial
Decide = decide
Fold = fold
Snapshots = Default
Passivation = PassivationPolicy.After(TimeSpan.FromHours 2.0) }
FCQRS.FSharp.Fcqrsaggregate: IActor -> Aggregate<'State,'Command,'Event> -> AggregateHandle<'Command,'Event>Register an aggregate and return its typed handle. Calling this IS the registration (it initializes the sharding region).
api: IActorName: stringInitial: 'Stateinitial: string optionDecide: Command<'Command> -> 'State -> EventAction<'Event>handleCommand (decide): command + current state -> what to do.
decide: Command<RegisterUser> -> string option -> EventAction<UserRegistered>Fold: Event<'Event> -> 'State -> 'StateapplyEvent (fold): event + current state -> next state (pure).
fold: Event<UserRegistered> -> string option -> string optionSnapshots: SnapshotPolicySnapshot cadence: Default (config / 30), NoSnapshots, or Every n.
DefaultUse the global config (config:akka:persistence:snapshot-version-count), or 30.
Passivation: PassivationPolicyIdle passivation: PassivationPolicy.Default (configuration, then Akka's 120s), After an idle period, or Never.
FCQRS.Common.PassivationPolicyIdle passivation for an aggregate type, set per entity at registration. Passivation stops an idle actor and releases its in-memory state; the next command recovers it from the journal. Only messages routed through cluster sharding count as activity. Sagas ignore this: their shard regions remember entities, which disables idle passivation in Akka.NET. A saga stops at StopSaga or abort instead.
AfterPassivate after this idle period, overriding configuration. A non-positive value means Never.
System.TimeSpanRepresents a time interval.
FromHours: float -> TimeSpanReturns a that represents a specified number of hours, where the specification is accurate to the nearest millisecond. A number of hours accurate to the nearest millisecond. is less than TimeSpan.MinValue or greater than TimeSpan.MaxValue. -or- is . -or- is . is equal to . An object that represents .
public sealed class OrderAggregate : Aggregate<OrderState, OrderCommand, OrderEvent>
{
public override PassivationPolicy PassivationPolicy =>
PassivationPolicy.NewAfter(TimeSpan.FromHours(2));
}
PassivationPolicy.Never keeps the entity resident until the node stops or the shard moves.
PassivationPolicy.Default leaves configuration in charge, so the full order is:
- the aggregate definition's
AfterorNever; akka.cluster.sharding.<EntityName>.passivate-idle-entity-after;akka.cluster.sharding.passivate-idle-entity-after;- Akka.NET's
120s.
Choosing Never means the entity holds memory for as long as the node runs. It bounds recovery
cost, not memory, so it suits a small, bounded set of hot aggregates rather than an open keyspace.
Two limits apply:
- Only messages routed through cluster sharding count as activity. Messages an entity sends to
itself, and direct sends to a resolved
IActorRef, do not reset the idle timer. - Sagas are never idle-passivated. FCQRS starts saga regions with remembered entities, and Akka
disables idle passivation whenever that is on. A saga stops when its workflow reaches
StopSagaor aborts, so a saga that never terminates stays resident by design.
Passivation is not a per-instance setting: every entity of a type shares one timeout, whether it comes from configuration or from the definition. An individual aggregate instance cannot be given its own.
Deferring, snapshots, and passivation covers what passivation does and does not discard. Passivation costs a replay, so tune it together with the snapshot cadence.
Overriding with HOCON
Application configuration is added after the embedded HOCON, so matching application keys win. The example below overrides the three SQLite persistence stores explicitly:
config {
connection-string = "Data Source=app.db;"
akka {
persistence {
journal.sql {
connection-string = ${config.connection-string}
provider-name = "SQLite.MS"
auto-initialize = true
}
query.journal.sql {
connection-string = ${config.connection-string}
provider-name = "SQLite.MS"
auto-initialize = true
}
snapshot-store.sql {
connection-string = ${config.connection-string}
provider-name = "SQLite.MS"
auto-initialize = true
}
}
}
}
Load the file with ConfigurationBuilder().AddHoconFile("config.hocon").Build() and pass the result to
Fcqrs.actor, or add the same keys through another IConfiguration provider.
When overriding the database provider, change the journal, query journal, and snapshot store together. Pointing them at different databases is possible but changes backup, recovery, and availability behaviour and should be an explicit design choice.
Logging and diagnostics
FCQRS emits a message-flow log through ILogger and spans through ActivitySource. Configure payload
visibility before handling sensitive data. Observe your system lists the
categories, source names, switches, and fatal-flush hook.
Akka.NET internal logging defaults to OFF; FCQRS application-flow logs still use the supplied
ILoggerFactory. Enable Akka.NET internals with
builder.WithAkkaLogging(AkkaLogLevel.Info) from the hosting builder, or set config:akka:loglevel
in your IConfiguration.
Scaling to a cluster
The default node listens on localhost and joins itself. A multi-node deployment must override the remote hostname and port and configure seed-node discovery or another Akka.NET bootstrap mechanism. Every node must reach the shared journal and use compatible serializers and event contracts.
Cluster sharding routes an aggregate or saga id to its current node, so domain definitions do not change. Before deploying several nodes, verify rolling-version compatibility, shared storage, node discovery, coordinated shutdown, and monitoring for cluster membership and unreachable nodes.
Observe your system covers runtime diagnostics.