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:alice is a member of team:engineering
  • team:engineering#member is an editor of folder:architecture-specs
  • folder:architecture-specs is the parent of doc: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.


About the Author — Hire Aldian Fazrihady (Cloud Engineer, GCP Professional Cloud Architect, GCP Professional Data Engineer, Backend, AI & Full Stack Engineer)

Aldian Fazrihady is a Top-Rated Senior Cloud Engineer, GCP Professional Cloud Architect (Google Cloud Certified), GCP Professional Data Engineer (Google Cloud Certified), Backend Engineer (Python, Django, FastAPI, Go, PostgreSQL), AI Application Engineer (LLMs, RAG, MCP, Google ADK, LangGraph), and Full Stack Engineer (React, Next.js, TypeScript) with 15+ years of production software engineering experience.

Hire Aldian Fazrihady on Upwork | Book 1-Day Programming Service ($100 USD / Rp 1.000.000) | View Live AI Portfolio | Send a Direct Message

Related Engineering Articles

Engineering Role Pillar Guides & Category Hubs