Tutorials Courses Interview Prep (100 Q&A) AI Tools (50) Developer Tools (50) Tracks Pricing Plans Blog & Articles Contact Us
Open-Access Production Interview Prep

Senior & Lead Engineer Interview Mastery Hub

100 real-world, scenario-based architecture & concurrency questions designed for 5–10+ years experienced developers. Free & open for every student and engineer.

100

Real-world Q&As

100%

Scenario-Based

5-10 Yrs

Senior / Lead Depth

5 Stacks

Core Technologies

Showing 20 questions for senior interview preparation

•
System Design, Redis & Distributed Systems 10+ Years (Principal / Architect) Expert Production Scenario

How does the Redis Redlock Algorithm provide Fault-Tolerant Distributed Locking across independent Redis nodes?

Incident Scenario: A financial settlement system running on 5 distributed microservice nodes needed to acquire mutually exclusive locks without relying on a single Redis master point-of-failure.
45 views • Direct Permalink

Why a Single Redis Master is Insufficient for Strict Distributed Locking

In a standard Master-Replica Redis setup, replication is asynchronous. If the master crashes immediately after granting a lock before replicating to replicas, the promoted replica can grant the exact same lock to a second client, causing catastrophic double-execution.

The Redlock Algorithm Workflow

  1. Client initializes $N$ independent Redis master nodes (e.g. $N=5$).
  2. Client gets current millisecond timestamp $T_1$.
  3. Client attempts to acquire the lock sequentially across all $N$ instances using identical key, random unique value, and TTL (e.g. 10s) with a short timeout (e.g. 50ms) per node.
  4. Client computes elapsed time $Elapsed = T_2 - T_1$.
  5. Lock Acquisition Success: If the client acquired the lock on majority of nodes (>= 3 out of 5) AND $Elapsed < TTL$, the lock is valid for $ValidityTime = TTL - Elapsed$.
  6. Failure & Rollback: If client failed to acquire on majority, it immediately sends an unlock script (Lua EVAL) to all instances, even those where it thought acquisition failed.
Tags: #Redis #Redlock #Distributed Locks #High Availability #Consensus
System Design, Redis & Distributed Systems 8-10 Years (Tech Lead) Hard Production Scenario

Explain the 3 High-Scale Cache Failure Patterns: Cache Avalanche, Cache Breakdown (Dog-Piling), and Cache Penetration, with mitigations.

Incident Scenario: During Black Friday, a major e-commerce backend crashed because 50,000 product cache keys with identical 1-hour TTLs expired at the exact same second.
316 views • Direct Permalink

1. Cache Avalanche (Mass Simultaneous Expiration)

  • Problem: Millions of keys expire at the same instant; massive traffic rushes to the DB.
  • Solution: Add Random TTL Jitter:
    $ttl = 3600 + rand(0, 600); // 60 to 70 minutes randomized expiration
    

2. Cache Breakdown / Dog-Piling (Hot Key Expiry)

  • Problem: A single viral product key expires; 20,000 concurrent requests miss simultaneously.
  • Solution: Distributed Mutex Lock or Background Pre-warming / Stale-While-Revalidate.

3. Cache Penetration (Non-Existent Keys Attack)

  • Problem: Malicious requests query non-existent IDs (id = -9999), bypassing cache and hitting DB on every request.
  • Solution:
    1. Cache Empty Objects / Nulls with short TTL (e.g. 60 seconds).
    2. Bloom Filter: Use Redis Bloom filter to determine in $O(1)$ whether an ID could possibly exist before querying database.
Tags: #Cache Avalanche #Cache Breakdown #Cache Penetration #Bloom Filter #Redis
System Design, Redis & Distributed Systems 8-10 Years (Tech Lead) Hard Production Scenario

Compare Rate Limiting Algorithms: Token Bucket, Leaky Bucket, Fixed Window Counter, and Sliding Window Log/Counter.

Incident Scenario: Designing an enterprise API gateway protecting downstream microservices from traffic spikes while allowing legitimate burst traffic.
471 views • Direct Permalink

Comparison Matrix

