Skip to content

Commit 970ceb4

Browse files
authored
Merge pull request #387 from authzed/docs-on-performance
feat: improved docs on performance
2 parents 3ab7b81 + 8a8fce5 commit 970ceb4

File tree

7 files changed

+95
-62
lines changed

7 files changed

+95
-62
lines changed

.markdownlint-cli2.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ config:
88
no-hard-tabs: false
99
no-inline-html: false
1010
no-multiple-blanks: false
11+
max-one-sentence-per-line: false
1112
customRules:
1213
- "markdownlint-rule-max-one-sentence-per-line"
1314
fix: false

pages/spicedb/concepts/_meta.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
"consistency": "Consistency",
99
"datastores": "Datastores",
1010
"datastore-migrations": "Datastore Migrations",
11-
"dispatch": "Dispatch",
1211
"reflection-apis": "Reflection APIs",
1312
"watch": "Watching Changes"
1413
}

pages/spicedb/concepts/dispatch.mdx

Lines changed: 0 additions & 57 deletions
This file was deleted.

pages/spicedb/getting-started/first-steps.mdx

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ import { InlinePlayground } from '@/components/playground'
3535
<Cards>
3636
<Card arrow={true} title="Consistency" href="../concepts/consistency" />
3737
<Card arrow={true} title="Caveats" href="../concepts/caveats" />
38-
<Card arrow={true} title="Dispatch" href="../concepts/dispatch" />
3938
</Cards>
4039

4140
### Dive into some videos

pages/spicedb/ops/_meta.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"deploying-spicedb-operator": "Deploying the SpiceDB Kubernetes Operator",
44
"eks": "Deploying to AWS EKS",
55
"data": "Writing data to SpiceDB",
6+
"performance": "Improving Performance",
67
"observability": "Observability Tooling",
78
"ai-agent-authorization": "Authorization for AI Agents",
89
"secure-rag-pipelines": "Secure Your RAG Pipelines with Fine Grained Authorization"

pages/spicedb/ops/eks.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,13 @@ If the `spicedb-le-tls` secret is not present, follow this [troubleshooting guid
151151
[Secret]: https://kubernetes.io/docs/concepts/configuration/secret
152152
[troubleshooting guide]: https://cert-manager.io/docs/troubleshooting/acme/
153153

154-
### Configuring Dispatch TLS
154+
### Configuring Cross-Pod TLS
155155

156-
SpiceDB [dispatches] work across instances in the same deployment via [gRPC].
156+
SpiceDB will be more performant when cross-pod communication is enabled (see [performance]).
157157
We'll be securing this pod-to-pod communication with its own internal-only certificate:
158158

159159
[gRPC]: https://grpc.io
160-
[dispatches]: ../concepts/dispatch
160+
[performance]: performance#by-enabling-cross-node-communication
161161

162162
```sh
163163
kubectl apply --server-side -f - <<EOF

pages/spicedb/ops/performance.mdx

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
import { Callout } from 'nextra/components'
2+
3+
# Improving Performance
4+
5+
## By enabling cross-node communication
6+
7+
SpiceDB can be deployed in a clustered configuration where multiple nodes work together to serve API requests. In such a configuration, and for the CheckPermissions API, enabling a feature called **dispatch** allows nodes to break down one API request into smaller "questions" and forward those to other nodes within the cluster. This helps reduce latency and improve overall performance.
8+
9+
### How it works
10+
11+
Each SpiceDB node maintains an in-memory cache of permissions queries it has resolved in the past. When a new permissions query is encountered by one node, its answer may be present on another node, so SpiceDB will forward the request onward to the other node to check the shared cache.
12+
13+
For more details on how dispatching works, see the [Consistent Hash Load Balancing for gRPC] article.
14+
15+
[consistent hash load balancing for grpc]: https://authzed.com/blog/consistent-hash-load-balancing-grpc/
16+
17+
### Configuration in Kubernetes environments
18+
19+
If using the [SpiceDB Operator], dispatching is enabled by default and no additional configuration is necessary.
20+
21+
If not using it, you need to set the following flag:
22+
23+
```sh
24+
--dispatch-upstream-addr=kubernetes:///spicedb.default:50053
25+
```
26+
27+
where `spicedb.default` is the Kubernetes `Service` in which SpiceDB is accessible.
28+
29+
<Callout type="info">
30+
If you are deploying SpiceDB under Kubernetes, it is recommended to use the [SpiceDB Operator], which configures dispatching automatically.
31+
32+
[spicedb operator]: /spicedb/ops/operator
33+
</Callout>
34+
35+
### Configuration in non-Kubernetes environments
36+
37+
<Callout type="warning">
38+
Non-Kubernetes based dispatching relies upon DNS updates, which means it can become stale if DNS is changing. This is not recommended unless DNS updates are rare.
39+
</Callout>
40+
41+
To enable dispatch, the following flags must be specified:
42+
43+
```sh
44+
spicedb serve \
45+
--dispatch-cluster-enabled=true \
46+
--dispatch-upstream-addr=upstream-addr \
47+
...
48+
```
49+
50+
or via environment variables with the `SPICEDB_` prefix:
51+
52+
```sh
53+
SPICEDB_DISPATCH_CLUSTER_ENABLED=true \
54+
SPICEDB_DISPATCH_UPSTREAM_ADDR=upstream-addr \
55+
spicedb serve ...
56+
```
57+
58+
The `upstream-addr` should be the DNS address of the load balancer at which _all_ SpiceDB nodes are accessible at the default dispatch port of `:50053`.
59+
60+
## By enabling Materialize
61+
62+
[Materialize] is a separate service that allows for the precomputation of permission query results.
63+
64+
If Materialize is running, SpiceDB can dispatch sub-queries to Materialize, which can significantly speed up permission checks.
65+
66+
[Materialize]: /authzed/concepts/authzed-materialize
67+
68+
## By enabling the schema cache
69+
70+
The schema cache stores type definitions and caveat definitions to avoid repeatedly fetching schema information from the datastore.
71+
72+
SpiceDB offers two caching modes:
73+
74+
1. **Just-In-Time (JIT) Caching**: The default mode that loads definitions on-demand. Uses less memory, but it incurs a cold start penalty on first access to each definition.
75+
2. **Watching Cache**: An experimental mode that proactively maintains an always-up-to-date cache. This mode uses more memory but avoids cold start penalties. It is recommended when there are frequent schema changes.
76+
77+
To configure the schema cache, use the following flags:
78+
79+
```bash
80+
# Enable namespace cache (default: true)
81+
--ns-cache-enabled=true
82+
83+
# Maximum memory (default: 32 MiB)
84+
--ns-cache-max-cost=32MiB
85+
86+
# Enable experimental watchable schema cache (default: false)
87+
# When true: uses watching cache if datastore supports it
88+
# When false: always uses JIT caching
89+
--enable-experimental-watchable-schema-cache=false
90+
```

0 commit comments

Comments
 (0)