Design a Scalable IAM Platform for Users and Services
System DesignModel answerLast updated
Design a multi-tenant Identity and Access Management system with SPIFFE-style workload attestation, dynamic RBAC/ABAC policy evaluation, local enforcement, and tamper-evident auditing.
Design an enterprise-grade Identity and Access Management (IAM) platform serving multi-tenant SaaS environments and internal microservice infrastructure.
The platform must manage authentication (verifying who an entity is) and authorization (verifying what an entity can do) across human operators and automated workload instances.
Core Requirements
- Multi-Tenant & Resource Hierarchy: Support nested structures (e.g., Organization $\rightarrow$ Folder $\rightarrow$ Project $\rightarrow$ Resource) where policies defined on parent containers naturally apply to downstream resources.
- Hybrid RBAC + ABAC Access Control: Support role-based permission grouping alongside dynamic attribute conditions (e.g., origin network, environment tag, time window).
- Short-Lived Workload Credentials: Issue identity tokens to microservices using cryptographic attestation, eliminating long-lived static API secrets. Avoid embedding permission lists in tokens.
- Sub-Millisecond Enforcement Latency: Execute runtime access checks with extreme performance ($p99 < 1\text{ ms}$) at high throughput ($1\text{M+ checks/sec}$).
- Auditing & Rapid Revocation: Maintain an immutable, tamper-evident record of security events and propagate identity revocations across the global fleet within 60 seconds.
Expected Technical Scope
- High-level architecture separating control plane operations from data plane execution.
- Entity data model, resource URN schema, and JWT token payload design.
- End-to-end authentication and delegation flows (human OIDC, workload attestation, on-behalf-of delegation).
- Policy evaluation algorithm and real-time policy cache propagation strategy.
- Failure modes, operational trade-offs, and key rotation lifecycle.
Hints
Hint 1
Decouple identity verification (AuthN) from access permission evaluation (AuthZ). Avoid placing mutable authorization permissions directly inside signed identity tokens.
Hint 2
Distinguish the control plane (persisting policies with strong consistency) from the data plane (evaluating authorization with local snapshot caches).
Hint 3
Use a hierarchical resource model where policies bound to parent nodes propagate down to child resources unless explicitly overrode by a deny rule.
Model answer
Hard Try it yourself first — then compare your approach, complexity and edge cases.
System Architecture Overview
An Identity and Access Management (IAM) platform sits on the hot path of every API interaction. A resilient IAM design cleanly separates two core functional planes:
- Control Plane: Handles identity administration, tenancy management, role assignments, policy edits, and audit persistence. It favors strong consistency and ACID guarantees over sub-millisecond responsiveness.
- Data Plane: Handles token validation, workload identity attestation, and real-time authorization checking. It favors extreme availability and sub-millisecond evaluation latency, running directly adjacent to target services.
+-----------------------------------+
| Admin UI / CLI / API |
+-----------------------------------+
|
v
+-----------------------------------------------------------------------+
| CONTROL PLANE |
| |
| +--------------------+ +--------------------+ +---------------+ |
| | Tenant/User Mgmt | | Policy Management | | Key Manager | |
| +--------------------+ +--------------------+ +---------------+ |
| | | | |
| +------------------------+----------------------+ |
| v |
| Primary DB (Strong Consistency) |
+-----------------------------------------------------------------------+
|
CDC Engine (e.g., Kafka / Debezium)
|
v
+-----------------------------------------------------------------------+
| DATA PLANE |
| |
| +-----------------------+ +-----------------------+ |
| | Attestation Service | | Policy Sync Gateway | |
| +-----------------------+ +-----------------------+ |
| | | |
| +-------------------+-------------------+ |
| v |
| In-Memory Snapshot Cache |
| | |
| +---------------------------+---------------------------+ |
| | | |
| v v |
| +------------------------+ +------------------------+ |
| | Local PDP (Sidecar / | | Local PDP (Sidecar / | |
| | Embedded Library) | | Embedded Library) | |
| +------------------------+ +------------------------+ |
| | | |
| v v |
| +------------------------+ +------------------------+ |
| | Microservice A (PEP) | -- (mTLS) -->| Microservice B (PEP) | |
| +------------------------+ +------------------------+ |
+-----------------------------------------------------------------------+
1. Capacity & Scale Assumptions
- Tenancy Hierarchy: ~10,000 corporate organization tenants organized into arbitrary parent-child structures.
- Identities: 1,000,000 human user accounts; 50,000 unique service definitions running across 200,000 active compute instances (containers/VMs).
- Evaluation Throughput: System-wide peak of 1,000,000+ authorization checks/second.
- Latency SLAs:
- Local sidecar policy decision: $p99 < 0.5\text{ ms}$.
- Centralized RPC fallback decision: $p99 < 5\text{ ms}$.
- Token Issuance Rate: 200,000 workload instances refreshing credentials every 10 minutes $\approx$ 333 QPS steady-state, designed to absorb 3,000 QPS burst peak.
- Policy Propagation: Policy updates must reach every execution sidecar within < 3 seconds.
2. API Specifications
Data Plane APIs (Runtime Execution)
POST /v1/auth/token- Exchanges valid workload attestation data or human OIDC authorization codes for short-lived access credentials.
POST /v1/auth/token/exchange(RFC 8693)- Exchanges an incoming caller identity token for a downscoped, target-audience identity token during cross-service RPC calls.
POST /v1/authorize- Payload:
{ principal_id, action, resource_urn, context_attributes } - Response:
{ decision: "ALLOW" | "DENY", matching_policy_id: "pol_99b", revision: 1042 }
- Payload:
GET /.well-known/jwks.json- Serves current public JSON Web Key Sets used to verify identity signatures locally.
Control Plane APIs (Administrative Management)
PUT /v1/tenants/{tenant_id}/policies/{policy_id}- Upserts policy definitions using optimistic concurrency control (
If-Match: "etag_value").
- Upserts policy definitions using optimistic concurrency control (
POST /v1/tenants/{tenant_id}/bindings- Binds a specific role to a principal or group over a designated resource hierarchy node.
POST /v1/admin/revoke-principal- Immediately revokes active refresh tokens, invalidates cache states, and broadcasts session termination signals across all nodes.
3. Data Model & Entity Schema
Resources use a canonical Uniform Resource Name (URN) structure to enable tree-based inheritance checks:
urn:platform:{tenant_id}:{project_id}:{service_name}:{resource_type}/{resource_id}
+-------------------+ +-------------------+
| Tenant | | Resource |
+-------------------+ +-------------------+
| id (PK) | | urn (PK) |
| name |<----------| tenant_id (FK) |
| parent_id (FK) | | parent_urn (FK) |
+-------------------+ +-------------------+
^ ^
| |
+-------------------+ +-------------------+
| Principal | | Role Binding |
+-------------------+ +-------------------+
| id (PK) | | id (PK) |
| tenant_id (FK) | | resource_scope |---| (References URN scope)
| type (USER/SVC) | | role_id (FK) |---|
| external_id | | principal_id (FK) |---| (References Principal)
+-------------------+ | condition_expr |
^ +-------------------+
| |
+-------------------+ v
| Group Member | +-------------------+
+-------------------+ +-------------------+
| group_id (FK) | | Role |
| principal_id (FK) | +-------------------+
+-------------------+ | id (PK) |
| permissions[] |
+-------------------+
Key Relational Structure
- Principal: An active actor (User or Service Workload).
- Role Binding: Connects a
Principal(orGroup) to aRoleconstrained by aresource_scopenode and an optional Common Expression Language (CEL) attribute condition. - Deny Policy: Overriding rules evaluated prior to standard grant bindings to enforce explicit restrictions across entire subtrees.
CREATE TABLE role_bindings (
id UUID PRIMARY KEY,
tenant_id VARCHAR(64) NOT NULL,
resource_scope VARCHAR(255) NOT NULL, -- e.g. "urn:platform:t1:proj_alpha:*"
role_id VARCHAR(64) NOT NULL,
principal_type VARCHAR(16) NOT NULL, -- 'USER', 'SERVICE', 'GROUP'
principal_id VARCHAR(64) NOT NULL,
condition_expr TEXT NULL, -- e.g. "request.time < timestamp('2026-01-01T00:00:00Z')"
created_at TIMESTAMP WITH TIME ZONE DEFAULT CURRENT_TIMESTAMP,
version BIGINT NOT NULL DEFAULT 1
);
CREATE INDEX idx_bindings_scope ON role_bindings (tenant_id, resource_scope);
4. Authentication Flows & Token Strategy
Microservice Authentication (Attestation Flow)
Static long-lived client secrets introduce leakage risks. Instead, services utilize SPIFFE-style short-lived attestation:
- Local Attestation: A workload container boots up and queries its local agent sidecar.
- Platform Evidence Collection: The agent collects platform-attested proof (e.g., signed Kubernetes Service Account Tokens, cloud platform instance identity documents, and container image hashes).
- Validation & Minting: The IAM Attestation Service verifies these platform proofs against registered
WorkloadIdentityrules. - Credential Issuance: Upon successful attestation, the IAM service issues two short-lived credentials:
- An X.509 SVID Certificate (1-hour lifespan) for zero-trust mutual TLS (mTLS).
- A Short-Lived JWT Access Token (10-minute lifespan) signed via asymmetric ES256 keys.
{
"iss": "https://iam.platform.internal",
"sub": "spiffe://platform.internal/ns/prod/sa/payment-service",
"aud": "inventory-service",
"tenant": "tenant_enterprise_99",
"exp": 1740000600,
"iat": 1740000000,
"jti": "b134d101-3fa2-4c2c-a209-7d8fa31519d4",
"act": {
"sub": "user_human_4412"
}
}
Architectural Principle: Do not place permissions/roles directly inside JWT claims. Embedding permissions balloons token header sizes and freezes stale authorization rights for the entire life of the token. Tokens establish Identity only; permissions are evaluated dynamically at access time.
5. Policy Evaluation Algorithm
Authorization uses a Policy Enforcement Point (PEP) + Policy Decision Point (PDP) model.
- PEP: The API Gateway, Service Mesh sidecar (Envoy), or internal RPC middleware that intercepts incoming traffic.
- PDP: A lightweight in-memory engine (embedded library or local sidecar daemon) that computes decision results using pre-cached policy trees.
Incoming Request (Principal, Action, Resource, Context)
|
v
[ Collect Principal Identifiers ]
(User ID + Transitive Group IDs)
|
v
[ Build Resource Scope Path ]
(e.g., [/org_1/proj_a/db_1, /org_1/proj_a, /org_1, *])
|
v
+---------------------------+
| Matches Explicit DENY |
| Rule along Path? |
+---------------------------+
/ \
YES / \ NO
v v
[ Return DENY ] +---------------------------+
| Matches ALLOW Binding & |
| Evaluates Condition TRUE? |
+---------------------------+
/ \
YES / \ NO
v v
[ Return ALLOW ] [ Return DENY ]
Local Policy Indexing Structure
To maintain sub-millisecond execution target ($<0.5\text{ ms}$), the PDP index builds an in-memory hash map lookup structure:
$$\text{Index Key: } (\text{TenantID}, \text{PermissionVerb}) \longrightarrow \text{Radix Tree of Resource Scope Paths}$$
When evaluating orders.read on urn:platform:t1:p1:order-service:order/99:
- The PDP queries its local map for
orders.read. - It performs a radix tree matching lookup against the resource scope hierarchy.
- If any matched node satisfies the attached CEL attribute condition, access is granted—unless an explicit DENY entry matches the subtree.
6. Policy Snapshot Synchronization & Revocation
To achieve low-latency evaluation without central database queries on every RPC, policy trees are streamed out to edge PDP daemons.
+------------------+ +--------------------+ +-----------------------+
| Primary DB | | CDC / Debezium | | Kafka Bus |
| (Policy Write) | ------> | (Capture Changes) | ------> | "iam-policy-updates" |
+------------------+ +--------------------+ +-----------------------+
|
v
+------------------+ +--------------------+ +-----------------------+
| Local PDP Cache | <------ | Local PDP Agent | <------ | Policy Dist. Gateway |
| (In-Memory Index)| | (Pulls Delta/Sync) | | (Aggregates & Fans) |
+------------------+ +--------------------+ +-----------------------+
- Change Data Capture (CDC): Admin policy updates committed to the primary database trigger CDC events via Debezium into a Kafka topic partitioned by
tenant_id. - Policy Distribution Gateway: Consolidates changes into compressed versioned delta chunks.
- Edge Streaming: Local PDP daemons maintain a persistent gRPC stream to the distribution gateway. Updates apply to memory in under 3 seconds globally.
- Rapid Revocation Handling:
- Session/Token Revocations generate high-priority invalidation messages published directly to a fast distributed cache (Redis Pub/Sub or local bloom filter sidecar sync).
- If an edge PDP loses connectivity to the control stream for longer than its max stale threshold (e.g., 30 seconds), it trips a circuit breaker and falls back to synchronous calls to the centralized IAM data plane service.
7. Auditing, Cryptography, and Key Rotation
Tamper-Evident Audit Logging
Audit logs are written to an append-only, hash-chained log stream. Each event stores a cryptographic signature chaining back to the hash of the preceding record:
$$\text{Hash}n = \text{HMAC-SHA256}\left(\text{SecretKey}, \text{Hash}{n-1} \parallel \text{EventData}_n\right)$$
- Logs capture administrative actions (policy updates, role binds) and rejected authorization attempts.
- Periodically, the current log tail hash is posted to an external immutable ledger or cloud write-once-read-many (WORM) storage bucket for legal non-repudiation.
Key Lifecycle Management
- Asymmetric Signing: Access tokens use ES256 (ECDSA using P-256 and SHA-256).
- Key Rotation Schedule:
- Public signing keys rotate every 30 days.
- The system retains public keys in the
jwks.jsonendpoint for 90 days (RETIRINGstate) to allow smooth validation transitions across active tokens. - Active keys carry a unique Key ID (
kid) header in JWT payloads for dynamic verification lookup.
8. Failure Modes & Architecture Trade-offs
| Scenario | Potential Risk | Mitigation / Fail-Safe Strategy |
|---|---|---|
| Control Plane DB Failure | Inability to edit policies or register new services. | Fail-Static Design: Data Plane PDPs continue serving reads using their last-known valid snapshot. Existing runtime traffic remains uninterrupted. |
| Policy Sync Stream Partition | Edge PDPs drift out of date relative to recent admin changes. | PDPs mark their state stale after 30s of disconnected streaming. If staleness exceeds threshold, fall back to synchronous remote AuthZ checks. |
| Local PDP Memory Exhaustion | Large tenants with millions of unique resource bindings exceed sidecar memory limits. | Implement hierarchical scope prefixing. Edge PDPs only load policy sets relevant to their local microservice's tenant boundaries rather than global state. |
| Compromised Service Identity | An attacker gains control of a service pod's credentials. | Enforce short 10-minute maximum token lifetimes, issue mTLS certificates tied to specific workload attestations, and support targeted principal revoking. |
Key Design Trade-offs
- Stateful Central Engine vs. Local PDP Sidecars:
- Centralized: Simpler operational complexity, but adds 2–5 ms latency network overhead to every internal microservice RPC and creates a massive centralized bottleneck.
- Local PDP (Chosen): Sub-millisecond evaluation and high availability, at the cost of managing edge cache synchronization streams and eventual consistency windows (up to 3s propagation lag).
- Coarse-Grained Tokens vs. Self-Contained JWT Claims:
- Self-Contained Claims: Faster initial validation without policy lookups, but results in bloated payload sizes and impossible real-time access revocation.
- Identity-Only Tokens (Chosen): Compact payload footprint and instant access revocation support, requiring efficient local PDP caching engines to run permission lookups dynamically.