You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This feature is only available in KurrentDB 25.1 and later.
204
-
:::
202
+
KurrentDB provides two operations for appending events to one or more streams in a single atomic transaction: `appendRecords` and `multiStreamAppend`. Both guarantee that either all writes succeed or the entire operation fails, but they differ in how records are organized, ordered, and validated.
205
203
206
-
You can append events to multiple streams in a single atomic operation. Either all streams are updated, or the entire operation fails.
|**Record ordering**| Interleaved. Records from different streams can be mixed, and their exact order is preserved in the global log. | Grouped. All records for a stream are sent together; ordering across streams is not guaranteed. |
208
+
|**Consistency checks**| Decoupled. Can validate the state of any stream, including streams not being written to. | Coupled. Expected state is specified per stream being written to. |
209
+
|**Protocol**| Unary RPC. All records and checks sent in a single request. | Client-streaming RPC. Records are streamed per stream. |
207
210
208
211
::: warning
209
212
Metadata must be a valid JSON object, using string keys and string values only.
@@ -212,13 +215,135 @@ KurrentDB's metadata handling. This restriction will be lifted in the next major
212
215
release.
213
216
:::
214
217
218
+
### appendRecords
219
+
220
+
::: note
221
+
This feature is only available in KurrentDB 26.1 and later.
222
+
:::
223
+
224
+
`appendRecords` appends events to one or more streams atomically. Each record specifies which stream it targets, and the exact order of records is preserved in the global log across all streams.
225
+
226
+
#### Single stream
227
+
228
+
The simplest usage appends events to a single stream:
Records can target different streams and be interleaved freely. The global log preserves the exact order you specify:
267
+
268
+
```ts
269
+
const records = [
270
+
{
271
+
streamName: "order-stream",
272
+
record: jsonEvent({
273
+
id: uuid(),
274
+
type: "OrderCreated",
275
+
data: { orderId: "123" },
276
+
}),
277
+
},
278
+
{
279
+
streamName: "inventory-stream",
280
+
record: jsonEvent({
281
+
id: uuid(),
282
+
type: "ItemReserved",
283
+
data: { itemId: "abc", quantity: 2 },
284
+
}),
285
+
},
286
+
{
287
+
streamName: "order-stream",
288
+
record: jsonEvent({
289
+
id: uuid(),
290
+
type: "OrderConfirmed",
291
+
data: { orderId: "123" },
292
+
}),
293
+
},
294
+
];
295
+
296
+
awaitclient.appendRecords(records);
297
+
```
298
+
299
+
#### Consistency checks
300
+
301
+
Consistency checks let you validate the state of any stream, including streams you are not writing to, before the append is committed. All checks are evaluated atomically: if any check fails, the entire operation is rejected and an `AppendConsistencyViolationError` is thrown with details about every failing check and the actual state observed.
// ensure the inventory stream exists before confirming the order,
319
+
// even though we are not writing to it
320
+
{
321
+
type: STREAM_STATE,
322
+
streamName: "inventory-stream",
323
+
expectedState: STREAM_EXISTS,
324
+
},
325
+
];
326
+
327
+
awaitclient.appendRecords(records, checks);
328
+
```
329
+
330
+
This decoupling of checks from writes enables [Dynamic Consistency Boundary](https://www.eventstore.com/blog/dynamic-consistency-boundary) patterns, where a business decision depends on the state of multiple streams but the resulting event is written to only one of them.
331
+
332
+
### multiStreamAppend
333
+
334
+
::: note
335
+
This feature is only available in KurrentDB 25.1 and later.
336
+
:::
337
+
338
+
`multiStreamAppend` appends events to one or more streams atomically. Records are grouped per stream using `AppendStreamRequest`, where each request specifies a stream name, an expected state, and the events for that stream.
0 commit comments