Habitat's road to release: 02 sap for syncing permissioned spaces
A package to help apps keep permissioned data up-to-date.
ast week, we released our Space Proxy, which makes it possible for any atproto dev to experiment with the upcoming simplespace API today, ahead of the official release!
This week, we are making available sap, a Golang package for syncing permissioned spaces, inspired by the tap tool for backfilling and live-tailing public records.
How sap works:
sapimplements the sync protocol from the permissioned data proposal. It crawls permissioned spaces a user has access to, pulls the records from these, and receives notifications of new writes.- Apps can use
sapto continuously poll for new records in a space, and then index these into their AppView. Today, this indexes just the records and not the permission, but we have some updates that will improve the dev-ex here soon (see below). - Sap uses
listRepoOpsto incrementally update its synced repos and maintains a set hash for each. If a set hash deviates from the response's commit info, sap will mark the repo as desynced and do full state recovery viagetRepo. - Sap also tracks server errors and will retry requests with backoff.
- Currently
sapis compatible with Habitat's implementation of the permissioned data proposal which use thenetwork.habitat.*namespace and diverges slightly from the spec. We will continue to align these APIs as the finalized spec is released.
Follow ups:
- Support for running sap as a stand-alone binary so that you can include it as a service for apps written in languages other than Golang.
- Sap currently doesn't tell the caller about who has permission to what. At request time, your app will need to attempt to get a space credential on behalf of the requesting user to enforce permissions properly. We are working to build this into sap directly, to reduce additional steps done by the app.
- Sap crawls a user's spaces via
listSpaceswhen the user session is added viaSap.AddSession.However, the spaces protocol doesn't specify a way to notify apps of new spaces. If your app creates a space, you can track it viaSap.TrackSpace. However, if a new space was created in another app or the user was added to a space by another space host, there isn't a prescribed way to discover it. We kicked off a discussion on the Community Discourse around discovery of permissioned spaces. In this side-page, we outline the problem and a possible solution further.
- Sap has a lot of moving parts like auth sessions, crawl state, notification registration, resync loops, etc. Hence, Sap needs good observability for when something does goes awry. It currently emits Opentelemetry metrics and traces, but we're also planning on adding an API to introspect Sap's internal state and maybe also a UI to visualize it.
- Sap should theoretically be compatible with other permissioned spaces implementations like Nick Gerakines' and HappyView except we're using
network.habitat.*namespace. We'll experiment with these implementations and try to make Sap work with them as well. - Proper versioning for future sap releases.
We are testing sap with teams building applications on top of Habitat. If you decide to use sap, please join us on our Discord or email us at hello@habitat.network to give us feedback and help us improve it! Godocs are here: https://pkg.go.dev/github.com/habitat-network/habitat/pkg/sap
What's next:
- We have some very exciting releases coming the next two weeks, including finer-grained permissioning on top of spaces, and management of spaces across apps. Follow us @habitat.network to keep up!
Until next week!
- Habitat team 🌱
Did you enjoy this article?
Recommend it — Standard Reader surfaces well-loved writing to more readers across the network.