Bird
Raised Fist0

Security Fundamentals - AuthN, AuthZ, Encryption at Rest and in Transit

HLDmediumInterview freq: high
Choose your preparation mode4 modes available
🏗️
Security Fundamentals - AuthN, AuthZ, Encryption at Rest and in Transit
Designing scalable, secure authentication, authorization, and encryption for 2B DAU systems
mediumNon-Functional Requirements FrameworkFreq: high
⚙️
Functional Requirements
  • User Authentication: Support secure login via OAuth 2.0 and multi-factor authentication (MFA).
  • User Authorization: Enforce fine-grained access control using Role-Based Access Control (RBAC) and Attribute-Based Access Control (ABAC).
  • Encryption at Rest: Encrypt all sensitive data stored in databases and object storage using AES-256 with key management.
  • Encryption in Transit: Use TLS 1.3 for all client-server and inter-service communication.
  • Audit Logging: Maintain immutable logs of authentication and authorization events for compliance and forensic analysis.
  • Token Management: Issue, validate, and revoke JWT tokens with short TTL and refresh tokens.
📊
Non-Functional Requirements
  • Availability: 99.99% uptime SLA for AuthN/AuthZ services to avoid user lockout.
  • Latency: Authentication and authorization checks must complete within 100ms P99 to avoid user experience degradation.
  • Scalability: Support 2 billion DAU with peak write QPS of ~925K and read QPS of ~10M for token validation and permission checks.
  • Security Compliance: Meet GDPR, HIPAA, and SOC 2 requirements for data encryption and auditability.
  • Durability: Audit logs and encryption keys must be stored durably with replication and backups.
❓
Clarifying Questions to Ask
  • What authentication methods must be supported beyond OAuth 2.0 and MFA?
  • What is the expected token TTL and refresh token policy?
  • Are there specific compliance standards (e.g., GDPR, HIPAA) that must be met?
  • What is the expected peak concurrency and QPS for authorization checks?
  • Should encryption keys be rotated automatically, and at what frequency?
  • Is audit logging required to be tamper-proof or stored offsite?
Out of Scope
✗ User profile management and social graph services.
✗ Business logic authorization beyond core RBAC/ABAC enforcement.
✗ Physical hardware security modules (HSM) provisioning and management.
✗ Client-side encryption or zero-knowledge encryption schemes.
📌
Assumptions
  • 2 billion DAU
  • 40 authentication/authorization requests per user per day
  • 100 bytes average size per auth event log entry
  • Token TTL of 15 minutes with refresh tokens
⚡
QPS Calculation
write qps2B users × 40 auth events/day ÷ 86400 sec ≈ 925,926 writes/sec
peak write qpsAssuming 3× peak factor: 925,926 × 3 ≈ 2.78M writes/sec
read qpsAuthorization checks are more frequent; estimate 10× writes: 9.25M reads/sec
💾
Storage Estimate
daily storage2B × 40 × 100 bytes = 8 TB/day
retention days90
total storage8 TB × 90 days = 720 TB
with replication720 TB × 3 (replication factor) = 2.16 PB
🖥️
Server Estimate
auth serviceAssuming 10K RPS per server, peak 2.78M writes/sec requires ~278 auth servers
token cacheUsing Redis with 100K ops/sec per node, 9.25M reads/sec requires ~93 Redis nodes
🏗️
Architecture Diagram
Architecture Diagram
          +----------------+
          |   Client App   |
          +-------+--------+
                  | TLS 1.3
                  v
          +-------+--------+
          | AuthN Service  |
          +-------+--------+
                  |
                  | OAuth 2.0 / JWT
                  v
          +-------+--------+
          | Token Service  |
          +-------+--------+
                  |
                  | Validate / Issue Tokens
                  v
          +-------+--------+
          | AuthZ Service  |
          +-------+--------+
                  |
                  | RBAC/ABAC Checks
                  v
          +-------+--------+
          | Policy Store   |
          +-------+--------+
                  |
                  | Encrypted Storage (AES-256)
                  v
          +-------+--------+
          | Audit Logging  |
          +----------------+
🧩
Components
AuthN Service
Handles user authentication via OAuth 2.0 and MFA
Why thisOAuth 2.0 is industry standard with wide client support; MFA adds security layer
Why notCustom auth protocols lack standardization and client ecosystem support
Token Service
Issues, validates, and revokes JWT tokens with short TTL and refresh tokens
Why thisJWT enables stateless token validation reducing DB lookups and latency
Why notOpaque tokens require DB lookups on every request, increasing latency and DB load
AuthZ Service
Enforces fine-grained RBAC and ABAC authorization policies
Why thisCombines RBAC for role simplicity and ABAC for attribute flexibility at scale
Why notPure RBAC lacks flexibility; pure ABAC is complex and slower at scale
Policy Store
Stores encrypted authorization policies and user-role mappings
Why thisApache Cassandra supports linear write scalability and tunable consistency for 925K writes/sec
Why notPostgreSQL B-tree indexes do not scale linearly at this write volume without complex sharding
Audit Logging
Stores immutable logs of auth events for compliance and forensic analysis
Why thisApache Kafka provides durable, ordered, replicated log storage with high throughput
Why notRelational DBs cannot handle 8TB/day write volume with required durability and throughput
Encryption Key Management
Manages AES-256 keys with automatic rotation and secure storage
Why thisHashiCorp Vault provides secure key storage, rotation, and audit logging
Why notManual key management is error-prone and does not scale securely
Redis Token Cache
Caches validated tokens to reduce token validation latency and DB load
Why thisRedis TTL natively expires tokens without cron jobs; sub-millisecond lookup reduces latency
Why notMemcached lacks native TTL expiration and persistence, risking stale tokens
🔄
Data Flow
1
Client App → AuthN Service
User submits credentials over TLS 1.3
Ensures encryption in transit and prevents MITM attacks
2
AuthN Service → Token Service
On successful auth, request JWT token issuance
JWT tokens are stateless and signed for integrity
3
Client App → AuthZ Service
Send JWT token with resource access request
Token validated and permissions checked before access granted
4
AuthZ Service → Policy Store
Fetch authorization policies and user-role mappings
Policies stored encrypted with AES-256 for security
5
AuthZ Service → Audit Logging
Log authorization decisions immutably
Logs used for compliance and forensic analysis

