Skip to content

Commit 5205e47

Browse files
committed
Fix link checker and lint
1 parent 96a33e8 commit 5205e47

File tree

2 files changed

+77
-24
lines changed

2 files changed

+77
-24
lines changed

pages/best-practices/best-practices.mdx

Lines changed: 75 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,53 @@ In most cases, these rules should be followed.
1818
The recommended rules reflect how we would run our own systems, but may not apply to every use case and may not make sense in every situation.
1919
Follow them if you can and ignore them if you can’t.
2020

21+
<BestPracticesSelector />
22+
2123
## Priority A Rules: Essential
2224

23-
### Make sure your schema fails closed
25+
### Make Sure your Schema Fails Closed
2426

2527
Tags: **schema**
2628

2729
This is related to the idea of using negation sparingly, and of phrasing your schema additively.
2830
Give thought to what happens if your application fails to write a relation: should the user have access in that case?
2931
The answer is almost always `no`.
3032

33+
This example is very simple, but illustrates the basic point:
34+
35+
#### Avoid
36+
37+
This schema starts with everyone having access and reduces it as you add users to the deny list.
38+
If you fail to write a user to the deny list, they'll have access when they shouldn't:
39+
40+
```zed
41+
definition user {}
42+
43+
definition resource {
44+
relation public: user:*
45+
relation deny: user
46+
47+
permission view = public - deny
48+
}
49+
```
50+
51+
#### Prefer
52+
53+
By contrast, this schema defaults to nobody having access, and therefore fails closed:
54+
55+
```zed
56+
definition user {}
57+
58+
definition resource {
59+
relation user: user
60+
61+
permission view = user
62+
}
63+
```
64+
65+
This is an admittedly simple example, but the concept holds in more complex schemas.
66+
This will also sometimes require a conversation about the business logic of your application.
67+
3168
### Tune Connections to Datastores
3269

3370
Tags: **operations**
@@ -36,6 +73,25 @@ To size your SpiceDB connection pools, start by determining the maximum number o
3673

3774
Use these values to set the `--datastore-conn-pool-read-max-open` and `--datastore-conn-pool-write-max-open` flags, and set the corresponding min values to half of each, adjusting as needed based on whether your workload leans more heavily on reads or writes.
3875

76+
#### Example
77+
78+
Let's say you have a database instance that supports 200 connections, and you know that you read more than you write.
79+
You have 4 SpiceDB instances in your cluster.
80+
A starting point for tuning this might be:
81+
82+
```sh
83+
spicedb serve
84+
# other flags here
85+
--datastore-conn-pool-read-max-open 30
86+
--datastore-conn-pool-read-min-open 15
87+
--datastore-conn-pool-write-max-open 20
88+
--datastore-conn-pool-write-min-open 10
89+
```
90+
91+
This reserves 50 connections per SpiceDB instance and distributes them accordingly.
92+
93+
The `pgxpool_empty_acquire` metric can help you understand if your SpiceDB pods are starved for connections if you're using Postgres or Cockroach.
94+
3995
### Test Your Schema
4096

4197
Tags: **schema**
@@ -44,7 +100,7 @@ You should be testing the logic of your schema to ensure that it behaves the way
44100

