← Bytedance Interview Insights

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

SeniorPrefer not to say
Jun 2026

Summary

Bytedance system design round, one question but it had a lot of moving parts. They wanted a full LRU cache design with TTL baked in, which sounds manageable until you get to the cleanup and concurrency bits.

Questions Asked (1)

Q1

Design an in-memory LRU cache that supports TTL expiration. Cover the data structures, eviction logic, how expired entries get cleaned up, time complexity, and concurrency.

System DesignAlgorithms & Data StructuresTechnical Trade-offs
Author's notes

I went with the classic hashmap plus doubly linked list combo and felt pretty good about the get and put logic.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements (capacity, TTL semantics, concurrency level), then propose a hash map + doubly linked list for O(1) LRU operations, augmented with TTL metadata and a cleanup strategy. Discuss trade-offs between lazy and active expiration, and explain concurrency approaches like sharding or fine-grained locking.

Pro tip: Emphasize that TTL and LRU are orthogonal concerns: TTL determines eligibility for eviction, while LRU determines order. Propose a hybrid cleanup (lazy on access + periodic sweep) to balance memory and latency, and mention that real systems often use approximate LRU (e.g., sampling) for scalability.

1. Clarify Requirements and Constraints

Ask about expected capacity, read/write ratio, TTL granularity, concurrency needs, and whether strict LRU or approximate is acceptable. This shapes data structure and locking choices.

2. Design Core Data Structures

Use a hash map for O(1) key lookup and a doubly linked list for O(1) recency updates. Store TTL expiration timestamp in each node. Explain how get and put update recency and handle capacity.

3. Define Eviction and Expiration Logic

On put, if capacity exceeded, evict least recently used entry. For TTL, check expiration on access (lazy) and optionally run a background thread to periodically remove expired entries. Discuss trade-offs.

4. Analyze Time and Space Complexity

State that get, put, and evict are O(1) average time. Space is O(capacity). Mention that periodic cleanup adds O(n) per sweep but amortized cost is low.

5. Address Concurrency

Propose thread-safe design: either a single lock (simple but contended), fine-grained locks per bucket/shard, or lock-free with atomic operations. Discuss read-write locks and sharding to reduce contention.

Key Points to Mention

  • Hash map + doubly linked list for O(1) LRU operations
  • TTL stored as expiration timestamp per entry; lazy expiration on access
  • Active expiration via background thread or timer wheel for timely cleanup
  • Eviction policy: LRU among non-expired entries; expired entries are removed first
  • Concurrency: sharding, read-write locks, or lock striping to balance safety and performance
  • Trade-offs: strict vs approximate LRU, memory overhead of TTL metadata, and cleanup latency

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