Design Memcached

Quick Overview

Design a distributed in-memory caching system like Memcached. Cover consistent hashing, cache eviction policies, replication strategies, and handling cache stampedes. This is a common Meta E6+ infrastructure question.

Meta
System Design
Software Engineer
Meta
Software Engineer
Onsite
System Design
Hard

0


Design a distributed in-memory caching system like Memcached. Cover consistent hashing, cache eviction policies, replication strategies, and handling cache stampedes. This is a common Meta E6+ infrastructure question.

Meta runs one of the largest Memcached deployments in the world in front of its social graph storage, so this is a natural infrastructure question for senior candidates. The interviewer checks whether you can reason about key distribution, eviction, replication, and thundering-herd problems with realistic numbers rather than buzzwords.

What the Interviewer Expects
  • State functional and non-functional requirements, including latency targets and consistency expectations
  • Estimate memory, QPS, and node count with back-of-envelope math
  • Explain consistent hashing with virtual nodes and how it limits remapping when nodes join or leave
  • Compare eviction policies such as LRU and slab-based allocation and their memory overhead
  • Address cache stampedes with leases, request coalescing, or probabilistic early expiration
  • Discuss replication and invalidation across regions and the staleness it implies
Key Topics to Cover
Consistent hashing
Eviction policies
Cache stampede and leases
Replication and invalidation
Hot key mitigation
Capacity estimation
How to Approach This
  1. Start by clarifying functional and non-functional requirements with the interviewer.
  2. Estimate the scale: QPS, storage, bandwidth. This drives your design decisions.
  3. Draw a high-level architecture first, then deep dive into 1-2 critical components.
  4. Discuss trade-offs explicitly (e.g., consistency vs availability, SQL vs NoSQL).
  5. Address failure scenarios, monitoring, and how the system handles 10x traffic spikes.
Possible Follow-up Questions
  • How would you invalidate cached entries when the backing database is updated in another region?
  • A single celebrity key is getting millions of reads per second. How do you handle the hot key?
  • What happens to hit rate when you add ten nodes to the cluster, and how do you minimize the impact?
  • How would you prevent a cold cache from overwhelming the database after a large outage?
Sharpen Your Skills on Codemia

Practice similar problems with our interactive workspace, get AI feedback, and track your progress.

Practice System Design Problems
Sample Answer
Requirements

Functional Requirements:

  1. Key-Value Storage: The system should allow users to store and retrieve arbitrary key-value pairs.
  2. Scalability: The system must support horizontal scaling to ...
Capacity Estimation

Assuming Meta has approximately 1 billion daily active users (DAUs) and each user generates around 1 KB of cacheable data:

  • Daily Cache Size: 1 billion users * 1 KB = 1 TB of cacheable data per d...

Submit Your Answer
Markdown supported