← TikTok Interview Insights

TikTok·Software Engineer·Onsite - System Design / Architecture·Senior

SeniorPrefer not to say
May 2026

Summary

TikTok system design round focused almost entirely on Redis internals. Pretty deep dive, more than I expected for a single session.

Questions Asked (6)

Q1

Walk me through Redis's core data structures and their time and space complexity characteristics.

Algorithms & Data StructuresTechnical Trade-offs
Author's notes

Covered strings, lists, sets, sorted sets, hashes, and streams.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

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.

1. Categorize the data structures

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.

2. Explain each structure's purpose and common operations

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).

3. Detail time complexity of operations

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).

4. Discuss space complexity and memory optimizations

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.

5. Relate to real-world trade-offs and TikTok's scale

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.

Key Points to Mention

  • Strings: O(1) GET/SET, binary-safe, up to 512MB; used for caching, counters.
  • Lists: O(1) push/pop at ends, O(N) index access; implemented as quicklist (linked list of ziplists) for memory efficiency.
  • Hashes: O(1) field access, O(N) for HGETALL; small hashes use ziplist encoding to save memory.
  • Sets: O(1) add/remove/contains; unordered, used for tags, unique items; intset encoding for small integer sets.
  • Sorted Sets: O(log N) insert/delete, O(log N) range queries; skiplist + hash table; ideal for leaderboards.
  • Advanced structures: Bitmaps (bit operations, O(1) per bit), HyperLogLogs (O(1) cardinality estimation, ~12KB), Geospatial (O(log N) radius queries), Streams (O(1) append, O(N) range).

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q2

Compare RDB and AOF persistence in Redis. What are the durability, performance, and recovery trade-offs?

System DesignTechnical Trade-offs
Author's notes

This one I felt decent about.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

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.

1. Define RDB and AOF

Briefly explain that RDB takes point-in-time snapshots, while AOF logs every write operation. This sets the foundation for comparison.

2. Analyze Durability

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.

3. Evaluate Performance Impact

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.

4. Compare Recovery Characteristics

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.

5. Conclude with Use Cases

Summarize when to use each: RDB for backups and fast recovery, AOF for higher durability, and hybrid for balanced production systems.

Key Points to Mention

  • RDB is a point-in-time snapshot, compact and fast to load, but can lose data between snapshots.
  • AOF logs every write, offers better durability with configurable fsync policies (always, everysec, no).
  • Performance: RDB has lower runtime overhead but fork() can cause latency; AOF has higher write overhead but can be tuned.
  • Recovery: RDB loads faster; AOF replay can be slow, but hybrid RDB-AOF (Redis 4.0+) combines both for faster recovery.
  • Trade-offs: RDB is good for backups and disaster recovery; AOF is better for durability; hybrid is often used in production.
  • Consider TikTok's scale: persistence choices impact replication, failover, and latency in high-throughput environments.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q3

How do Redis eviction policies work, and what happens to keys with TTLs when the instance is under memory pressure?

System DesignTechnical Trade-offs
Author's notes

Knew the policy names (allkeys-lru, volatile-lru, noeviction, etc.) but fumbled a bit explaining the interaction between TTL expiration and active eviction.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

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.

1. Define eviction policies

List and briefly describe Redis eviction policies: noeviction, allkeys-lru, allkeys-lfu, allkeys-random, volatile-lru, volatile-lfu, volatile-random, volatile-ttl.

2. Explain eviction mechanics

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.

3. Clarify TTL behavior under pressure

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.

4. Discuss trade-offs and use cases

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.

5. Mention monitoring and tuning

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.

