← Snapchat Interview Insights

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

SeniorPrefer not to say
Apr 2026

Summary

Snapchat system design round, one big question about building an in-memory cache with TTL and LRU eviction. More depth required than I expected, especially once the distributed angle came up.

Questions Asked (1)

Q1

Design an in-memory cache that supports per-key TTL expiration, LRU eviction when at capacity, and the standard get/put operations. Walk through your data structures, expiration strategy, thread safety, and how you'd extend this to a distributed setting.

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

I started with the hashmap plus doubly linked list combo for LRU which felt solid, but then they asked how I'd handle TTL and I kind of fumbled for a minute.

Create a free account to read the full note

AI HintsAI Generated

Suggested Approach

Start by clarifying requirements (capacity, TTL semantics, thread safety, distributed needs). Then design the core data structures (hash map + doubly linked list) and explain how TTL and LRU interact. Finally, discuss thread safety and distributed extensions, highlighting trade-offs.

Pro tip: Mention that TTL expiration can be lazy (on access) combined with active expiration to avoid memory bloat, and that in a distributed setting, consistent hashing and replication are key to scaling and fault tolerance.

1. Clarify Requirements

Ask about expected scale, read/write ratio, TTL precision, eviction policy details, and consistency needs in distributed mode.

2. Design Core Data Structures

Use a hash map for O(1) key lookup and a doubly linked list for LRU ordering. Each node stores key, value, and expiration timestamp.

3. Handle TTL Expiration

Implement lazy expiration on get/put and a background thread for active expiration to prevent stale entries from consuming memory.

4. Ensure Thread Safety

Use fine-grained locking (e.g., per-bucket locks) or a concurrent hash map with atomic operations to minimize contention.

5. Extend to Distributed

Partition data using consistent hashing, replicate for fault tolerance, and consider a gossip protocol for TTL synchronization.

Key Points to Mention

  • Hash map + doubly linked list for O(1) get/put and LRU eviction.
  • Lazy vs. active expiration strategies and their trade-offs.
  • Thread safety via locking or lock-free data structures.
  • Distributed caching with consistent hashing and replication.
  • Handling TTL in distributed setting: clock skew and synchronization.
  • Eviction policy interaction: expired items should be removed before LRU eviction.

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