45101
- For unit testing and TDD, use test relations + assertions and [zed validate](https://authzed.com/docs/spicedb/modeling/validation-testing-debugging#zed-validate).
46102
- For snapshot testing, use test relations + expected relations and [zed validate](https://authzed.com/docs/spicedb/modeling/validation-testing-debugging#zed-validate).
47-
- For integration testing, use the SpiceDB test server with spicedb [serve-testing](https://authzed.com/docs/spicedb/modeling/validation-testing-debugging#integration-test-server).
103+
- For integration testing, use the SpiceDB test server with SpiceDB [serve-testing](https://authzed.com/docs/spicedb/modeling/validation-testing-debugging#integration-test-server).
48104

49105
### Prefer Relations to Caveats
50106

@@ -53,15 +109,15 @@ Tags: **schema**
53109
If an authorization concept can be expressed using relations, it should be.
54110
We provide caveats as an escape hatch; they should only be used for context that’s only available at request time, or else ABAC logic that cannot be expressed in terms of relationships.
55111

112+
This is because caveats come with a performance penalty.
113+
A caveated relationship is both harder to cache and also slows down computation of the graph walk required to compute a permission.
114+
56115
Some examples:
57116

58117
- A banlist - this could be expressed as a list in caveat context, but it can also be expressed as a relation with negation.
59118
- A notion of public vs internal - boolean flags seem like an obvious caveat use case, but they can also be expressed using self relations.
60119
- Dynamic roles - these could be expressed as a list in caveats, and it’s not immediately obvious how to build them into a spicedb schema, but our [Google Cloud IAM example](https://authzed.com/blog/google-cloud-iam-modeling) shows how it’s possible.
61120

62-
This is because caveats come with a performance penalty.
63-
A caveated relationship is both harder to cache and also slows down computation of the graph walk required to compute a permission.
64-
65121
### Make Your Writes Idempotent
66122

67123
Tags: **application**
@@ -88,12 +144,18 @@ In Postgres, the implementation of MVCC depends on the internals of the transact
88144

89145
Tags: **operations**
90146

91-
While designing your authorization, it’s important to plan ahead for how quickly an update is guaranteed, while trading off performance via cache effectiveness.
92-
By default, SpiceDB sets the Quanitzation Interval to 5s; check operations are cached within this window.
93-
To change this value, set `--datastore-revision-quantization-interval` longer or shorter.
147+
SpiceDB gives the user the ability to make tradeoffs between cache performance and up-to-date visibility using [its consistency options](https://authzed.com/docs/spicedb/concepts/consistency).
148+
In addition to these call-time options, there are also some flags that can provide better cache performance if additional staleness is acceptable.
149+
For example, by default, SpiceDB sets the Quantization Interval to 5s; check operations are cached within this window when using `minimize_latency` or `at_least_as_fresh` calls.
150+
Setting this window to be larger increases the ability of SpiceDB to use cached results with a tradeoff of results staying in the cache longer.
151+
More details about how these flags work together can be found in our [Hotspot Caching blog post](https://authzed.com/blog/hotspot-caching-in-google-zanzibar-and-spicedb).
152+
To change this value, set the `--datastore-revision-quantization-interval` flag.
94153

95-
When it comes to write consistency, SpiceDB defaults to high safety, especially in distributed database writing scenarios, guaranteeing a visibility order.
96-
Individual datastores may also allow a relaxation of this guarantee, based on your scenario; for example, [setting CockroachDB’s overlap strategy](https://authzed.com/docs/spicedb/concepts/datastores#overlap-strategy), trading some authorization visibility safety across domains for greatly increased write throughput.
154+
When it comes to write consistency, SpiceDB defaults to high safety,
155+
especially in distributed database writing scenarios, guaranteeing a visibility order.
156+
Individual datastores may also allow a relaxation of this guarantee, based on your scenario;
157+
for example, [setting CockroachDB’s overlap strategy](https://authzed.com/docs/spicedb/concepts/datastores#overlap-strategy),
158+
can let you trade some ordering and consistency guarantees across domains for greatly increased write throughput.
97159

98160
### Use GRPC When Possible
99161

@@ -278,7 +340,7 @@ Tags: **schema**
278340
As a schema grows in size and complexity, it can become difficult to navigate and grok.
279341
We implemented [Composable Schemas](https://authzed.com/docs/spicedb/modeling/composable-schemas) to solve this problem, allowing you to break down a schema into multiple files and definitions into multiple problems.
280342

281-
### When In Doubt, Add Another Permission
343+
### Don't Re-Use Permissions Across Use Cases
282344

283345
Tags: **schema**
284346

@@ -291,3 +353,5 @@ Tags: **schema**
291353

292354
Expiration is a common use case – at some future time, a permission is revoked.
293355
It’s so common, it’s now [a built-in feature](https://authzed.com/docs/spicedb/concepts/expiring-relationships), and is far more efficient for SpiceDB to handle than doing the same with caveats!
356+
357+
</BestPracticesProvider>

pages/spicedb/concepts/datastores.mdx

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -274,19 +274,8 @@ Because this counter is instance-specific, there are ways in which the data in t
274274
Two concrete examples are the use of `pg_dump` and `pg_restore` to transfer data between an old instance and a new instance and setting up
275275
logical replication between a previously-existing instance and a newly-created instance.
276276

277-
If you encounter this, SpiceDB can behave as though there is no schema written, because the data (including the schema) is associated with a future transaction ID and therefore
278-
isn't "visible" to Spicedb.
279-
You may see an error like this:
280-
281-
```
282-
FAILED_PRECONDITION: object definition `some_definition` not found
283-
```
284-
285-
If this occurs, you can use `spicedb datastore repair` (along with your usual datastore flags) to roll the transaction counter of the database forward until SpiceDB is able to resume normal operation:
286-
287-
```
288-
spicedb datastore repair --datastore-engine=postgres --datastore-conn-uri=$DATASTORE_URI
289-
```
277+
If you encounter this, SpiceDB can behave as though there is no schema written, because the data (including the schema) is associated with a future transaction ID and therefore isn't "visible" to Spicedb.
278+
If you run into this issue, the fix is [documented here](https://authzed.com/docs/spicedb/concepts/datastores#transaction-ids-and-mvcc)
290279

291280
### Configuration
292281

0 commit comments

Comments
 (0)