Databases advanced LIVE SIMULATOR
πŸ’Ώ

Tunable DB Consistency Simulator

Simulate tunable read/write consistency levels (One, Quorum, All) in a Dynamo-style replicated database ring. Slice network connections to create partitions, execute operations

dynamovector clockquorumtunable consistencyeventual consistencyread repairgossipsimulator
Interactive Simulator

Continue with the guided workspace

Use the paired workspace to connect this guide's mental model with live component state, visible signals, and the outcome each step or scenario is meant to prove.

A Dynamo-style masterless database lets writes succeed on any subset of replicas, trading immediate consistency for high write availability. Tunable consistency comes from three knobs β€” replication factor NN, write quorum WW, and read quorum RR β€” and the core mental model is quorum intersection: when R+W>NR + W > N, every read overlaps a previous write on at least one replica, so the latest value is always retrievable.

Mental Model

A Dynamo-style masterless database scales write availability by allowing writes to succeed on any subset of nodes. It achieves tunable consistency through three parameters: Replication Factor (NN), Write Quorum (WW), and Read Quorum (RR). The core mental model is quorum intersection: if R+W>NR + W > N, the read quorum and write quorum are mathematically guaranteed to overlap on at least one replica node. This overlap ensures that a read will always retrieve the latest write. If R+W≀NR + W \le N, the database is eventually consistent, meaning reads might return stale data.

Components and Why They Exist

Client App

The client application triggers reads and writes at configurable consistency levels (ONE, QUORUM, ALL) and verifies whether returned values are fresh, stale, or conflicted. Request packets leave the Client App card toward the selected coordinator and report the resolved value and quorum outcome on return.

Coordinator Node

The coordinator node manages the lifecycle of a distributed request, fans queries out to the replica preference list, counts quorum acknowledgments, and triggers read repair when stale versions appear. A highlighted ring outline marks the active coordinator as it dispatches blue write packets or green read packets across the cluster.

Replicas (N1 to N5)

Replicas N1 through N5 store data partitions redundantly, execute local reads and writes, and maintain logical vector clocks to track causal history. Each replica card displays its stored key value alongside its vector clock counters (such as [N1:2]) and network partition state.

Gossip Protocol (Anti-Entropy)

The gossip protocol exchanges key metadata in the background so partitioned or skipped replicas converge without waiting for a client read to touch every stale key. Periodic anti-entropy sync events reconcile divergent vector clocks and bring lagging replica cards back into agreement.

Edge Cases and Misconceptions

  • LWW (Last-Write-Wins) timestamp issues: Many databases use wall-clock timestamps to resolve version conflicts. If server clocks drift, a write that occurred later in real time might be discarded because its timestamp is lower than a stale node’s clock, causing permanent data loss.
  • Quorum does not prevent conflict: If two clients write concurrently to different partitioned nodes with a write quorum of 1 (W = 1), both writes succeed, creating diverging histories. Vector clocks identify this concurrency, forcing the application or database to merge the values.
  • ALL consistency availability penalty: Setting the write quorum to ALL (W = ALL) ensures absolute read freshness, but if even a single replica node is partitioned or restarts, all writes fail, destroying the system’s write availability.

Common Questions

Why is a coordinator node used in a masterless database?

In a masterless (Dynamo-style) database, any node can receive client requests. The contacted node acts as the coordinator for that specific request, querying the correct replicas based on consistency parameters, resolving version conflicts, and responding to the client.

What is the difference between Vector Clocks and wall-clock timestamps?

Wall-clock timestamps rely on server clocks, which drift and can cause newer writes to be overwritten (Last-Write-Wins anomalies). Vector clocks track logical causality (happened-before relationships) by incrementing node-specific counters, allowing nodes to detect concurrent writes and conflicts accurately.

How does Read Repair resolve staleness?

When a client reads with a consistency level R > 1, the coordinator fetches data from R replicas. If it detects a replica with an older vector clock, it returns the newest value to the client and immediately sends an asynchronous write to update the stale replica.

What is Gossip Sync (Anti-Entropy) and why is it needed?

Read Repair only updates stale replicas when a key is actively read. Gossip Sync is a background anti-entropy process where nodes periodically exchange vector clock metadata to discover and synchronize stale keys across the network.

What happens when $R + W \le N$?

The quorums might not overlap. For example, in a cluster with N=3, W=1, and R=1, a write might update only Node A, while a subsequent read queries only Node B, returning stale data (or no data) until background gossip sync completes.

How does a vector clock determine if a version is newer?

A vector clock V_A is newer than (dominates) V_B if every counter in V_A is greater than or equal to the corresponding counter in V_B, and at least one counter is strictly greater. If some counters in V_A are larger while others in V_B are larger, the versions are concurrent (in conflict).

Why do Dynamo-style databases prefer local quorums?

In multi-region clusters, waiting for replica acknowledgments across WAN links is extremely slow. Using local quorums (e.g., Local Quorum) allows quorums to be met within the local datacenter, delivering low latency while relying on async replication to remote datacenters.