# Durable Streams

[Durable Streams](https://github.com/durable-streams/durable-streams) is an open standard for real-time streams with durable, replayable history. Rivet provides an implementation backed by Rivet Actors.

## Quickstart

### Run locally

### Standalone

Start the local Rivet control plane and the Durable Streams worker:

```sh
npx @rivet-dev/services dev
```

Durable Streams is available at `http://127.0.0.1:8642/durable-streams/v1/stream/<path>`.

### RivetKit TypeScript SDK

Already running Rivet Actors with the RivetKit TypeScript SDK? Durable Streams is already available to you on RivetKit 2.3.12. No separate server needed.

### Connect to a stream

### TypeScript client

Install the official client:

```sh
npm install @durable-streams/client
```

client.ts:

```ts
import { DurableStream } from "@durable-streams/client";

const stream = await DurableStream.create({
	url: "http://127.0.0.1:8642/durable-streams/v1/stream/demo",
	contentType: "application/json",
});

await stream.append(JSON.stringify({ message: "hello" }));
```

### HTTP

Create a stream, append a record, and read its contents:

```sh
curl -i -X PUT \
  -H 'content-type: application/json' \
  --data '[{"message":"hello"}]' \
  http://127.0.0.1:8642/durable-streams/v1/stream/demo

curl -i -X POST \
  -H 'content-type: application/json' \
  --data '{"message":"world"}' \
  http://127.0.0.1:8642/durable-streams/v1/stream/demo

curl 'http://127.0.0.1:8642/durable-streams/v1/stream/demo?offset=-1'
```

### Deploy

### Rivet Cloud

1. Sign up at the [Rivet dashboard](https://dashboard.rivet.dev) and create a new project.
2. When creating the project, choose Durable Streams as the product.
3. Point your Durable Streams client at the services URL you're given, for example `https://xxxxx.rivet.run/durable-streams/`.

### Self-hosted

Run the Rivet control plane with the required feature flags enabled:

```sh
docker run -p 6420:6420 \
  -e RIVET__FEATURES__GUARD_GATEWAY_V3__MODE=on \
  -e RIVET__FEATURES__GUARD_GATEWAY_V3__PERCENTAGE=100 \
  rivetdev/engine
```

See the [self-hosting guides](/actors/self-host/) for other ways to run it.

Run the Durable Streams worker. It runs your streams and connects to the control plane:

```sh
docker run -p 8642:8642 \
  --add-host=host.docker.internal:host-gateway \
  -e RIVET_ENDPOINT=http://host.docker.internal:6420 \
  -e HOST=0.0.0.0 \
  rivetdev/services
```

Your streams are at `http://<host>:8642/durable-streams/v1/stream/<path>`.
