Skip to content

Commit 8516d23

Browse files
committed
--wip--
1 parent e60743b commit 8516d23

File tree

1 file changed

+89
-0
lines changed

1 file changed

+89
-0
lines changed

decouple-nats.md

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
# Nats decoupling: Transport-Agnostic pipeline
2+
3+
## Overview
4+
5+
The goal is to decouple the NATs transport from the pipeline.
6+
7+
## Requirements
8+
9+
- Ability to deliver messages across dynamo instances with at least once delivery guarantee.
10+
- Ability to switch between transports at runtime.
11+
12+
13+
## Durability guarantees
14+
15+
### At least once delivery
16+
- No message loss is possible.
17+
- Message is delivered at least once to the consumers
18+
19+
### Exactly once delivery
20+
- needs ack/nack coordination and stateful tracking of messages to ensure once delivery.
21+
22+
### At most once delivery
23+
- Message loss is possible.
24+
25+
26+
## Current NATs use cases
27+
#### 2. JetStream-backed Queue/Event Bus
28+
- **Location**: `lib/runtime/src/transports/nats.rs` (`NatsQueue`)
29+
- **Functionality**:
30+
- Stream creation per subject pattern `{stream_name}.*`
31+
- Publisher-only, worker-group, and broadcast consumer modes
32+
- Durable consumers with pull-based consumption
33+
- Administrative operations (purge, consumer management)
34+
35+
#### 3. Event Publishing for KV Router
36+
- **Location**: `lib/llm/src/kv_router/publisher.rs`
37+
- **Functionality**:
38+
- Publishes KV cache events from ZMQ or direct sources
39+
- Uses `EventPublisher` trait to send events
40+
41+
#### 4. Event Consumption for KV Router
42+
- **Location**: `lib/llm/src/kv_router/subscriber.rs`
43+
- **Functionality**:
44+
- Consumes `RouterEvent` messages via durable consumers
45+
- Handles state snapshots and stream purging
46+
47+
#### 5. Object Store (JetStream Object Store)
48+
- **Location**: `lib/runtime/src/transports/nats.rs`
49+
- **Functionality**:
50+
- File upload/download operations
51+
- Typed data serialization with bincode
52+
- Bucket management and cleanup
53+
54+
#### 6. Key-Value Store (JetStream KV)
55+
- **Location**: `lib/runtime/src/storage/key_value_store/nats.rs`
56+
- **Functionality**:
57+
- Implements `KeyValueStore` trait
58+
- CRUD operations with conflict resolution
59+
- Watch streams for real-time updates
60+
61+
#### 7. Request/Reply Pattern
62+
- **Location**: `lib/runtime/src/transports/nats.rs`
63+
- **Functionality**:
64+
- Service stats collection via broadcast requests
65+
- Each service responds once to stats queries
66+
67+
## Proposal
68+
- Use named message bus to publish and subscribe to messages.
69+
- Generalize ingress/egress components to support different transports
70+
71+
72+
## Alternative solutions
73+
74+
### Message queue transports
75+
- ZeroMQ
76+
- Redis
77+
- Kafka
78+
- SQS
79+
- GCP PubSub
80+
- Azure Service Bus
81+
82+
### Object store
83+
- S3
84+
- Redis
85+
- Shared filesystem
86+
87+
### Ideas
88+
89+
1. Use RocksDB / local storage to persist messages on producer side to guarantee at least once delivery.

0 commit comments

Comments
 (0)