Backend & Cloud Engineer Guide: Fine-Grained ReBAC Authorization (Zanzibar / OpenFGA)
Simple role checks (if user.role == "admin":) work for basic apps, but they collapse as soon as enterprise customers ask for Google Drive or GitHub-style permissions: "A user can view a Document if they are an direct viewer of the Document, OR an editor of its parent Folder, OR a member of a Team that owns the Workspace." Hardcoding recursive SQL joins across folders, teams, and external guest shares in every API endpoint leads to slow queries and permission bypass bugs. As a Senior Backend Engineer and Cloud Engineer, I implement fine-grained Relationship-Based Access Control (ReBAC) inspired by Google Zanzibar (OpenFGA / SpiceDB / PostgreSQL Tuple Graphs).
1. Modeling Permissions as Zanzibar Relationship Tuples (`user`, `relation`, `object`)
In a Zanzibar-style authorization model, every permission grant is stored as a normalized relationship tuple of the form (user, relation, object):
user:aliceis amemberofteam:engineeringteam:engineering#memberis aneditoroffolder:architecture-specsfolder:architecture-specsis theparentofdoc:cloud-run-blueprint
# OpenFGA / Zanzibar Authorization Model Definition (DSL)
model
schema 1.1
type user
type team
relations
define member: [user]
type folder
relations
define owner: [user, team#member]
define editor: [user, team#member] or owner
define viewer: [user, team#member] or editor
type document
relations
define parent: [folder]
define editor: [user, team#member] or editor from parent
define viewer: [user, team#member] or editor or viewer from parent
2. Solving the "List Authorized Objects" Pagination Problem
Checking a single permission (Check(user:alice, viewer, doc:123)) takes under 3 milliseconds, but rendering a paginated table of 50 documents Alice is allowed to see out of 1,000,000 rows cannot be done by calling Check() 1,000,000 times. I architect hybrid pre-filtering: scoping the primary SQL query by tenant/workspace index first and intersecting with OpenFGA/SpiceDB ListObjects or materialized closure tables in PostgreSQL.
3. Hire a Senior Backend & Cloud Engineer for Enterprise Authorization
Designing fine-grained RBAC, ABAC, or Zanzibar ReBAC permissions for your SaaS platform or AI RAG pipeline? Explore my Backend Engineer Pillar Guide, review my Multi-Tenant SaaS Isolation & RLS Guide, or book a 1-Day Authorization Architecture Sprint.