Raven
Architecture
System design and data flow for Raven
Raven is a Python 3.13 ConnectRPC ASGI service that serves the desktop client using the Connect Protocol (JSON) over HTTP/2.
System context
Raven desktop app -> Raven (ConnectRPC/ASGI) -> Spanner
|-> Bubble APIs (login/SSO)
|-> Firebase Admin (custom tokens)
|-> Secret Manager (Bubble token, OIDC client id)Service layout
services/raven/
main.py ASGI entrypoint + lifespan
config/ Settings + .env loading
core/ Domain logic (auth, search, SSO, repository)
tests/ Unit and integration testsRequest flow
- Desktop app calls an RPC method (Connect/JSON over HTTP/2).
AuthInterceptorverifies Firebase ID tokens and injects claims.- Raven delegates to core services (search engine, SSO, or pet benefits).
- Responses are serialized as Connect Protocol JSON.
Components
services/raven/main.py: ASGI entrypoint and lifespan handling.services/raven/core/runtime.py: Connect app wiring + lifecycle.services/raven/core/engine.py: patient search orchestration.services/raven/core/repository.py: Spanner queries + search indexes.services/raven/core/bubble_client.py: Bubble login + SSO.services/raven/core/auth.py: Firebase Admin token management.services/raven/core/interceptors.py: auth and request context.services/raven/core/sso_service.py: Microsoft OIDC validation and SSO login.services/raven/core/pet_benefits.py: Pet benefits aggregation.
Auth and identity
- All RPCs except
Login,SSO, andSSOLoginrequire a Firebase ID token. AuthInterceptorvalidates the token and enforces anorganization_idclaim.LoginandSSOLoginmint Firebase custom tokens and set org claims.
Patient search pipeline
QueryClassifiernormalizes the raw query.SearchQueryContextgates probes (code vs. name vs. contact matches).SpannerPatientSearchRepositoryruns a multi-probe SQL query with index hints.PatientSearchEnginededupes, ranks, and maps results to proto messages.- Results are returned as
PatientSearchResponseor streamed in batches.
Streaming search
stream_patient_searchuses a coordinator to manage START/CANCEL commands.- Search results stream in phases: RUNNING, RESULTS, DONE, CANCELLED, ERROR.
- Batch sizing is controlled by
SEARCH_STREAM_BATCH_SIZE.
SSO and login flow
- Bubble APIs validate credentials and return organization context.
- Microsoft OIDC validation runs only when
MICROSOFT_CLIENT_IDis configured. - Firebase Admin mints tokens and adds
organization_idcustom claims.
Pet benefits
- Pet benefits are resolved via Bubble tables in Spanner (
bubble_pet,bubble_subscriptions,bubble_petBenefit,bubble_benefit,bubble_product). - The service short-circuits to empty responses when membership data is missing.
Reliability and scaling
- Spanner pool is warmed at startup and cleared on shutdown.
- Cloud Run is configured for h2c (HTTP/2 cleartext) on port 8080.
- Search performance depends on required Spanner search indexes.
- Search queries use optional exact staleness to reduce tail latency.
Last updated on