0
$\begingroup$

I am studying system design for distributed systems and in this page (https://github.com/donnemartin/system-design-primer), one of the following advantages was mentioned for federation for databases was:

Smaller databases result in more data that can fit in memory, which in turn results in more cache hits due to improved cache locality.

What I don't understand is why would smaller databases have more memory? Furthermore, how does federation improve cache locality and result in more cache hits?

$\endgroup$

1 Answer 1

1
$\begingroup$

It's not smaller databases have more memory - it's about size of a data set.

Let's say we have a data set of 100G and we have a cache of 10G - assuming completely random access to data, we have 1/10 probability of reading data from the memory cache vs reading it all the way from a storage.

What if we take our 100G and shard (e.g. using hash of a key) it to two nodes of 50G each? In that case, the probability of fining the data in the cache on every node is 10/50-> 1/5 - twice better than before.

Can we do our system even faster? Let's have 10 nodes! Now every node has just 10G of data and 10G of memory - we can read all data from the memory - making it fast.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.