Caching Authorization Decisions
What you'll learn: How to cache permission checks to reduce latency while maintaining security correctness.
The Core Problem
Every time a user requests a protected resource, your system must ask "Is this user allowed to do this?" Hitting your Policy Decision Point (PDP) or authorization service for every single request creates latency and load. But caching authorization decisions introduces a critical risk: serving stale permissions after they've been revoked.
How Authorization Caching Works
Authorization caching stores the result of permission checks temporarily, so repeated requests for the same resource by the same user skip the expensive PDP lookup.
Example flow:
- User requests
/api/documents/123 - Check cache:
user:alice:read:doc123→ cache miss - Query PDP: "Can Alice read document 123?" → Yes
- Cache result with TTL (e.g., 60 seconds)
- Next request within 60s returns cached "Yes" instantly
Critical Design Considerations
TTL balancing: Shorter TTLs (5-60 seconds) reduce staleness risk but increase PDP load. Longer TTLs improve performance but delay permission revocation enforcement.
Cache key structure: Include user ID, action, and resource. For RBAC, you might cache role memberships separately from resource permissions.
Invalidation strategy: When permissions change, proactively invalidate affected cache entries rather than waiting for TTL expiration. This requires your authorization system to publish permission-change events.
Security requirements matter: High-security operations (financial transactions, admin actions) may skip caching entirely. Read-heavy, low-risk operations benefit most from caching.
Where to cache: At the Policy Enforcement Point (PEP) in each service, at the API Gateway, or in a shared cache like Redis. Service-local caches reduce network hops but complicate invalidation.
Key Takeaway: Cache authorization decisions with short TTLs for performance, but implement cache invalidation and limit caching to low-risk operations where brief staleness is acceptable.