Algorithm Pros Cons Ideal For
Token Bucket Allows bursts up to bucket capacity, smooth refills Memory state tracking required API Gateways (Stripe / GitHub style)
Leaky Bucket Guarantees constant, smooth output rate Discards bursts if queue full Egress traffic shaping
Fixed Window Low memory Boundary spikes (2x burst at window edges) Basic IP throttling
Sliding Window Counter Prevents boundary spikes, memory efficient Approximate calculation High-scale tier limiting

Sliding Window Lua Script in Redis

local key = KEYS[1]
local now = tonumber(ARGV[1])
local window = tonumber(ARGV[2])
local limit = tonumber(ARGV[3])

-- Remove timestamps older than current sliding window
redis.call('ZREMRANGEBYSCORE', key, '-inf', now - window)
local current_count = redis.call('ZCARD', key)

if current_count < limit then
    redis.call('ZADD', key, now, now)
    redis.call('EXPIRE', key, window)
    return 1 -- Allowed
else
    return 0 -- Blocked (HTTP 429)
end
Tags: #Rate Limiting #Token Bucket #Sliding Window #Redis Lua #API Gateway
System Design, Redis & Distributed Systems 10+ Years (Principal / Architect) Expert Production Scenario

How do you design a Real-Time Notification System delivering to 10M concurrent users with WebSockets and Redis Pub/Sub?

Incident Scenario: A flash notification must be pushed to 10 million active web and mobile users within 3 seconds of a global event announcement.
548 views • Direct Permalink

Architectural Blueprint

[Client Socket] ---> [Load Balancer / Nginx] ---> [WebSocket Gateway Cluster (Node/Go/Reverb)]
                                                          ^
                                                          | Redis Pub/Sub Cluster / Kafka
                                                          |
                                                 [Notification Service]

Core Architecture Components:

  1. Stateful Connection Nodes: Gateway instances maintain persistent TCP socket connections and keep a local in-memory lookup map of user_id -> [socket_fd_1, socket_fd_2].
  2. Channel Partitioning in Redis Pub/Sub: Broadcast messages are partitioned by tenant or topic channels (broadcast:global vs user:12345).
  3. Backpressure & Drop Policies: If a client's TCP socket buffer is saturated, drop non-critical status updates to prevent memory exhaustion on the gateway node.
Tags: #WebSockets #Redis Pub/Sub #Kafka #System Design #Scaling
System Design, Redis & Distributed Systems 10+ Years (Principal / Architect) Expert Production Scenario

How do you design an Idempotent Payment Processing Architecture with the Saga Pattern across Microservices?

Incident Scenario: An e-commerce purchase requires 3 microservices: 1) Deduct Inventory, 2) Charge Credit Card, 3) Issue Invoice. How do you ensure consistency if Step 2 succeeds but Step 3 fails?
533 views • Direct Permalink

Choreography vs Orchestration Saga

Because 2-Phase Commit (2PC) blocks distributed databases, distributed systems use Saga Pattern:

  • A sequence of local transactions where each step publishes an event.
  • If any step fails, the Saga executes Compensating Transactions in reverse order (e.g. RefundPayment, RestoreInventory).
[Order Created] -> (Deduct Inventory) -> (Charge Stripe) -> [Invoice Failed]
                                                |
                                                v
                              [Trigger Compensating Action]
                                       Refund Stripe
                                     Restore Inventory
                                    Mark Order Cancelled

Idempotency Keys:

Each step checks if the order_id has already been processed to safely allow retries without duplicate charges.

Tags: #Saga Pattern #Distributed Transactions #Idempotency #Compensating Actions
System Design, Redis & Distributed Systems 8-10 Years (Tech Lead) Hard Production Scenario

How does the Circuit Breaker Pattern prevent cascading failures in Microservice architectures?

Incident Scenario: When a downstream third-party shipping API slowed down to 30s per request, all upstream web servers exhausted their thread pools and crashed.
59 views • Direct Permalink

The 3 States of Circuit Breaker

  1. Closed: Normal state. Requests pass through. Tracks failure rate.
  2. Open: If failure rate exceeds threshold (e.g. 50% over 10s), the circuit trips to OPEN. Requests fail immediately with a fallback response without calling the slow downstream service.
  3. Half-Open: After a cooldown period (e.g. 30s), a limited trial number of requests are allowed through. If they succeed, circuit resets to CLOSED; if they fail, it returns to OPEN.
