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
## Summary
Enable confirmed reads by default for all WebSocket subscriptions and
SQL queries. This is a 2.0 breaking change that improves data integrity.
### What changed
Previously, subscription updates and SQL results were sent to clients
immediately, before the transaction was confirmed durable. A server
crash could cause clients to have observed data that was lost.
Now the server defaults to `confirmed=true`. Clients receive updates
only after durability is confirmed. This adds a small latency cost but
guarantees that any data a client receives will survive a server
restart.
### Changes
**Server (2 files, 2 lines each):**
- `subscribe.rs`: `SubscribeQueryParams.confirmed` defaults to `true`
- `database.rs`: `SqlQueryParams.confirmed` defaults to `true`
**Documentation:**
- Migration guide updated with "Confirmed Reads Enabled by Default"
section
- Added to overview list and quick migration checklist
### Opt-out
Clients can opt out by explicitly passing `?confirmed=false` in the
WebSocket URL or using `.withConfirmedReads(false)` /
`.WithConfirmedReads(false)` / `.with_confirmed_reads(false)` in SDKs.
### Smoketest impact
Smoketests that don't explicitly pass `--confirmed` will now get
confirmed reads via the server default. This should not cause failures
-- confirmed reads only add a small wait for durability confirmation
before sending results. The `confirmed_reads.py` smoketest explicitly
passes `--confirmed` and continues to work as before.
### SDK impact
No SDK changes needed. SDKs only send the `confirmed` query parameter
when explicitly set by the user. When not set, the server default
applies -- which is now `true`.
---------
Signed-off-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
Co-authored-by: clockwork-labs-bot <clockwork-labs-bot@users.noreply.github.com>
Co-authored-by: clockwork-labs-bot <bot@clockworklabs.com>
Co-authored-by: Zeke Foppa <196249+bfops@users.noreply.github.com>
Co-authored-by: Zeke Foppa <bfops@users.noreply.github.com>
Copy file name to clipboardExpand all lines: docs/docs/00300-resources/00100-how-to/00600-migrating-to-2.0.md
+65Lines changed: 65 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -18,6 +18,7 @@ SpacetimeDB 2.0 introduces a new WebSocket protocol (v2) and SDK with several br
18
18
2.**`light_mode` removed** -- no longer necessary since reducer events are no longer broadcast
19
19
3.**`CallReducerFlags` removed** -- `NoSuccessNotify` and `set_reducer_flags()` are gone
20
20
4.**Event tables introduced** -- a new table type for publishing transient events to subscribers
21
+
5.**Confirmed reads enabled by default** -- subscription updates and SQL results are only sent after the transaction is confirmed durable
21
22
22
23
## Reducer Callbacks
23
24
@@ -1295,6 +1296,69 @@ In 2.0, the success notification is lightweight (just `request_id` and `timestam
1295
1296
</TabItem>
1296
1297
</Tabs>
1297
1298
1299
+
## Confirmed Reads Enabled by Default
1300
+
1301
+
### What changed
1302
+
1303
+
In 1.0, subscription updates and SQL query results were sent to the client immediately, before the underlying transaction was confirmed to be durable. This meant a client could observe a row that was later lost if the server crashed before persisting it.
1304
+
1305
+
In 2.0, **confirmed reads are enabled by default**. The server waits until a transaction is confirmed durable before sending updates to clients. This ensures that any data a client receives will survive a server restart.
1306
+
1307
+
### Impact
1308
+
1309
+
-**Slightly higher latency**: Subscription updates and SQL results may arrive a few milliseconds later, as the server waits for durability confirmation before sending them.
1310
+
-**Stronger consistency**: Clients will never observe data that could be lost due to a crash.
1311
+
-**No code changes required**: This is a server-side default change. Existing client code works without modification.
1312
+
1313
+
### Opting out
1314
+
1315
+
If your application prioritizes low latency over durability guarantees (for example, a real-time game where occasional data loss on crash is acceptable), you can opt out by passing `confirmed=false` in the connection URL:
1316
+
1317
+
<TabsgroupId="client-language"queryString>
1318
+
<TabItemvalue="typescript"label="TypeScript">
1319
+
1320
+
```typescript
1321
+
DbConnection.builder()
1322
+
.withUri("https://maincloud.spacetimedb.com")
1323
+
.withDatabaseName("my-database")
1324
+
.withConfirmedReads(false) // opt out of confirmed reads
1325
+
.build()
1326
+
```
1327
+
1328
+
</TabItem>
1329
+
<TabItemvalue="csharp"label="C#">
1330
+
1331
+
```csharp
1332
+
DbConnection.Builder()
1333
+
.WithUri("https://maincloud.spacetimedb.com")
1334
+
.WithDatabaseName("my-database")
1335
+
.WithConfirmedReads(false) // opt out of confirmed reads
1336
+
.Build();
1337
+
```
1338
+
1339
+
</TabItem>
1340
+
<TabItemvalue="rust"label="Rust">
1341
+
1342
+
```rust
1343
+
DbConnection::builder()
1344
+
.with_uri("https://maincloud.spacetimedb.com")
1345
+
.with_database_name("my-database")
1346
+
.with_confirmed_reads(false) // opt out of confirmed reads
1347
+
.build()
1348
+
.expect("Failed to connect");
1349
+
```
1350
+
1351
+
</TabItem>
1352
+
</Tabs>
1353
+
1354
+
For the CLI:
1355
+
1356
+
```bash
1357
+
# SQL without confirmed reads
1358
+
spacetime sql <database>"SELECT * FROM my_table"
1359
+
# The --confirmed flag is no longer needed (it is the default)
1360
+
```
1361
+
1298
1362
## Quick Migration Checklist
1299
1363
1300
1364
-[ ] Remove all `ctx.reducers.on_<reducer>()` calls
@@ -1320,3 +1384,4 @@ In 2.0, the success notification is lightweight (just `request_id` and `timestam
1320
1384
-[ ] Remove `with_light_mode()` from `DbConnectionBuilder`
1321
1385
-[ ] Remove `set_reducer_flags()` calls and `CallReducerFlags` imports
1322
1386
-[ ] Remove `unstable::CallReducerFlags` from imports
1387
+
-[ ] Note that confirmed reads are now enabled by default (no action needed unless you want to opt out with `.withConfirmedReads(false)`)
0 commit comments