Notification indexer service
README.md

Leonis #

Appview-less services can leverage microcosm services to hydrate their feeds however tracking notifications can be a challenge since it needs to be near realtime tracking likes, follows, replies, quotes, reposts, etc.

This service helps acts as a notification sync services by subscribing to a PDS to track users then ingests records from the relay to index notifications.

Content is indexed into fjall and served.

How It Works #

  1. Connects to PDS firehose (com.atproto.sync.subscribeRepos) and does an initial listRepos sync to build the actor registry. Tracks account and identity events to keep the set of enrolled actors current.
  2. Subscribes to a Jetstream relay filtering for app.bsky.feed.post, app.bsky.feed.like, app.bsky.feed.repost, and app.bsky.graph.follow. Sends relevant events through a bounded channel (10k capacity) with backpressure.
  3. Serves app.bsky.notification.listNotifications over HTTP with DID-scoped pagination and optional reason filtering.

Configuration #

All configuration is via environment variables. Only LEONIS_PDS_URL is required.

Variable Default Description
LEONIS_PDS_URL (required) WebSocket URL of your PDS (e.g. wss://pds.example.com)
LEONIS_JETSTREAM_URL wss://jetstream2.us-east.bsky.network/subscribe Jetstream relay endpoint
LEONIS_DATA_DIR ./data Directory for fjall storage
LEONIS_PORT 3000 HTTP listen port
LEONIS_RETENTION_DAYS 7 Notification retention period (1–30)
LEONIS_PROCESSOR_WORKERS 4 Number of event processor tasks
LEONIS_CURSOR_FLUSH_INTERVAL_SECS 5 How often cursors are persisted to disk
LEONIS_LAZY_ENROLLMENT false Enable on-demand DID enrollment via PLC directory lookup
LEONIS_LAZY_ENROLLMENT_FOREIGN_PDS ignore Policy for DIDs on a different PDS: ignore or subscribe
LEONIS_CACHE_TTL_SECS 30 Response cache TTL
LEONIS_CACHE_MAX_ENTRIES 10000 Maximum cache entries
LEONIS_PLC_DIRECTORY_URL https://plc.directory Custom PLC directory URL for DID resolution
LEONIS_REQUIRE_AUTH false Require atproto service-auth on XRPC endpoints. When enabled, callers must present a valid Authorization: Bearer <jwt> whose iss matches the requested did and whose aud matches LEONIS_SERVICE_DID.
LEONIS_SERVICE_DID (required when LEONIS_REQUIRE_AUTH=true) DID this service identifies as (e.g. did:web:notifications.example.com). Service-auth JWTs must have a matching aud claim.

Logging is controlled via RUST_LOG (default: info). Logs are emitted as structured JSON.

Running #

Binary #

LEONIS_PDS_URL=wss://pds.example.com cargo run --release

Docker #

docker build -t leonis .

docker run -d \
  -e LEONIS_PDS_URL=wss://pds.example.com \
  -v leonis-data:/data \
  -p 3000:3000 \
  leonis

API #

GET /xrpc/app.bsky.notification.listNotifications #

Returns notifications for a given actor.

Query parameters:

Parameter Type Default Description
did string (required) DID of the actor (did:plc:... or did:web:...)
limit integer 50 Max results per page (capped at 100)
cursor string — Pagination cursor from a previous response
reason string — Filter by reason: reply, mention, quote, follow, like, repost

Response:

{
  "notifications": [
    {
      "uri": "at://did:plc:abc.../app.bsky.feed.post/xyz",
      "cid": "",
      "author": "did:plc:abc...",
      "reason": "reply",
      "reasonSubject": "at://did:plc:def.../app.bsky.feed.post/123",
      "indexedAt": "2026-04-22T12:00:00.000000Z"
    }
  ],
  "cursor": "1745323200000000"
}

Notifications are returned newest-first. The cursor is an opaque string — pass it back to get the next page.

GET /health #

Returns service health status and current actor count.

{"status": "ok", "actors": 12345}

GET /metrics #

Prometheus-format metrics endpoint. Scrape this with Prometheus, Grafana Agent, or any OpenTelemetry collector with a Prometheus receiver.

Exposed metrics:

Metric Type Labels Description
leonis_http_requests_total counter status HTTP request count by status code
leonis_http_request_duration_seconds histogram — Request latency
leonis_notifications_indexed_total counter reason Notifications written to store
leonis_notifications_deleted_total counter — Notifications removed by retention
leonis_events_received_total counter — Jetstream events forwarded to processors
leonis_events_dropped_total counter — Jetstream events dropped (channel full)
leonis_actors_registered gauge — Current actor count
leonis_pds_connected gauge — PDS firehose connection status (0/1)
leonis_jetstream_connected gauge — Jetstream connection status (0/1)
leonis_lazy_enrollments_total counter result Lazy enrollment attempts (enrolled, skipped, failed)

Lazy Enrollment #

When LEONIS_LAZY_ENROLLMENT=true, a request for a DID not yet tracked will trigger an automatic PLC directory lookup to find the actor's PDS. The behavior depends on whether the resolved PDS matches LEONIS_PDS_URL:

  • Home PDS — the DID is enrolled immediately and future interactions are indexed.
  • Foreign PDS — controlled by LEONIS_LAZY_ENROLLMENT_FOREIGN_PDS:
    • ignore (default) — the DID is not enrolled. The request returns an empty result.
    • subscribe — the DID is enrolled individually. Only notifications involving this specific DID are indexed; no backfill of other actors on that PDS occurs.

Storage #

Data is stored in fjall with three partitions:

Partition Contents
actors Enrolled actor DIDs (loaded into an in-memory DashMap on startup)
notifications Notification records keyed by {target_did}\0{reverse_timestamp} for newest-first scans
cursors PDS and Jetstream stream cursors for resume after restart

The data directory layout:

$LEONIS_DATA_DIR/
└── (fjall keyspace files)

Building #

Requires Rust 1.95+.

cargo build --release
cargo test
cargo clippy