0 ratings0% found this document useful (0 votes) 97 views7 pagesSystem Caching - Part 2
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here.
Available Formats
Download as PDF or read online on Scribd
47723, 205 PM Acrash Course in Caching - Part 2 - by Alox Xu
A Crash Course in Caching - Part 2
Alex Xu
averse Ow)
This is part 2 of the Crash Course in Caching series.
Distributed cache
A distributed cache stores frequently accessed data in memory across multiple nodes.
The cached data is partitioned across many nodes, with each node only storing a portion
of the cached data. The nodes store data as key-value pairs, where each key is
deterministically assigned to a specific partition or shard. When a client requests data,
the cache system retrieves the data from the appropriate node, reducing the load on the
backing storage.
‘There are different sharding strategies, including modulus, range-based and consistent
hashing.
Modulus sharding
Modulus sharding involves assigning a key to a shard based on the hash value of the key
modulo the total number of shards. Although this strategy is simple, it can result in
many cache misses when the number of shards is increased or decreased. This is
because most of the keys will be redistributed to different shards when the pool is
resized.
htpssblog.bytebylego.comipla-crash-course-n-caching-par-2 w417128, 205 PM Acrash Course in Caching - Part 2 - by Alox Xu
‘Modulus sharding
Range-based sharding
Range-based sharding assigns keys to specific shards based on predefined key ranges.
With this approach, the system can divide the key space into specific ranges and then
map each range to a particular shard. Range-based sharding can be useful for certain
business scenarios where data is naturally grouped or partitioned in specific ranges,
such as geolocation-based data or data related to specific customer segments.
Range-based sharding
68) (6 15) (30)
cS SS =
Ss ———— Ss
to ' 7
: 2. cache miss \
\ 3. read from storage
! & write to cache
\
Storage ;
\
Read-through
ByteByteGo Newsletter t jet
Start trial
Sign in
htpssblog.bytebylego.comipla-crash-course-n-caching-par-2417128, 205 PM Acrash Course in Caching - Part 2 - by Alox Xu
© 2023 ByteByteGo - Privacy - Terms - Collection notice
Substack is the home for great writing
htpssblog.bytebylego.comipla-crash-course-n-caching-par-2
Ww