Tags: #Circuit Breaker #Resilience #Fault Tolerance #Microservices
System Design, Redis & Distributed Systems 5-8 Years (Senior) Hard Production Scenario

How do you design a Global URL Shortener (Bitly-scale) handling 100M URLs and 10 Billion clicks/month?

Incident Scenario: Interview system design question: Design a short link redirection engine with sub-10ms response times globally.
179 views • Direct Permalink

Key Architecture Decisions

  1. Base62 Encoding: [a-z, A-Z, 0-9]. A 7-character string allows $62^7 \approx 3.5 \text{ trillion}$ unique URLs.
  2. Distributed ID Generator (Snowflake / Redis Atomic Counters): Generate unique 64-bit auto-incrementing integer -> Convert to Base62.
  3. Caching & CDN:
    • Return HTTP 302 (Temporary Redirect) if click tracking analytics are required on every hit.
    • Return HTTP 301 (Permanent Redirect) if latency is prioritized (browser caches redirect permanently).
    • Cache hot 20% of URLs in Redis cluster (80/20 Pareto principle).
Tags: #System Design #Base62 #URL Shortener #Distributed ID
System Design, Redis & Distributed Systems 8-10 Years (Tech Lead) Hard

Explain the CAP Theorem and PACELC Theorem with real-world database trade-offs.

Incident Scenario: Evaluating whether Cassandra, DynamoDB, or CockroachDB is the right storage engine for globally distributed user carts.
265 views • Direct Permalink

CAP Theorem: Consistency, Availability, Partition Tolerance

In the presence of a Network Partition ($P$), a distributed system must choose between:

  • $CP$ (Consistency): Reject writes to maintain data accuracy (e.g. Redis Cluster, MongoDB, HBase).
  • $AP$ (Availability): Accept writes on both sides of partition; resolve conflicts later (e.g. DynamoDB, Cassandra).

PACELC Theorem (Extending CAP for Normal Operations)

If Partition ($P$): Choose between Availability ($A$) or Consistency ($C$). Else ($E$): Choose between Latency ($L$) or Consistency ($C$).

Tags: #CAP Theorem #PACELC #Distributed Databases #Consistency
System Design, Redis & Distributed Systems 5-8 Years (Senior) Medium Production Scenario

How do you implement Async Worker Retries with Exponential Backoff and Dead Letter Queues (DLQ)?

Incident Scenario: A bank webhook was temporarily offline; retrying failed webhook jobs every 1 second overwhelmed the receiving server and wasted CPU cycles.
553 views • Direct Permalink

Exponential Backoff with Jitter

$retryDelay = min(3600, pow(2, $attemptCount) * 10 + rand(0, 5));
  • Attempt 1: 20s
  • Attempt 2: 40s
  • Attempt 3: 80s
  • Max Retries Exceeded: Route the failed payload to a Dead Letter Queue (DLQ) for automated alerting and manual developer replay.
Tags: #Dead Letter Queue #Exponential Backoff #Queues #Resilience
System Design, Redis & Distributed Systems 8-10 Years (Tech Lead) Hard Production Scenario

How do you design a High-Scale Distributed Counter for Millions of Video Views or Upvotes?

Incident Scenario: Directly updating `UPDATE videos SET views = views + 1 WHERE id = 5` under 50,000 views/sec caused database row lock saturation.
331 views • Direct Permalink

Sharded Counters / Write-Back Buffering

  1. Redis Atomic Increment:
    Redis::incr("video:views:{$videoId}");
    
  2. Batch Flusher Daemon: Every 10 seconds, a background worker consumes the aggregated count from Redis via INCRBY and writes a single consolidated SQL update:
    UPDATE videos SET views = views + 5000 WHERE id = 5;
    

Reduces database write operations by 99.9%.

Tags: #Counters #Redis INCRBY #Write-Back Cache #High Concurrency
System Design, Redis & Distributed Systems 10+ Years (Principal / Architect) Hard Production Scenario

How does Consistent Hashing minimize data movement during Cache Cluster node addition or removal?

