Memcached Interview Questions and Answers
Freshers / Beginner level questions & answers
Ques 1. What is Memcached?
Memcached is a high-performance, distributed memory caching system used to speed up dynamic web applications by alleviating database load.
Ques 2. What is the default port number for Memcached?
The default port for Memcached is 11211.
Ques 3. What are the advantages of using Memcached?
Advantages of Memcached include improved performance, reduced database load, scalability, and ease of use as a distributed caching solution.
Ques 4. What are Memcached buckets?
Memcached buckets are logical containers that allow the grouping of related caches. They help organize and manage different sets of data.
Ques 5. How can you add or update a value in Memcached?
You can add or update a value in Memcached using the 'set' command. If the key already exists, it will be updated; otherwise, a new key-value pair will be created.
Ques 6. What is the Memcached max connection limit?
The default max connection limit for Memcached is 1024. It can be configured in the Memcached server settings.
Ques 7. How can you retrieve data from Memcached?
Data can be retrieved from Memcached using the 'get' command by providing the key associated with the desired value.
Ques 8. How does Memcached handle cache misses?
In case of a cache miss, Memcached retrieves the data from the underlying storage (e.g., database) and stores it in the cache for subsequent requests.
Ques 9. What is the Memcached max item size?
The default max item size in Memcached is 1 MB. It can be adjusted based on the application's requirements.
Ques 10. What is Memcached connection timeout?
The connection timeout in Memcached specifies the maximum time a client is allowed to establish a connection with the server. It is set in seconds.
Intermediate / 1 to 5 years experienced level questions & answers
Ques 11. Explain how Memcached works.
Memcached stores key-value pairs in memory to reduce the need for repeated database queries. It uses a simple and efficient hashing algorithm for distributed caching across multiple servers.
Ques 12. How does Memcached handle data expiration?
Memcached uses a time-based expiration mechanism. Each key-value pair has a specified expiration time, and once the time is reached, the data is automatically evicted from the cache.
Ques 13. Explain the concept of Memcached slab allocation.
Memcached uses slab allocation to efficiently manage memory. It categorizes memory into slabs based on size, and each slab contains items of a specific size range.
Ques 14. Explain Memcached CAS (Check and Set) operation.
CAS is a mechanism in Memcached that allows for atomic updates. It checks if the value has been modified since it was retrieved, and updates it only if no changes occurred in the meantime.
Ques 15. Explain Memcached slabs and classes.
Memcached slabs represent chunks of memory allocated for items, and classes are sets of slabs with similar-sized items. Slabs are organized into classes to efficiently manage memory usage.
Ques 16. What is Memcached replication?
Memcached replication involves creating copies of data on multiple Memcached servers. It provides redundancy and high availability in case a server goes down.
Ques 17. Explain Memcached memory optimization techniques.
Memory optimization in Memcached can be achieved through techniques like slab reassignment, adjusting item size, and optimizing key storage.
Ques 18. What is the Memcached LRU algorithm?
LRU (Least Recently Used) is a caching eviction algorithm used by Memcached to remove the least recently accessed items from the cache when it reaches its memory limit.
Ques 19. How can you monitor Memcached performance?
Memcached performance can be monitored using tools like memcached-tool, telnet, or specialized monitoring software. Key metrics include hit rate, miss rate, and memory usage.
Ques 20. Explain Memcached connection pooling.
Memcached connection pooling involves reusing existing connections instead of creating new ones for each request. This helps reduce overhead and improve performance.
Ques 21. Explain Memcached UDP support.
Memcached supports UDP (User Datagram Protocol) for fast and lightweight data transfer. It is often used for non-critical operations like cache updates.
Ques 22. What is Memcached key hashing?
Memcached uses a consistent hashing algorithm to determine the server responsible for a particular key. This ensures even distribution of keys across multiple servers.
Ques 23. Explain Memcached slab growth factor.
The slab growth factor in Memcached determines how much the memory allocation size should grow when the existing slabs are full. It helps in efficient memory management.
Experienced / Expert level questions & answers
Ques 24. What is the difference between Memcached and Redis?
While both are caching systems, Memcached is a simple key-value store, and Redis is a more feature-rich data store with support for data structures like sets and lists.
Ques 25. How does Memcached handle network partitions?
Memcached does not handle network partitions by default. Developers need to implement their own mechanisms, such as sharding and replication, to address network partition issues.
Ques 26. How can you handle cache stampede in Memcached?
Cache stampede can be mitigated using techniques like setting short expiration times, implementing mutexes, or using lazy loading to refresh the cache.
Ques 27. How can you secure Memcached servers?
Memcached servers can be secured by setting up firewall rules, using SASL (Simple Authentication and Security Layer), and configuring access controls to restrict unauthorized access.
Ques 28. Explain Memcached thread safety.
Memcached is not thread-safe by default. To achieve thread safety, developers can use a separate Memcached instance for each thread or use a thread-safe library.
Most helpful rated by users: