Bootstrap
When you subscribe with bootstrap: true, the server sends a complete snapshot of all existing entities before transitioning to live notifications. This ensures the subscriber starts from a consistent and complete view.
Server guarantees
Section titled “Server guarantees”The server uses a subscribe-before-scan approach:
- The subscription is registered for live notifications.
- The server sends
BOOTSTRAP_BEGIN(yielded as aBootstrapBeginnotification), with an approximate entity count. - The server scans every partition a page at a time and sends the entities as
Bootstrapnotifications. - When every partition has finished, the server sends
BOOTSTRAP_END(yielded asBootstrapComplete).
Because the subscription is registered before the scan begins:
- No gaps. Every entity that exists at subscribe time, or is created/updated after, is delivered at least once. You will never miss a change.
- No entity count limit. The server reads the snapshot a page at a time, only as fast as the subscriber consumes it, so kinds with millions of entities bootstrap correctly regardless of buffer sizes. If a bootstrap consumes nothing for
bootstrap_progress_timeout_secs(default 30), the connection is closed. - No
Bootstrapnotification followsBootstrapComplete. Every snapshot entity arrives before it, however long the bootstrap takes. - Duplicates are possible. An entity that changes during the scan window may arrive both as a
Bootstrapnotification and as a liveCreatedorUpdatednotification. This is by design. Gaps would mean stale data, while duplicates are easily resolved.
A server runs a limited number of bootstraps of one kind at once (max_concurrent_bootstraps_per_kind, default 2). A bootstrap that waits for a slot already receives live notifications.
Notification interleaving during bootstrap
Section titled “Notification interleaving during bootstrap”Between BootstrapBegin and BootstrapComplete, you may receive Bootstrap and live Created, Updated and Deleted notifications interleaved. Do not assume that all Bootstrap notifications arrive before any live notifications.
For any one entity, the server never sends a Bootstrap row after a later change to that entity. The client rules below don’t rely on this; they hold on their own.
Resolving duplicates: version wins
Section titled “Resolving duplicates: version wins”Every notification carries a Version that is monotonically increasing per entity. A Deleted carries the version of the deletion. During a bootstrap, the merge rule is highest version wins, regardless of notification type or arrival order, and deletes count:
- A
Bootstrapfor entity X at version 3, then a liveUpdatedfor X at version 4: apply version 4. - A live
Updatedfor X at version 4, then aBootstrapfor X at version 3: ignore the bootstrap row (you already have newer data). - A live
Deletedfor X at version 5, then aBootstrapfor X at version 5 or lower: ignore the bootstrap row. X stays deleted. Removing X is not enough; remember the delete’s version (a tombstone) until the bootstrap completes.
Outside a bootstrap, apply changes in arrival order. Versions restart when an in-memory server restarts, so comparing a live change with a version from before a reconnect can wrongly discard it.
Recommended pattern
Section titled “Recommended pattern”EntityMirror<TKey, T> implements these rules. Feed it every change from one loop and read Entries from anywhere:
var mirror = new EntityMirror<string, Player>(id => Convert.ToHexString(id.Span));
await foreach (var change in players.SubscribeAsync( bootstrap: true, reconnectMode: ReconnectBootstrapMode.Full, ct: ct)){ mirror.Apply(change); if (change.Type == NotificationType.BootstrapComplete) SignalReady(); // mirror.Entries now holds the whole kind}// Coming soonThe mirror collects each bootstrap, re-bootstraps included, into a fresh set: snapshot rows and live changes keep the higher version, and deletes leave tombstones. At BootstrapComplete it swaps that set in whole, so entities deleted while you were disconnected disappear. Live changes are also applied to Entries as they arrive. See Building correct state for reacting to changes and for writing to a database.
Detecting bootstrap completion
Section titled “Detecting bootstrap completion”The simplest way to detect bootstrap completion is the BootstrapComplete sentinel notification. It is yielded in the same stream, immediately after the last bootstrap entity. Its counterpart BootstrapBegin is yielded before the first. Both have Entity = null and zero-valued fields, and both are also emitted for re-bootstrap cycles (e.g. after reconnection with ReconnectBootstrapMode.Full).
Lower-level API
Section titled “Lower-level API”If you are using SubscriptionHandle directly, the BootstrapStatus property also tracks progress:
NotRequested -> InProgress -> Complete, then RebootstrapInProgress -> RebootstrapComplete for each re-bootstrap.
sub.BootstrapStatusChanged += status =>{ if (status is BootstrapState.Complete or BootstrapState.RebootstrapComplete) Console.WriteLine("Bootstrap complete.");};// Coming soonImportant: Do not use BootstrapStatus to filter notifications. Never drop live notifications while a bootstrap is in progress. The status is informational: it tells you when you have a complete snapshot.
One-shot bootstrap
Section titled “One-shot bootstrap”If you need a point-in-time snapshot without maintaining a live subscription, use BootstrapSnapshotAsync:
IReadOnlyList<Player> snapshot = await players.BootstrapSnapshotAsync();// Coming soonThis subscribes with bootstrap: true, feeds every notification into an EntityMirror as the snapshot streams in, and unsubscribes once bootstrap completes. Live updates and deletes that arrive during the bootstrap are applied, so the result is current as of BootstrapComplete. Because it drains continuously, it works for kinds of any size and is not limited by SubscriberBufferSize. It is useful for periodic reconciliation tasks.
Correctness rules summary
Section titled “Correctness rules summary”- Apply version-wins during a bootstrap.
Bootstrap,Created, andUpdatedall carry entity data and a version. Highest version wins, regardless of notification type or arrival order. - Never ignore live notifications during bootstrap. They may carry newer state than the scan.
- Treat
BootstrapandCreatedidentically for merge purposes. Both mean “here is the current state of this entity.” Deletedremoves the entity, and during a bootstrap leaves a tombstone at its version. Ignore any laterBootstraprow for that entity at or below that version. Discard the tombstones when the bootstrap completes.- Replace, don’t merge, at
BootstrapComplete. The bootstrap’s set is the whole kind: an entity you held that it lacks was deleted while you were disconnected.
EntityMirror follows all five.