Incident Scenario: Adding a 5th Memcached server caused 80% of existing cache keys to remap and miss simultaneously using standard `hash(key) % N`.
786 views • Direct Permalink

Consistent Hashing Ring

  1. Maps both Cache Servers and Keys onto a 360-degree circular hash ring (e.g. 0 to $2^{32}-1$).
  2. A key is assigned to the nearest server located clockwise on the ring.
  3. When a server is added or removed, only $K/N$ keys need remapping, preventing total cache thrashing.
  4. Virtual Nodes: Assigns multiple virtual points per physical server to ensure even distribution across nodes.
Tags: #Consistent Hashing #Virtual Nodes #Caching #Distributed Systems
System Design, Redis & Distributed Systems 5-8 Years (Senior) Medium Production Scenario

Explain the Difference between Polling, Long-Polling, Server-Sent Events (SSE), and WebSockets.

Incident Scenario: Selecting the most efficient realtime communication protocol for live stock price tickers vs bi-directional collaborative canvas editing.
48 views • Direct Permalink

Protocol Comparison

Protocol Direction Overhead Ideal Use Case
Short Polling Client -> Server High (repetitive HTTP headers) Simple status checks
Long Polling Client -> Server (held open) Medium Fallback when WebSockets blocked
Server-Sent Events (SSE) Server -> Client Only Very Low (Standard HTTP) Live Feed, Stock Tickers, AI Streaming text
WebSockets Full Duplex Bi-directional Minimal (Single TCP handshake) Multiplayer Games, Chat, Collaborative Editing
Tags: #SSE #WebSockets #Long Polling #Protocols
System Design, Redis & Distributed Systems 10+ Years (Principal / Architect) Expert Production Scenario

How do you design a Resilient Multi-Region Disaster Recovery architecture (Active-Active vs Active-Passive)?

Incident Scenario: Ensuring a SaaS application survives a complete AWS region outage with under 1 minute Recovery Time Objective (RTO) and zero Recovery Point Objective (RPO).
440 views • Direct Permalink

Active-Active vs Active-Passive

  • Active-Passive (Warm Standby): Primary region handles 100% traffic. Secondary region replicates data. DNS failover (Route 53) flips traffic if primary fails. RTO: 2-5 mins.
  • Active-Active (Multi-Region): Both US-East and EU-Central serve local traffic. Requires globally distributed conflict-free replicated data types (CRDTs) or distributed database like CockroachDB / Spanner.
Tags: #Disaster Recovery #Active-Active #RTO/RPO #Multi-Region
System Design, Redis & Distributed Systems 8-10 Years (Tech Lead) Hard Production Scenario

How does Log Aggregation and Distributed Tracing work with OpenTelemetry, Jaeger, and ELK Stack?

Incident Scenario: A user checkout request spans 6 microservices and 14 database queries. How do you trace where the latency occurred using a unified `trace_id`?
60 views • Direct Permalink

Distributed Context Propagation

  1. The edge API gateway generates a unique trace_id and span_id.
  2. Passed downstream across all HTTP/gRPC headers via W3C Trace Context (traceparent: 00-4bf92f3577b34da6a3ce929d0e0e4736-00f067aa0ba902b7-01).
  3. Each microservice logs the trace_id and exports span metrics to OpenTelemetry collector / Jaeger for visual timeline waterfalls.
Tags: #Distributed Tracing #OpenTelemetry #Jaeger #Observability
System Design, Redis & Distributed Systems 10+ Years (Principal / Architect) Expert Production Scenario

How do you secure Microservices using Mutual TLS (mTLS) and OAuth2 Token Exchange in a Zero-Trust architecture?

Incident Scenario: Preventing lateral movement and man-in-the-middle packet sniffing inside a Kubernetes cluster if an internal container is compromised.
440 views • Direct Permalink

Mutual TLS (mTLS) with Service Mesh (Istio / Linkerd)

  • Both client and server authenticate each other using X.509 cryptographic certificates rotated automatically by the service mesh control plane.
  • All internal pod-to-pod network traffic is encrypted with TLS 1.3.
  • Combined with short-lived JWT scoped tokens to verify service-level authorization.
