tags : Scaling Databases, Data Engineering, Database, Distributed Systems, Concurrency Consistency Models

FAQ

What does replication give?

  • Availability
  • Fault tolerance

Retries and Idempotency

  • At-most-once: Send request, don’t retry, update may not happen
  • At-least-once: Retry request until acknowledged, may repeat update
  • Exactly-once: (retry + idempotence) or deduplication

Issues with idempotency

  • If the functions are different eg. add & subtract on the same data, we don’t have the same gurantees

What’s a tombstone?

  • When we actually don’t delete something
  • But instead just mark it as deleted
  • Can be GC’ed later

Replication Types

Based on “How”

Failure Modes

Node failures

  • Followers/Secondary: catchup recovery from log
  • Leader
    • Detecting leader failure: timeout based detection/Heartbeat message
    • Leader Election: Node learns it’s a leader, communicated w followers
    • Failover

Adding and removing data

  • We can solve this by using logical Clocks and timestamps!
  • Every record has a logical timestamp of last write. This tells which values are newer/older.
  • Without timestamp even if replicas talked among themselves, they’ll not know which one was the last write. With timestamp that’s solved with a reconcile state / anti-entropy mechanism.

Architecture Types

Leader-Follower

Single Leader

  • Distinct Leader: Master or Primary
  • Followers: Read replicas, slaves, secondaries, participants
  • Flow
    • Read through followers
    • Write through leaders
  • Replication
    • Sync: Blocking
    • Async: Non-blocing
    • Semi-Sync : Sometime sync/sometimes async
  • Issues
    • With async, the new leader might not have the latest writes

Leaderless

Handling writes in Replicated Systems

LWW (Last Writer Wins)

  • We just keep the last value and discard others
  • Uses Lamport Clocks (total order)

MVR (Multi Value Register)

  • We want to keep all the values from all clients here
  • This will keep multiple values and cause a conflict, the application code then can decide how to deal with the conflict.
  • Uses Vector Clocks (partial order)

TODO Types

NOTE: Many of these could be different names for same thing

WAL file archiving

Full table replication

Full table replication copies all existing, new, and updated data from the primary database to the target, or even to every site in your distributed system.

Key based (incremental) replication

Key-based incremental replication identifies updated and new data using a replication key column in the primary database and only updates data in the replica databases which has changed since the last update. This key is typically a timestamp, datestamp, or an integer.

Log based (incremental) replication

Log-based incremental replication copies data based on the database binary log file, which provides information on changes to the primary database such as inserts, updates, and deletes.

Logical replication

Trigger based replication

Real time replication

Streaming replication

Multi master replication

  • More often than not, when people think they “need” multi-master they actually don’t.
  • the application needs to be written for such a setup

Master-Master replication

active-active replication

TO Read