- Authorization checks consistently take >500 ms
- Timeouts occur during peak traffic
- CPU usage in your authorization service is high
- Users notice slow page loads tied to permission checks
Common causes of slow queries
1. Too many authorization paths
Problem: Multiple rules grant the same permission, forcing Oso to evaluate every path. Example: A user can edit a document if they are:- Document owner
- Folder admin (recursive check)
- Organization admin with public access
2. Complex relationship chains
Problem: Deep hierarchies and multiple conditions increase processing time. Example: Access check involves folder parents, team memberships, and role inheritance in a single request.Common performance bottlenecks
Deep folder hierarchies
Scenario: File sharing app with nested folders- 10-level deep folders = 10 database queries
- Global admins trigger expensive “list all” operations
- 5 levels of nesting
- Users with access to many folders
- Frequent bulk “list all” queries
Multiple recursive relationships
Scenario: Document access through both folder hierarchy and team membershipComplex condition chains
Scenario: Admin access to public documents- Check admin role
- Verify document is public
- Get user’s organization
- Match document’s organization
Broad access patterns
Scenario: Super admin listing all accessible documents. Performance impact:- Evaluates thousands of resources
- Large DB scans
- Query optimizer struggles with atypical access patterns
- Global admin roles with organization-wide access
- Service accounts with broad permissions
- Bulk operations across many resources
Optimization strategies
1. Limit recursive depth
- Flatten hierarchies - Keep folder nesting ≤5 levels
- Cache permissions - Cache computed permissions per level
- Use direct permissions - Grant direct permissions for frequently used resources
2. Reduce authorization paths
- Consolidate roles - Merge similar toles
- Prioritize paths - Put most common rules first
- Remove redundant rules - Eliminate overlapping permission grants
3. Optimize for common queries
- Profile query patterns - Identify your most common authorization checks
- Add targeted facts - Pre-compute permissions for frequent queries
- Use Local Authorization - Query your database directly
4. Handle broad access carefully
- Separate admin interfaces - Don’t mix admin and end-user queries
- Paginate results - Limit bulk operations
- Cache admin permissions - Store broad access patterns
Monitor and test performance
Track key metrics
- Average response time - Target
<100ms
for simple queries - 95th percentile latency - Identify slow outliers
- Query frequency - Identify optimization targets
- Error rates - Spot timeouts
Use Oso Cloud logs
- Open the Logs page
- Filter for slow queries
- Identify patterns by user, resource, or rule
Load test scenarios
- Typical user
- Admin with broad access
- Bulk operations
- Deep hierarchy navigation
How Oso processes a query
- Policy Compilation - Convert your policy to internal format (cached)
- Policy Evaluation - Identify required data
- Data Query - Execute SQL against your facts
- Result Assembly - Return allow/deny decision
Related guides
- Local Authorization - Query your database directly for better performance
- Debugging guide - Identify specific performance bottlenecks
- Policy patterns - Learn efficient modeling strategies