Practice

(1/5)
1. In a Raft consensus system, at Step 4, the Leader sends AppendEntries RPCs to followers. What happens if a follower's log is inconsistent at this step?
easy
A. The follower immediately accepts the entries and overwrites conflicting logs
B. The follower rejects the AppendEntries, prompting the leader to decrement the nextIndex and retry
C. The follower crashes and restarts to recover the log state
D. The follower ignores the AppendEntries and waits for the next heartbeat

Solution

  1. Step 1: Understand Raft's log replication mechanism

    If a follower's log is inconsistent with the leader's, it rejects the AppendEntries RPC to signal a mismatch.
  2. Step 2: Leader's response to rejection

    The leader decrements the nextIndex for that follower and retries AppendEntries until logs match.
  3. Final Answer:

    Option B -> Option B
  4. Quick Check:

    Follower rejects inconsistent logs -> leader retries with decremented nextIndex [check]
Hint: Follower rejects mismatched logs; leader retries with lower index [check]
Common Mistakes:
2. In the CI/CD pipeline request flow, at Step 5 the Deployment Worker receives a build artifact reference and triggers deployment. What happens if the artifact is missing from the artifact registry at this step?
easy
A. Deployment Worker proceeds with last known artifact version silently
B. Deployment Worker retries indefinitely until artifact appears
C. Deployment Worker fails deployment and reports an error to the orchestrator
D. Deployment Worker skips deployment and triggers rollback automatically

Solution

  1. Step 1: Trace Deployment Worker behavior on missing artifact

    The Deployment Worker validates artifact presence before deployment; missing artifact causes failure.
  2. Step 2: Check fallback behaviors

    Retrying indefinitely would block pipeline; proceeding silently risks inconsistency; automatic rollback is triggered only after failed deployment, not missing artifact.
  3. Final Answer:

    Option C -> Option C
  4. Quick Check:

    Deployment Worker fails and reports error on missing artifact [check]
Hint: Missing artifact -> deployment fails, no silent fallback [check]
Common Mistakes:
3. In the request flow of a key-value store, at Step 4 the Gossip Protocol component receives a heartbeat from a node. What state does it update for that node?
easy
A. Updates the node's last known alive timestamp to maintain membership info
B. Marks the node as failed and triggers immediate data rebalancing
C. Resets the vector clock for all keys stored on that node
D. Triggers a consistent hashing ring reshuffle to redistribute keys

Solution

  1. Step 1: Understand Gossip Protocol heartbeat handling

    Gossip updates the membership list by refreshing the last alive timestamp for the node sending the heartbeat.
  2. Step 2: Eliminate incorrect states

    Marking node as failed contradicts receiving heartbeat. Vector clocks are unrelated to node liveness. Consistent hashing ring changes only on node join/leave, not heartbeat.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Heartbeat updates node's alive timestamp in gossip membership [check]
Hint: Heartbeat refreshes node's alive timestamp in gossip membership [OK]
Common Mistakes:
4. A critical database cluster must failover automatically without data loss or downtime during a primary node crash. Which component is responsible for orchestrating this failover in a distributed SQL database system?
easy
A. Consensus protocol (e.g., Raft) managing leader election and log replication
B. Load balancer redirecting traffic based on health checks
C. Client-side retry logic to reconnect to a new primary node
D. Backup scheduler triggering periodic snapshots for recovery

Solution

  1. Step 1: Identify failover orchestration component

    The consensus protocol like Raft manages leader election and ensures log replication consistency, enabling automatic failover without data loss.
  2. Step 2: Eliminate other options

    Client-side retries (A) handle reconnection but don't orchestrate failover; load balancers (B) redirect traffic but don't manage state; backups (D) aid recovery but not live failover.
  3. Final Answer:

    Option A -> Option A
  4. Quick Check:

    Consensus protocol controls leader election and failover [check]
Hint: Consensus protocols manage failover, not clients or load balancers
Common Mistakes:
5. For the Explore page, you must recommend trending photos to users with low latency and high freshness. Which architecture best fits this constraint?
medium
A. Use a batch job that runs every 6 hours to compute trending photos and store results in a database
B. Use a CDN to cache Explore page content globally and invalidate cache every hour
C. Use client-side polling every minute to fetch trending photos from a static cache
D. Use a streaming pipeline that updates trending scores in real-time and stores results in a fast key-value store

Solution

  1. Step 1: Analyze freshness and latency requirements

    Trending photos must be updated with low latency and high freshness, ruling out long batch intervals.
  2. Step 2: Evaluate architectures

    Batch jobs every 6 hours (A) are too stale. Client polling (C) adds load and latency. CDN cache invalidation (D) is coarse-grained and slow. Streaming pipeline (B) updates trending scores in real-time and stores in fast KV store, meeting freshness and latency.
  3. Final Answer:

    Option D -> Option D
  4. Quick Check:

    Streaming pipeline enables real-time trending updates [check]
Hint: Real-time streaming pipelines enable fresh trending data [check]
Common Mistakes:
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard