advanced26 min studyLesson 245 in Engineering

Commitment: preserve the current-term rule before applying

Track last-log, commit, and applied indices and explain why Raft cannot commit an older-term entry merely by recounting its replicas.

On this page

What you’ll understand

  • Use a leader's current-term majority rule to advance commitment.
  • Distinguish indirect commitment of an older prefix from direct replica counting.
  • Apply committed commands in order and define when a client result becomes available.

A replicated entry is not automatically an irrevocable decision. Raft places a crucial restriction on how a leader concludes that a prefix is committed: counting replicas directly establishes commitment only for an entry from that leader's current term. Once that entry is committed, its preceding prefix is committed too. The distinction looks fussy until a leadership change reveals an old entry that happened to reach a majority but could still be overwritten. Application must follow the proved committed prefix, not a reassuring replication percentage.

Three indices answer three questions

The last-log index describes what is locally stored. The commit index describes the highest prefix position this server knows is committed. The applied index describes how far its state machine has executed that committed sequence. A node can have a long speculative suffix, a shorter committed prefix, and an even shorter applied prefix. Exporting one generic replication index obscures these distinctions. When a read appears stale, inspect whether the delay lies in agreement, notification of commitment, or actual state-machine execution.

Application advances in index order through committed commands, not in the order network acknowledgements happen to arrive. A deterministic state machine produces the same state from the same starting snapshot and command sequence. If commands depend on nondeterministic local time, random values, or external service replies, those choices need to be represented consistently in the agreed input or handled by a separate design. Agreement on command bytes alone does not force replicas to make identical uncontrolled external observations.

0≤a≤c≤ℓ,inext apply=a+1≤c0\le a\le c\le\ell,\qquad i_{\rm next\ apply}=a+1\le c
a is lastApplied, c is commitIndex, and ℓ is the local last-log index, all dimensionless positions in one log. A snapshot may establish a nonzero base prefix. Application can advance only while the next index lies within the known committed prefix.↔ Scroll wide equations horizontally.

Count a current-term entry, then inherit its prefix

For a fixed-membership leader in term T, choose a candidate index N beyond its current commit index. The basic Raft rule requires that a majority's match indices reach N and that the leader's log entry at N has term T. Successful durable acknowledgements, including the leader's own appropriately persisted copy, support that count. Once N satisfies the rule, entries through N become committed. Previously committed entries do not become uncommitted merely because the leader later loses contact with a majority.

The extra term condition prevents an unsafe inference about old entries surviving earlier leadership changes. An older entry may have accumulated copies across terms without the election restriction yet ruling out a competing higher-term suffix. Commit a new current-term entry, often a no-op, and log matching ties the older prefix to that new committed entry. This explanation is specific to Raft's rule for retaining original entry terms; do not transfer it mechanically to a differently proved Paxos log protocol.

N>c,∣{s:match⁡s≥N}∣≥q,term⁡(L[N])=T⟹c′≥NN>c,\quad |\{s:\operatorname{match}_s\ge N\}|\ge q,\quad \operatorname{term}(L[N])=T\quad\Longrightarrow\quad c'\ge N
This is the basic fixed-membership Raft leader commitment rule under its full election, log, and persistence invariants. q is the configured majority, T the current leader term, and match_s a justified durable replication position. Indices and terms are dimensionless; joint configurations require their own quorum predicate.↔ Scroll wide equations horizontally.

Execution and a response complete the application contract

A client expecting an operation result generally needs the committed command applied and its result associated with its request identity. A leader may crash after application but before responding, so the replacement must recover the deduplication state needed to avoid performing the same logical action twice. External side effects add another boundary: a log entry instructing a payment does not atomically commit a separate payment provider. Use an explicit idempotency or transaction protocol rather than equating a replicated command with universal exactly-once effects.

The queue lab illustrates application pressure only. Reset, explicitly set both arrival two and service three, predict draining from four pending items, then Play or Step. For a separate overload comparison Reset and explicitly set arrival four and service three, predict, then play. Interpret arrival as newly committed work and service as application work in normalized items per second. Control edits retain elapsed time and recompute from the initial four items. The model does not determine commitment, model entry terms, or show a real apply loop.

Commit an old prefix through a new entry

A five-voter leader is in term six and has commitIndex eight. Entry nine has term five and is stored durably on four voters. Entry ten has term six and is stored durably on the leader and one follower. Apply the basic leader rule before and after a third voter stores entry ten.

  1. The majority threshold is three. Four copies of entry nine do not by themselves meet the current-term condition, because that entry's term is five rather than six. The stated observations alone do not justify advancing commitment to nine by the leader's replica-counting rule.

  2. Initially entry ten has only two justified copies, so it also fails the quorum count. After a third voter durably acknowledges the matching prefix through ten, its count reaches three and its term equals the leader's term six.

  3. The leader can now advance commitment through ten, indirectly committing entry nine as part of that prefix. If lastApplied was eight, it applies nine and then ten; it must not skip directly to ten merely because ten supplied the commitment proof.

The result

The current-term entry establishes the new committed prefix. Four older-entry copies and three current-term copies have different meanings under Raft's safety argument.

Explore the model

Interactive lab

Interactive lab · queue

Commit lag and apply lag are different

For each fixed-rate run choose Reset, explicitly set both rates, predict, then Play or Step. Compare committed-work arrival two and application service three with Reset plus arrival four and service three. Edits retain elapsed t and recompute from four initial pending items; the fluid model does not decide commitment or model log terms.

Commit lag and apply lag are differentFluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Current readings: Fluid backlog: 4; Net rate · λ − μ: −1 /s; M/M/1 mean residence: 1 s. All parameters are adjustable with the labeled controls below.02.557.51001.534.56Elapsed time · sFluid backlogλ < μ
Fluid backlogCurrent time
Fluid backlog
4
Net rate · λ − μ
−1 /s
M/M/1 mean residence
1 s
t = 0 s

Fluid backlog starts at 4 and follows max(0, 4 + (λ − μ)t). The separate M/M/1 residence-time formula assumes Poisson arrivals, exponential service and λ < μ. Parameter changes pause playback and recompute the model at the current elapsed time. Reset restores both parameters and returns time to zero. Playback starts paused. Adjust either parameter, then choose Play or Step.

Look forA committed prefix can still wait for application. A backlog estimate cannot replace the current-term commitment rule or ordered state-machine execution.

Check your understanding

In term eight, a leader observes an older term-seven entry on a majority but has not established any new current-term commitment. What does the basic Raft counting rule permit it to conclude from that observation alone?

Try it yourself

A node has last-log index 130, commitIndex 124, and lastApplied 120. How many entries may it apply immediately under its known committed prefix, and how many locally stored entries remain beyond commitment? What does this say about the newest client result?

Take a moment to make a prediction or work it out on paper. Open a hint when you need one.

Give me a hint

Calculate the two gaps separately. Being stored is not the same as having an agreed, applied result.

Compare with the solution

It can apply indices 121 through 124, four entries in order. Indices 125 through 130 are six stored entries beyond its known commitment and must not be executed merely because they are present. A client's operation at 130 has no confirmed applied result from these observations. Even an operation at 124 needs application and the appropriate response/deduplication contract before this node can return its computed result. These positions describe one node's knowledge, not a new global commitment proof.

Take it with you

  • Stored, committed, and applied indices must be distinguished.
  • Raft directly counts a current-term entry and commits its older prefix indirectly.
  • Application order, retry identity, and external effects remain explicit responsibilities.

Read further

Original sources and deeper explanations to follow at your own pace.

Optional progress, saved in this browser when available. Revisit any lesson at any time.

Lesson not marked complete.