Skip to Content
SpiceDB is 100% open source. [Star us on GitHub]
Managed MaterializeAPI ReferenceDownloadPermissionSets

DownloadPermissionSets

Available onDedicated onlyEvent Streams (in early access)

For large datasets, DownloadPermissionSets is a faster alternative to LookupPermissionSets  for the initial backfill: instead of streaming individual events over a single connection, it hands you a manifest of files you can fetch directly from blob storage, in parallel.

Request

The request maps to DownloadPermissionSetsRequest:

{ "optional_at_revision": "the_zed_token" }

If optional_at_revision is omitted, Materialize returns files for the latest fully-published revision. If provided, Materialize returns files for that specific revision if they’re still available (see Snapshot rotation).

Once you’ve backfilled from the downloaded files, switch to WatchPermissionSets  to keep your copy current. See The Permission Set Lifecycle for the full flow.

Response

The response (DownloadPermissionSetsResponse) lists the available Files:

{ "timestamp": "2024-05-10T11:10:38Z", "at_revision": { "token": "GiAKHjE3MTUzMzk0Mzg2MjA4NzI1MDIuMDAwMDAwMDAwMA==" }, "files": [ { "name": "metadata.json", "url": "https://..." }, { "name": "flat_member_to_set.parquet", "url": "https://..." }, { "name": "flat_set_to_set.parquet", "url": "https://..." } ] }

at_revision is the ZedToken for the revision the files were built at. When you switch to WatchPermissionSets  after the backfill, pass it as optional_starting_after so the stream picks up right after the files, without gaps.

Each file’s url is a time-limited signed URL: download promptly. If a batch download runs long and the URLs expire, re-call DownloadPermissionSets with the previous response’s at_revision as optional_at_revision. Without it, you’d get the newest files, and could end up mixing files from different snapshots.

Sharded responses

Sharding isn’t generally available yet. If you’re interested in it, contact your AuthZed account team.

Large datasets can be sharded, with each file split into several parts. The response then lists every part:

{ "timestamp": "2024-05-10T11:10:38Z", "at_revision": { "token": "GiAKHjE3MTUzMzk0Mzg2MjA4NzI1MDIuMDAwMDAwMDAwMA==" }, "files": [ { "name": "metadata.json", "url": "https://..." }, { "name": "flat_member_to_set-shard-0.parquet", "url": "https://..." }, { "name": "flat_member_to_set-shard-1.parquet", "url": "https://..." }, { "name": "flat_set_to_set-shard-0.parquet", "url": "https://..." }, { "name": "flat_set_to_set-shard-1.parquet", "url": "https://..." } ] }

Treat each file’s parts as one combined dataset. For example, read flat_member_to_set-shard-*.parquet together as flat_member_to_set.

Files

Materialize publishes permission set data as two Parquet files, one for each kind of edge.

flat_member_to_set.parquet

Each row is a member → set edge: a subject that’s directly a member of a set. A subject is usually a member of an intermediate set, such as document:123#viewer, rather than of the permission you watch, such as document:123#view. That set is then nested in the permission’s set, in flat_set_to_set.parquet.

ColumnExampleMeaning
resource_typedocumentThe set’s resource type
resource_id123The set’s resource ID
resource_relviewerThe set’s name (see below)
subject_typeuserThe member’s type
subject_idevanThe member’s ID
subject_relThe member’s relation, or empty if the member is an object

resource_rel isn’t always a relation or permission from your schema. It can be a name Materialize generates, such as viewer.0. Treat it as an opaque string, and only use it to join with child_resource_rel in flat_set_to_set.parquet.

flat_set_to_set.parquet

Each row is a set → set edge: a child set nested in a parent set, so every member of the child is also a member of the parent. Nesting is already flattened: a set nested several levels deep links straight to the permission it grants. See Permission Sets for what “child” and “parent” mean here.

ColumnExampleMeaning
child_resource_typegroupThe child set’s resource type
child_resource_idengineeringThe child set’s resource ID
child_resource_relmemberThe child set’s name, an opaque string like resource_rel
parent_resource_typedocumentThe parent set’s resource type
parent_resource_id456The parent set’s resource ID
parent_resource_relviewThe parent set’s permission or relation

Querying the files

These are plain Parquet files, so any Parquet reader works: DuckDB, pandas/pyarrow, Spark, and most data warehouses can query them directly without a custom parser.

To find everyone in a permission set, combine its direct members with the members of its child sets. Because nesting is already flattened, one join is enough. For example, with DuckDB :

-- Every subject that can view document 123 SELECT subject_type, subject_id FROM 'flat_member_to_set.parquet' WHERE resource_type = 'document' AND resource_id = '123' AND resource_rel = 'view' UNION SELECT m.subject_type, m.subject_id FROM 'flat_set_to_set.parquet' s JOIN 'flat_member_to_set.parquet' m ON m.resource_type = s.child_resource_type AND m.resource_id = s.child_resource_id AND m.resource_rel = s.child_resource_rel WHERE s.parent_resource_type = 'document' AND s.parent_resource_id = '123' AND s.parent_resource_rel = 'view';

See Syncing to a Relational Database for the same pattern in tables you keep up to date.

Errors

NotFound

Returned when no download manifest exists for the requested revision (or for the latest revision, if none was specified). For example, if hydration hasn’t published a manifest yet, or the requested revision has aged out. Retry against the latest revision, or re-run without optional_at_revision.