Tags: #mTLS #Zero Trust #Service Mesh #Security #OAuth2
System Design, Redis & Distributed Systems 5-8 Years (Senior) Medium Production Scenario

How do you design a High-Throughput Leaderboard System with Millions of Scores using Redis Sorted Sets (`ZSET`)?

Incident Scenario: Real-time gaming platform tracking top 100 player ranks out of 10 million players updating scores continuously.
328 views • Direct Permalink

Redis Sorted Sets ($O(\log N)$ Complexity)

# Add / update player score
ZADD leaderboard 4500 "user_9821"

# Get user current global rank (0-indexed)
ZREVRANK leaderboard "user_9821"

# Fetch top 10 players with scores
ZREVRANGE leaderboard 0 9 WITHSCORES

Internal SkipList data structure delivers sub-millisecond lookups across millions of elements.

Tags: #Redis ZSET #Leaderboard #SkipList #Performance
System Design, Redis & Distributed Systems 8-10 Years (Tech Lead) Hard Production Scenario

How does Database Connection Starvation happen during traffic spikes and how do you configure Maximum Connection limits?

Incident Scenario: During a marketing campaign, 400 auto-scaled web workers each opened 20 database connections, crashing MySQL with `Too many connections` (max 1,000).
645 views • Direct Permalink

Connection Pooling with ProxySQL / PgBouncer

  • Without connection pooling: $400 \text{ pods} \times 20 \text{ connections} = 8,000 \text{ open DB connections}$, overwhelming database thread management.
  • With Multiplexing Proxy: 8,000 application client connections multiplex over 50 persistent, high-speed connections to MySQL, keeping DB CPU in the sweet spot.
Tags: #Connection Pooling #Database Starvation #Auto Scaling #ProxySQL
System Design, Redis & Distributed Systems 5-8 Years (Senior) Medium

Explain Write-Through vs. Write-Behind (Write-Back) vs. Cache-Aside caching strategies.

Incident Scenario: Choosing caching architectures for high-frequency GPS tracking ingestion vs low-frequency user profile settings.
678 views • Direct Permalink

Caching Strategies

  1. Cache-Aside (Lazy Loading): Application reads cache; on miss, reads DB and writes to cache. Standard for most web apps.
  2. Write-Through: Application writes to cache, and cache synchronously writes to DB before returning. Consistency guaranteed, higher write latency.
  3. Write-Back (Write-Behind): Application writes to cache immediately; cache asynchronously flushes batch writes to DB in the background. High write performance, small risk of data loss if cache crashes before sync.
Tags: #Cache Aside #Write Through #Write Back #Architecture
System Design, Redis & Distributed Systems 5-8 Years (Senior) Medium Production Scenario

How do you design a Secure Content Delivery Network (CDN) Token Authentication system for private video streaming?

Incident Scenario: Ensuring paid video course URLs cannot be shared on social media or hotlinked by unauthorized users.
656 views • Direct Permalink

HMAC-Signed URLs with Expiration & IP Binding

  1. Backend generates an HMAC-signed URL containing: path, expires_timestamp, and optional client_ip.
  2. Cloudflare / CloudFront edge worker validates the signature in $O(1)$ at the edge node:
    https://cdn.example.com/video/master.m3u8?token=a8f9c1...&exp=1772189400
    
  3. If token expired or tampered, edge rejects with HTTP 403 without touching origin servers.
Tags: #CDN #Signed URLs #Security #Streaming
System Design, Redis & Distributed Systems 8-10 Years (Tech Lead) Hard Production Scenario

How do you design a Scalable Full-Text Search Engine with Elasticsearch / Meilisearch synchronizing with relational databases?

Incident Scenario: Ensuring search indexes reflect real-time database updates within 1 second without double-writing failures.
488 views • Direct Permalink

Change Data Capture (CDC) via Debezium & Kafka

Instead of dual-writing in application code (which risks desynchronization if search fails):

  1. Database writes to transaction WAL (Binlog).
  2. Debezium CDC connector tails the Binlog and streams row change events to Kafka.
  3. An indexing consumer batch writes updates into Elasticsearch / Meilisearch. Guarantees 100% data consistency with sub-second synchronization latency.
Tags: #Elasticsearch #Meilisearch #Change Data Capture #Debezium #Search