KatInterview

Designing a Graph-Based Authorization Service and Zero-Downtime Migration

System DesignModel answer
HardModel answerSystem Designsystem-designauthorizationgraph-database

Last updated

Design a scalable graph database schema for user-resource authorization (ReBAC) and plan a zero-downtime migration strategy from a legacy relational system.

Context

Your organization is replacing an existing legacy authorization system (stored in a SQL database) with a Relationship-Based Access Control (ReBAC) service backed by a graph database.

The access model must support:

  • Direct user-to-resource permissions.
  • Indirect permissions via nested user groups (groups containing other groups).
  • Resource hierarchies (e.g., Organization $\rightarrow$ Folder $\rightarrow$ Document) where access to a parent node grants inherited access to child nodes.
  • Multiple permission levels (read, write, admin).
  • Explicit permission revocations/denials that take precedence over granted inherited access.

Requirements

Part 1: Architecture & Graph Schema

  • Define the graph schema (node types, edge types, properties, and indexes).
  • Explain how authorization queries are evaluated:
    1. check_permission(user_id, resource_id, required_permission) $\rightarrow$ boolean
    2. list_accessible_resources(user_id, permission) $\rightarrow$ List<resource_id>
  • Detail how explicit denials, nested groups, and inheritance are handled in traversals while avoiding unbounded path explosion.

Part 2: Performance & Scalability

  • Design a caching strategy to meet strict latency targets ($< 10\text{ ms}$ for $p99$ access checks) under a read-heavy workload ($100,000\text{ read queries/sec}$ vs. $500\text{ permission updates/sec}$).
  • Describe invalidation strategies for cached decisions when deep nested hierarchies or high-degree nodes ("supergroups" or root folders) change.
  • Address graph partitioning (sharding) strategies to prevent cross-machine traversal bottlenecks.

Part 3: Zero-Downtime Migration Strategy

  • Outline a step-by-step migration plan from the legacy relational database to the graph database without service downtime.
  • Detail dual-writing, data reconciliation, shadow reading, and fallback/rollback mechanisms.

Hints

Hint 1

Consider how directed edges represent group membership versus resource containment. Standardize edge direction to make traversals single-directional (e.g., User -> Group -> Resource vs Resource -> Group -> User).

Hint 2

Think about how explicit DENY nodes or properties alter traversal semantics. A breadth-first search (BFS) or depth-first search (DFS) must process denials before resolving granted access.

Hint 3

For high-scale caching, caching individual edge operations vs. caching fully resolved reachability decisions (e.g., bitsets or path tokens) has major trade-offs during cache invalidation.