Key Points to Mention

  • Redis eviction policies: noeviction, allkeys-lru, allkeys-lfu, allkeys-random, volatile-lru, volatile-lfu, volatile-random, volatile-ttl.
  • Under volatile-* policies, only keys with an expire set are eligible for eviction; under allkeys-*, all keys are eligible.
  • TTL keys are not given priority for eviction unless using volatile-ttl; they may be evicted before expiration if memory pressure occurs.
  • Redis uses approximated LRU/LFU algorithms with random sampling to reduce memory overhead.
  • noeviction policy returns errors on write commands when memory limit is reached, which can cause application failures.
  • Monitoring evicted_keys and memory usage helps in tuning the eviction policy and maxmemory setting.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q4

Explain how Redis replication works, how Sentinel handles failover, and how Cluster handles sharding.

System DesignTechnical Trade-offs
Author's notes

Three separate concepts jammed into one question.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

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.

1. Redis Replication Basics

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).

2. Replication Trade-offs

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.

3. Sentinel for High Availability

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.

4. Cluster for Sharding

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.

5. Comparison and Use Cases

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.

Key Points to Mention

  • Asynchronous replication and its implications for consistency and durability (e.g., data loss during failover).
  • Sentinel's role: monitoring, notification, automatic failover, and configuration provider for clients.
  • Sentinel quorum and majority for failover decision; split-brain scenarios and how to mitigate.
  • Redis Cluster's hash slot mechanism (16384 slots) and client-side redirection (MOVED/ASK).
  • Cluster's built-in failover: each master has replicas, and a replica is promoted if master fails.
  • Trade-offs: replication for read scaling, Sentinel for HA without sharding, Cluster for scaling and HA but with complexity.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q5

What are the limitations of Redis transactions and Lua scripting, and what are the common pitfalls when implementing distributed locks?

System DesignTechnical Trade-offs
Author's notes

The distributed locks part is where things got interesting.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

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.

1. Explain Redis Transactions Limitations

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.

2. Explain Lua Scripting Limitations

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.

3. Discuss Distributed Lock Pitfalls

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.

4. Connect to System Design Trade-offs

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.

5. Summarize Best Practices

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.

Key Points to Mention

  • Redis transactions (MULTI/EXEC) lack rollback and isolation, and WATCH can cause retries.
  • Lua scripts are atomic but block the server and must be deterministic; they are not a replacement for ACID transactions.
  • Distributed lock pitfalls: lock expiration, clock drift, network partitions, and the need for fencing tokens.
  • Redlock algorithm and its controversies (e.g., Martin Kleppmann's critique).
  • Alternatives to Redis locks: ZooKeeper, etcd, or database-based locks.
  • Best practices: unique lock identifiers, timeouts, idempotency, and graceful degradation.

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.

Q6

How would you prevent a cache stampede, and what strategies exist for handling hotspot keys in Redis?

System DesignTechnical Trade-offs
Author's notes

Talked through probabilistic early expiration, mutex-based locking on cache miss, and local in-process caching as a buffer for hotspot keys.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

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.

1. Define the problem

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.

2. Prevent cache stampede

Describe techniques such as mutex locks, early recomputation, and probabilistic early expiration to ensure only one request rebuilds the cache.

3. Handle hotspot keys

Discuss strategies like key sharding, local caching, read replicas, and request coalescing to distribute load and reduce latency.

4. Evaluate trade-offs

Compare strategies in terms of consistency, latency, complexity, and resource usage, and suggest when to use each.

5. Apply to TikTok's scale

Propose a combined approach suitable for TikTok's global, high-throughput environment, mentioning monitoring and dynamic adjustment.

Key Points to Mention

  • Mutex locks and distributed locks (e.g., Redis SETNX) to serialize cache rebuilds
  • Probabilistic early expiration (e.g., XFetch algorithm) to spread out recomputation
  • Key sharding: splitting a hot key into multiple sub-keys with random suffixes
  • Local caching (in-process cache) to reduce Redis load for extremely hot keys
  • Read replicas and Redis Cluster for horizontal scaling
  • Request coalescing (e.g., using a queue) to batch identical requests

AI-generated suggestions, not part of the candidate's original notes. May be inaccurate — verify before relying on them.