In the first two parts I got OB running and created a tenant I could write data into — “it works.” This part is the bit a distributed database most needs you to understand: what entitles it to claim high availability and elastic scaling. Two things carry that: log streams + Paxos majority, and the automatic scheduling layered on top. This is also the disaster-recovery logic I most need to be clear-headed about on our production K8s + OB setup.

Learning notes again. Some of these mechanisms took me a while to untangle, so I’ve marked the “I used to think… now I get it” moments for anyone starting out too.


1. The consistency core: log stream + Paxos majority

The redo log of each partition (Tablet) flows into a log stream, and the log stream has replicas across Zones. One is the leader, which accepts writes; the rest are followers.

Whether a write succeeds comes down to: a majority of replicas has persisted that redo log, and only then does the leader confirm the commit. That is what lets OB talk about high availability at all — lose a minority of nodes and, as long as a majority remains, the service is unaffected.

The leader is not a lifetime appointment — it lives on a lease. When elected it receives a lease, and while healthy it keeps renewing it. The leader only does leader work while its lease is valid. If its machine fails and the lease stops being renewed, then once the lease expires the followers elect a new leader and grant it a fresh lease. That is the actual guard against split-brain: under a network partition the old leader can at most serve until its lease runs out, so you never end up with two leaders serving writes at the same time.

I used to think “primary-standby replication plus semi-sync is solid enough.” What I eventually understood: majority commit plus the lease is the real mechanism. Semi-sync is at best “try hard not to lose anything”; Paxos is “mathematically fine even if a minority is gone.”

One correction I have to flag about GTS, because I got this wrong at first: I had written that the new leader takes its timestamp from GTS and that this is what prevents split-brain. That’s not right. GTS (Global Timestamp Service) is not an anti-split-brain mechanism — it’s the service that generates continuously increasing timestamps within a tenant, used to stamp each transaction’s commit version and each statement/transaction’s read version, which is how MVCC and globally consistent snapshots work. (It keeps timestamps from going backwards via its own replicas: before a new GTS leader takes over it replays the previous leader’s pre-allocated range.) Anti-split-brain is the majority + lease story above.

Here’s the whole thing — how a write commits, and what happens when the leader dies:

Log stream Paxos majority commit and leader election

Only the leader accepts writes; the redo log goes to followers, a majority persisted means committed; if the leader fails, a new one is elected.


2. Replica placement: locality and primary_zone

Which Zones hold replicas, and where leaders prefer to sit, are controlled by two knobs — the two you touch most when operating this thing:

  • locality: the replica type and distribution of the tenant’s log streams across Zones. For example:
    • F@z1, F@z2, F@z3: a full replica (F = Full) in each of the three Zones.
    • F@z1, F@z2, L@z3: z3 holds a log replica (L = Log; it stores redo logs but not the data, saving storage).
  • primary_zone: which Zones leaders prefer. A semicolon ; means priority ordering, a comma , means equal priority. z1;z2;z3 means z1 is the most preferred place for leaders.

How many data centers you can survive, and where the read/write centre of gravity sits, comes down to these two working together.

My mistake here: I assumed locality was frozen once the tenant was created. It isn’t — you can change it online with ALTER TENANT ... SET locality = 'F@z1, F@z2, L@z3', and OB will create / drop / migrate replicas until the layout matches. No downtime, no rebuild.


3. Elasticity: scaling out and automatic rebalancing

Scaling a traditional database often means downtime, or hand-rolled sharding. OB’s version is “add machines → it rebalances itself”:

  1. Add OBServers to the cluster (more capacity at the cluster level).
  2. Give the tenant a bigger resource spec — e.g. add Units to its resource pool, or raise UNIT_NUM.
  3. The new capacity forms new Units, and RootService splits log streams and migrates Tablets onto the new machines.
  4. Once load levels out across machines, the scale-out is done.

Scale-in is the reverse: move and merge the log streams off the target machines, then retire them. The whole thing is owned by the balancing layer (log stream split/merge plus Tablet migration) — nobody moves data by hand.

What struck me: this is remarkably kind to operators. Adding a machine used to mean a pile of manual work; now it’s basically a declarative “give this tenant more resource,” and RootService does the rest.


4. What happens when a Zone goes down (the DR view)

This is the part that maps directly onto “we lost an AZ” on our Kubernetes setup:

  • A Zone holding only minority replicas goes down: the majority is still there, so the service is unaffected — you’ve just lost some redundancy, so fix the machine.
  • The Zone holding the leader goes down: the lease stops being renewed → the remaining replicas elect a new leader → service resumes. Transactions that hadn’t finished committing are recovered by replaying redo / commit logs through the two-phase-commit state machine, ending in a consistent state.

So for production, at least 3 Zones (3 replicas, tolerates losing 1) is the usual recommendation; a two-site-three-center layout typically runs 5 replicas to tolerate losing an entire IDC. Translated to our K8s + OB world: if a Kubernetes availability zone drops out, OB sees it as a Zone going away, and everything above applies — understanding it at this level is what “high availability in the cloud” actually means.


5. Wrap-up & what’s next

  • High availability = log stream Paxos majority + lease-based protection against split-brain; locality / primary_zone control replica placement and where leaders sit.
  • Elasticity comes from RootService splitting and migrating automatically — scaling doesn’t involve moving data by hand.
  • Zone failures are recovered by automatic re-election, provided enough replicas remain to form a majority.

The last part lands on our actual environment: how to run OB on Kubernetes with ob-operator, how to back it up, and how to tell whether it’s healthy. This part was the theory; the next one is “how to put it into production.”

References: