7.8 KiB
JetStream Post-Baseline Remaining Parity Design
Date: 2026-02-23
Status: Approved
Scope: Port all remaining Go JetStream functionality still marked Baseline or N in differences.md, including required transport prerequisites (gateway/leaf/account protocol) needed for full JetStream parity.
1. Architecture and Scope Boundary
Parity closure target
The completion target is to eliminate JetStream and JetStream-required transport deltas from differences.md by moving remaining rows from Baseline/N to Y unless an explicit external blocker is documented with evidence.
In scope (remaining parity inventory)
- JetStream runtime stream semantics:
- retention runtime behavior (
Limits,Interest,WorkQueue) MaxAgeTTL pruning andMaxMsgsPerenforcementMaxMsgSizereject path- dedupe-window semantics (bounded duplicate window, not unbounded dictionary)
- stream config behavior for
Compression, subject transform, republish, direct/KV toggles, sealed/delete/purge guards
- JetStream consumer semantics:
- full deliver-policy behavior (
All,Last,New,ByStartSequence,ByStartTime,LastPerSubject) AckPolicy.Allwire/runtime semantics parityMaxDeliver+ backoff schedule + redelivery deadlines- flow control frames, idle heartbeats, and rate limiting
- replay policy timing parity
- Mirror/source advanced behavior:
- mirror sync state tracking
- source subject mapping
- cross-account mirror/source behavior and auth checks
- JetStream storage parity layers:
- block-backed file layout
- time-based expiry/TTL index integration
- optional compression/encryption plumbing
- deterministic sequence index behavior for recovery and lookup
- RAFT/cluster semantics used by JetStream:
- heartbeat / keepalive and election timeout behavior
nextIndexmismatch backtracking- snapshot transfer + install from leader
- membership change semantics
- durable meta/replica governance wiring for JetStream cluster control
- JetStream-required transport prerequisites:
- inter-server account interest protocol (
A+/A-) with account-aware propagation - gateway advanced semantics (
_GR_.reply remap + full interest-only behavior) - leaf advanced semantics (
$LDS.loop detection + account remap rules) - cross-cluster JetStream forwarding path over gateway once interest semantics are correct
- internal
JETSTREAMclient lifecycle parity (ClientKind.JetStreamusage in runtime wiring)
Out of scope
Non-JetStream-only gaps that do not affect JetStream parity closure (for example route compression or non-JS auth callout features) remain out of scope for this plan.
2. Component Plan
A. Transport/account prerequisite completion
Primary files:
src/NATS.Server/Gateways/GatewayConnection.cssrc/NATS.Server/Gateways/GatewayManager.cssrc/NATS.Server/LeafNodes/LeafConnection.cssrc/NATS.Server/LeafNodes/LeafNodeManager.cssrc/NATS.Server/Routes/RouteConnection.cssrc/NATS.Server/Protocol/ClientCommandMatrix.cssrc/NATS.Server/NatsServer.cssrc/NATS.Server/Subscriptions/RemoteSubscription.cssrc/NATS.Server/Subscriptions/SubList.cs
Implementation intent:
- carry account-aware remote interest metadata end-to-end
- implement gateway reply remap contract and de-remap path
- implement leaf loop marker handling and account remap/validation
B. JetStream runtime semantic completion
Primary files:
src/NATS.Server/JetStream/StreamManager.cssrc/NATS.Server/JetStream/ConsumerManager.cssrc/NATS.Server/JetStream/Consumers/PullConsumerEngine.cssrc/NATS.Server/JetStream/Consumers/PushConsumerEngine.cssrc/NATS.Server/JetStream/Consumers/AckProcessor.cssrc/NATS.Server/JetStream/Publish/JetStreamPublisher.cssrc/NATS.Server/JetStream/Publish/PublishPreconditions.cssrc/NATS.Server/JetStream/Models/StreamConfig.cssrc/NATS.Server/JetStream/Models/ConsumerConfig.cssrc/NATS.Server/JetStream/Validation/JetStreamConfigValidator.cs
Implementation intent:
- enforce configured policies at runtime, not just parse/model shape
- preserve Go-aligned API error codes and state transition behavior
C. Storage and snapshot durability
Primary files:
src/NATS.Server/JetStream/Storage/FileStore.cssrc/NATS.Server/JetStream/Storage/FileStoreBlock.cssrc/NATS.Server/JetStream/Storage/FileStoreOptions.cssrc/NATS.Server/JetStream/Storage/MemStore.cssrc/NATS.Server/JetStream/Snapshots/StreamSnapshotService.cs
Implementation intent:
- replace JSONL-only behavior with block-oriented store semantics
- enforce TTL pruning in store read/write paths
D. RAFT and JetStream cluster governance
Primary files:
src/NATS.Server/Raft/RaftNode.cssrc/NATS.Server/Raft/RaftReplicator.cssrc/NATS.Server/Raft/RaftTransport.cssrc/NATS.Server/Raft/RaftLog.cssrc/NATS.Server/Raft/RaftSnapshotStore.cssrc/NATS.Server/JetStream/Cluster/JetStreamMetaGroup.cssrc/NATS.Server/JetStream/Cluster/StreamReplicaGroup.cssrc/NATS.Server/JetStream/Cluster/AssetPlacementPlanner.cs
Implementation intent:
- transition from in-memory baseline consensus behavior to networked state-machine semantics needed by cluster APIs.
E. Internal JetStream client and observability
Primary files:
src/NATS.Server/NatsServer.cssrc/NATS.Server/InternalClient.cssrc/NATS.Server/Monitoring/JszHandler.cssrc/NATS.Server/Monitoring/VarzHandler.csdifferences.md
Implementation intent:
- wire internal
ClientKind.JetStreamclient lifecycle where Go uses internal JS messaging paths - ensure monitoring reflects newly enforced runtime behavior
3. Data Flow and Behavioral Contracts
- Interest/account propagation:
- local subscription updates publish account-scoped interest events to route/gateway/leaf peers
- peers update per-account remote-interest state, not global-only state
- Gateway reply remap:
- outbound cross-cluster reply subjects are rewritten with
_GR_.metadata - inbound responses are de-remapped before local delivery
- no remap leakage to end clients
- Leaf loop prevention:
- loop marker (
$LDS.) is injected/checked at leaf boundaries - looped deliveries are rejected before enqueue
- Stream publish lifecycle:
- validate stream policy + preconditions
- apply dedupe-window logic
- append to store, prune by policy, then trigger mirror/source + consumer fanout
- Consumer delivery lifecycle:
- compute start position from deliver policy
- enforce max-ack-pending/rate/flow-control/backoff rules
- track pending/acks/redelivery deterministically across pull/push engines
- Cluster lifecycle:
- RAFT heartbeat/election drives leader state
- append mismatch uses next-index backtracking
- snapshots transfer over transport and compact follower logs
- meta-group and stream-groups use durable consensus outputs for control APIs
4. Error Handling, Testing, and Completion Gate
Error handling principles
- Keep JetStream API contract errors deterministic (validation vs state vs leadership vs storage).
- Avoid silent downgrades from strict policy semantics to baseline fallback behavior.
- Ensure cross-cluster remap/loop detection failures surface with protocol-safe errors and no partial state mutation.
Test strategy
- Unit tests for each runtime policy branch and protocol transformation.
- Integration tests for gateway/leaf/account propagation and cross-cluster message contracts.
- Contract tests for RAFT election, snapshot transfer, and membership transitions.
- Parity-map tests tying Go feature inventory rows to concrete .NET tests.
Strict completion criteria
- Remaining JetStream/prerequisite rows in
differences.mdare eitherYor explicitly blocked with linked evidence. - New behavior has deterministic test coverage at unit + integration level.
- Focused and full suite gates pass.
differences.mdand parity map are updated only after verified green evidence.