Covered strings, lists, sets, sorted sets, hashes, and streams.
Start by categorizing Redis data structures into basic (strings, lists, hashes, sets, sorted sets) and advanced (bitmaps, hyperloglogs, geospatial, streams). For each, briefly describe its purpose, then highlight the time complexity of common operations (e.g., O(1) for hash field access, O(log N) for sorted set inserts) and space characteristics (e.g., memory overhead, encoding optimizations). Emphasize how these complexities influence real-world design choices, especially for high-scale applications like TikTok.
Pro tip: Mention Redis's internal encoding optimizations (e.g., ziplist, intset, quicklist) and how they affect memory usage and performance, showing you understand trade-offs beyond textbook complexities. Also, relate to TikTok's scale by discussing how choosing the right data structure can reduce latency and memory footprint in a high-throughput environment.
Group Redis data structures into basic types (strings, lists, hashes, sets, sorted sets) and advanced types (bitmaps, hyperloglogs, geospatial, streams). This provides a clear structure for your answer.
For each data structure, briefly state what it's used for and list key operations (e.g., GET/SET for strings, LPUSH/RPOP for lists, HSET/HGET for hashes).
For each structure, specify the Big-O time complexity of common operations, noting any exceptions (e.g., O(1) for hash field access, O(log N) for sorted set inserts, O(N) for list index access).
Explain how memory usage varies (e.g., strings can be up to 512MB, hashes use ziplists for small sizes) and mention Redis's encoding optimizations that reduce overhead.
Connect the complexities to practical scenarios, such as choosing sorted sets for leaderboards (O(log N) inserts) or using hashes for object storage to save memory, emphasizing performance at scale.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
Start by defining RDB and AOF, then compare them across durability, performance, and recovery. Use a structured comparison to highlight trade-offs and conclude with when to use each or a hybrid approach.
Pro tip: Mention that in production, many use a hybrid of RDB and AOF (e.g., Redis 4.0+ RDB-AOF hybrid) to balance fast recovery and durability, and discuss how TikTok's scale might influence persistence choices.
Briefly explain that RDB takes point-in-time snapshots, while AOF logs every write operation. This sets the foundation for comparison.
Compare durability: RDB can lose data since last snapshot; AOF with fsync every second loses at most 1 second, and with always fsync is fully durable but slower.
Discuss performance: RDB has minimal runtime overhead but can cause latency spikes during snapshotting; AOF has higher write overhead but can be tuned with fsync policies.
Explain recovery: RDB loads faster due to compact binary format; AOF replay can be slow for large logs, but Redis 4.0+ hybrid RDB-AOF speeds up recovery.
Summarize when to use each: RDB for backups and fast recovery, AOF for higher durability, and hybrid for balanced production systems.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
Knew the policy names (allkeys-lru, volatile-lru, noeviction, etc.) but fumbled a bit explaining the interaction between TTL expiration and active eviction.
Start by explaining the purpose of eviction policies and the available options in Redis, then detail how TTL keys are treated under memory pressure, emphasizing that TTL is not a direct factor in eviction decisions. Finally, discuss trade-offs and best practices for choosing a policy in production systems.
Pro tip: Mention that Redis approximates LRU/LFU with sampling to save memory, and that you can monitor evicted keys and memory usage to tune policies dynamically.
List and briefly describe Redis eviction policies: noeviction, allkeys-lru, allkeys-lfu, allkeys-random, volatile-lru, volatile-lfu, volatile-random, volatile-ttl.
Describe how Redis selects keys for eviction: for volatile-* policies, only keys with TTL are candidates; for allkeys-*, all keys are candidates. Mention that Redis uses approximated algorithms (sampling) for LRU/LFU.
Explain that TTL keys are not preferentially evicted unless the policy is volatile-ttl; under other policies, TTL keys are treated like any other key. Also note that expired keys are removed lazily and actively, but eviction may occur before expiration.
Compare policies: noeviction causes errors on writes; allkeys-* may evict frequently used keys; volatile-* risks evicting only TTL keys, potentially causing memory issues if many keys lack TTL. Recommend based on access patterns and data importance.
Highlight the importance of monitoring evicted_keys and memory usage, and adjusting maxmemory and policy as needed. Suggest using Redis INFO and slowlog for diagnostics.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
Three separate concepts jammed into one question.
Structure your answer by first explaining Redis replication as the foundation, then describe how Sentinel builds on it for high availability, and finally how Cluster extends it for horizontal scaling. For each component, cover the mechanism, trade-offs, and typical use cases, emphasizing how they solve different problems.
Pro tip: Highlight that replication is asynchronous by default, which means data loss can occur during failover; mention that WAIT command or Redis 7's replication improvements can mitigate this. Also, note that Sentinel and Cluster are not mutually exclusive—Cluster has built-in failover, but Sentinel is for non-sharded setups.
Explain that Redis uses master-replica replication where replicas connect to a master and receive a stream of write commands. Describe the initial sync (full resync via RDB snapshot) and ongoing propagation (command stream).
Discuss asynchronous replication by default, potential data loss on failover, and how replication lag affects consistency. Mention optional synchronous replication via WAIT command and its performance impact.
Describe Sentinel as a separate process that monitors masters and replicas, performs automatic failover by promoting a replica, and reconfigures clients. Explain quorum and consensus for failure detection.
Explain that Redis Cluster shards data across multiple masters using hash slots (16384 slots). Describe how clients are redirected (MOVED/ASK), and how Cluster handles failover with replica promotion per shard.
Summarize when to use each: replication for read scaling and backups, Sentinel for HA in non-sharded setups, Cluster for horizontal scaling and HA. Mention that Cluster includes built-in failover, so Sentinel is not needed.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
The distributed locks part is where things got interesting.
Start by clearly distinguishing the limitations of Redis transactions (MULTI/EXEC) and Lua scripting, then transition to the pitfalls of distributed locks. Emphasize how these limitations impact real-world system design and trade-offs, especially in high-concurrency environments like TikTok.
Pro tip: Demonstrate awareness that Redis is not a silver bullet for distributed locking; mention alternatives like Redlock or ZooKeeper and when to choose them. This shows you understand the broader ecosystem and can make informed architectural decisions.
Discuss that MULTI/EXEC does not support rollback on errors, lacks isolation levels, and cannot conditionally abort based on intermediate results. Mention that WATCH provides optimistic locking but can lead to retries under contention.
Highlight that Lua scripts block the Redis server, must be deterministic, and cannot access external data. Also note that scripts are atomic but not transactional in the ACID sense, and debugging is challenging.
Cover common issues: lock expiration causing premature release, clock drift, network partitions, and the difficulty of ensuring mutual exclusion. Mention the Redlock algorithm and its criticisms.
Relate these limitations to system design decisions: when to use Redis locks vs. other coordination services, how to handle failures, and the importance of idempotency and fencing tokens.
Conclude with best practices: use unique lock values, set reasonable timeouts, consider Redlock with caution, and always have a fallback mechanism. Emphasize testing under failure scenarios.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.
Talked through probabilistic early expiration, mutex-based locking on cache miss, and local in-process caching as a buffer for hotspot keys.
Start by defining cache stampede and its impact on system performance, then outline prevention strategies such as locking, early recomputation, and probabilistic early expiration. Next, discuss hotspot key handling with techniques like key sharding, local caching, and read replicas, emphasizing trade-offs and TikTok's scale.
Pro tip: Mention that TikTok's massive scale requires a combination of strategies, and highlight the importance of monitoring and adaptive thresholds to balance consistency and availability.
Explain what a cache stampede is and why it's critical in high-traffic systems like TikTok, where a single hot key can overwhelm the database.
Describe techniques such as mutex locks, early recomputation, and probabilistic early expiration to ensure only one request rebuilds the cache.
Discuss strategies like key sharding, local caching, read replicas, and request coalescing to distribute load and reduce latency.
Compare strategies in terms of consistency, latency, complexity, and resource usage, and suggest when to use each.
Propose a combined approach suitable for TikTok's global, high-throughput environment, mentioning monitoring and dynamic adjustment.
AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.