Reaves.dev

v0.1.0

built using

Phoenix v1.7.12

Consistency In Distributed Data Stores

Stephen M. Reaves

::

2023-03-03

Notes about Lesson 10 of CS-7210

Required Readings

Summary

Why is Consistency Important and Hard

It’s important because distributed systems are to appear as one logical entity but it’s hard because we contain multiple copies of state and those copies might be out of sync at any given time.

We make guarantees about the ordering of the updates in the system and how they are going to be visible to the read operations on the system.

Example consistency models:

Ordering is from most consistent to most available

Key Value Store

Like hash map

Memcached

Designed and released by Facebook in 2013

In-memory KV store

Replaced by Tao a few months later

Tao is better for graph traversals, which Facebook used a lot

Memcached is used in different contexts like within cluster and across geos

Look-Aside Cache Design

Workload can be considered for cache if:

Cache sits beside the db, not in front

  1. Explicit GET call to cache
  2. Cache replies Miss
  3. Explicit call to DB (using SQL-native semantics)
  4. Explicit SET call to cache

Any updates to DB must call DELETE on cache

Memcached discards based on LRU

Cache is clean, but non-authoritative

Explicit nature allows client applications to decide on consistency vs speed trade off

Mechanisms in Memcached

Concurrent DBRead -> DBSet -> CacheSet operations can arrive out of order which can lead to incorrect cache states

Leases are used to fix this.

Memcached leases are tokens issued on cache miss with time bounds to soft-lock writes on certain objects (among other issues).

Limiting the number of tokens issues can (partially) solve the Thundering Herd problem

Single instance of MC has finite memory, data is sharded by multiple instances

Routing is handled by clients to keep MC simple

Multiple MC clusters can be mirrored to help with single object performance and add failure domains

Invalidations are driven by DB in commit order

Cannot use same consistency mechanisms for cross-datacenter clusters

MC expects replication at the storage layer for cross-datacenter clusters

Cross-datacenter traffic order:

  1. GET on remote MC, setting remote flag
  2. Write to master DB
  3. DELETE from MC
  4. Master DB replicates to slave DB
  5. MC deletes remote marker

Causal Plus Consistency

Causal dependencies are not visible at system level

Client library embeds ordering metadata on PUT requests. (PUT_AFTER)