Memcached 00:00:01 A profile page asks one cache server A social app wants user forty-two's profile. In a common Memcached setup, the client chooses a server for the key. That server does not forward an ordinary cache miss around the fleet. The client hashes user:42. The rule gives server 2. Server 2 does not have it. It does not ask the others: it does not know them. The application reads the row. It stores the value on server 2 with a time to live. The same key goes to the same server and is found. The database remains the source of the profile. A successful fill improves the next read, but a missing cached copy must never become a missing account. 00:00:45 Why a 139-byte item uses more room Inside one Memcached process an item needs space for the key, value, metadata and representation overhead. The exact footprint depends on the build and configuration, so follow these example sizes. Two pages are in use, one for the smallest class and one for the largest shown. No class is full. With this example's overhead, a twenty-byte key and sixty-byte value require one hundred thirty-nine bytes altogether. A one-hundred-twenty-byte chunk is too small. A one-hundred-fifty-two-byte chunk fits, leaving thirteen bytes unused. The item takes one chunk. The next items of this size are stored without cutting anything. A slab class uses fixed-size chunks. That speeds allocation, but different item sizes create internal slack and different demands across classes. 00:01:40 Empty small chunks cannot hold a large item A dashboard reports plenty of free chunks. Then a larger profile gets evicted. Both facts fit once you break the allocator down by slab class. The 96-byte class has three pages and little in them. The 192-byte class has one full page. It belongs to the 192 class. There is no free chunk and no free page. The example evicts an item from the larger class despite free chunks in the smaller one. Those small chunks are not interchangeable with a larger chunk. The mover takes a page from the small class and cuts it into 192-byte chunks. Automatic page movement can change the allocation between classes over time. Look at evictions, item sizes and free chunks per class before concluding the whole cache has run out of memory. 00:02:30 A new server changes which keys are warm Add a fourth server to a fleet of three. The application still knows the same keys, but its server-selection function can send them somewhere else. Hash values 0 to 11, modulo 3. A modulo rule moves nine of the twelve illustrated keys. Three quarters of these cached lookups would go to a different machine. The illustrated consistent-hashing assignment moves three of these twelve. That proportion belongs to the sample and its key distribution. Consistent hashing can reduce remapping when membership changes. A cache migration still needs an origin-load plan for the keys that move and miss. 00:03:09 Coalesce the expensive rebuild Two clients arrive just after a popular profile expires. Both see a miss. A short-lived coordination key acquired with add can let just one of them perform the expensive refill. The entry has just expired. Server 1 gets STORED, server 2 gets NOT_STORED. Server 1 reads the database. Server 2 waits 100 ms. Server 1 stores the page and removes the lock. Server 2 reads it. Treat the coordination entry as a cache hint with a bounded lifetime. Use a design that tolerates an owner failure and repeated refresh; the authoritative profile must stay safe even if that hint disappears.