Skip to content

Evaluate S3 conditional writes as a replacement for Raft coordination #169

Closed

Description

@scttfrdmn

Summary

Evaluate whether S3 conditional writes (If-None-Match / If-Match) can provide the
coordination guarantees the internal/distributed package is being built toward, at a fraction
of the complexity. This is a design evaluation, not a commitment to re-scope: nothing in
v0.11.0-v0.13.0 changes unless this produces evidence that it should.

Filed against v0.11.0 deliberately — the evaluation is only useful before more consensus code
is written.

Background

The evaluation should start from what the distributed package actually does today, which is
narrower than the roadmap and package docs imply. Findings from the v0.10.0 review:

There is no state machine. applyLogEntry in internal/distributed/consensus.go is three
empty arms:

switch entry.Type {
case EntryTypeOperation:
    // Apply operation to state machine
case EntryTypeConfigChange:
    // Apply configuration change
case EntryTypeNoop:
    // No operation
}

Nothing anywhere appends EntryTypeOperation or EntryTypeConfigChange. The log holds one
bootstrap noop plus one entry per election win. The consensus layer elects leaders and
replicates nothing.

Consensus is not on the data path. Coordinator.executeLocally calls the backend directly
and never consults the log, commitIndex, term, or leadership.

"Strong consistency" is not linearizable. executeStrongConsistency fans an operation to N
nodes and succeeds on successCount >= len(targetNodes)/2+1. But every node writes the same
S3 key, so these are N redundant identical PUTs. Majority success is a reachability signal, not
a consistency guarantee. doc.go claims linearizability; the code does not support it.

broadcastProposal is a simulation stub that sleeps and self-accepts. selectConsistentHash
returns nodes[:count] — no hashing.

So the comparison is not "replace working Raft with conditional writes." It is "choose the
mechanism before building the thing," which is a much cheaper decision to make now.

Implementation

Produce a written evaluation covering:

  1. Which guarantees are actually needed. Distinguish what the filesystem requires
    (single-writer-per-key, atomic metadata updates, cache invalidation ordering) from what Raft
    provides. If S3 is the sole source of truth and every node writes the same keys, the useful
    primitive may be per-key CAS rather than a replicated log.

  2. What conditional writes can and cannot do. If-None-Match: * gives atomic
    create-if-absent; If-Match: <etag> gives compare-and-swap on update. Both are per-object.
    They cannot provide multi-key atomicity, leader election with liveness guarantees, or
    membership consensus. Be explicit about where that ceiling bites.

  3. The interface change required. Backend.PutObject in pkg/types/interfaces.go takes no
    precondition and returns no ETag, and there are zero hits for If-None-Match/If-Match
    repo-wide. ETags are already plumbed for reads (types.ObjectInfo.ETag, populated in
    HeadObject and ListObjects), so the read half exists. Scope the write-side change.

  4. Non-AWS compatibility. Conditional write support varies across MinIO, Ceph, and Wasabi.
    Since the metadata fallback path in the v0.14.0 work exists precisely for those backends,
    establish what degrades and how.

  5. A recommendation with enough specificity to act on: keep the Raft direction, replace it,
    or adopt a hybrid (CAS for per-key coordination, gossip for membership, no replicated log).

Acceptance Criteria

  • Written evaluation covering all five points above, committed under docs/
  • Explicit statement of which guarantees the filesystem needs versus which Raft provides
  • Concrete API sketch for the Backend precondition/ETag change
  • Compatibility matrix for AWS, MinIO, Ceph, and Wasabi
  • A recommendation, with the issues that would be opened or closed if adopted
  • doc.go's linearizability claim corrected either way — it is inaccurate today regardless
    of which direction is chosen
  • No code changes in this issue

Dependencies

None. Should be done early: its value decreases as more consensus code is written.

Activity

  1. added
    type: enhancement
    priority: medium
    area: distributed
    needs-design
    on Jul 30, 2026
  2. added
    effort: large
    on Aug 3, 2026
  3. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    Evaluation complete — PR #265, document at docs/design/conditional-writes-vs-raft.md.

    Recommendation: adopt the hybrid. Per-key compare-and-swap for coordination, gossip for
    membership, no replicated log. Stop building toward Raft.

    The one-line reason: Raft replicates a log so N nodes agree on state they each hold a copy of.
    ObjectFS nodes hold no such state — S3 does. Every operation internal/distributed coordinates ends
    in a write to a key in one bucket every node can already read, so a protocol whose purpose is
    agreeing on a replicated state machine has nothing to replicate.

    The premises in this issue all hold, verified against source rather than taken on trust:
    applyLogEntry is three empty arms with no caller appending EntryTypeOperation; executeLocally
    calls the backend directly, never consulting the log, commit index, term, or leadership;
    executeStrongConsistency fans N identical PUTs of the same bytes at one key and accepts on a
    majority, which is a reachability signal rather than linearizability.

    The CAS primitive is proven by execution, not inferred from AWS documentation. Substrate v0.85.0
    implements conditional writes (from substrate#397) with a 64-stripe per-key mutex held across
    check→Put, so an exactly-one-winner result is meaningful rather than an artifact of last-write-wins.
    Over real HTTP: 32 concurrent If-None-Match: * PUTs → exactly 1 winner; stale If-Match → 412
    with the object unchanged; If-Match on an absent key → NoSuchKey, not 412; 8 workers in a
    read-ETag → increment → CAS loop converge to exactly 8 with zero lost updates; and PutObject
    returns a fresh ETag, so a CAS loop needs no HEAD between iterations.

    Two findings this issue did not anticipate, both changing caller code:

    1. 409 and 412 are not synonyms. 412 = lost race, recompute and retry. 409
      ConditionalRequestConflict = a delete interleaved; a PutObject may be retried as-is, but a
      CompleteMultipartUpload has a dead upload ID and must restart from CreateMultipartUpload. A
      loop conflating them spins until it gives up — and substrate models only 412, so that bug is
      invisible in testing today. Filed upstream as S3: conditional writes never return 409 Conflict, so the retry path a caller must take is untestable substrate#540.
    2. Ceph RGW does not support conditional writes at all, which forces the compatibility rule:
      fail closed. An unconditional fallback turns "exactly one node performs this tier transition"
      into "every node does" — the failure the coordination exists to prevent, occurring silently.
      Detection by attempt, not by configuration: a backend that succeeds at an If-Match probe
      against a known-absent key is silently ignoring preconditions, which a feature flag would never
      notice.

    The ceiling (§2 of the doc, the part to read before agreeing): no multi-key atomicity, and no
    liveness guarantee on leadership — from which follows the design obligation that every guarded
    action must re-assert the CAS
    , because an action guarded by "I checked my lease a moment ago" is
    not guarded. Raft fails closed on quorum loss; CAS fails closed only if the guarded action
    re-checks. Cost is per-attempt, since AWS bills failed conditional requests at normal rates.

    Issue consequences, for your call — I have not closed anything. If accepted: close #128, #130
    (currently priority: critical, and the largest single saving), #133 (the gossip networking
    survives, the proposal framing does not), #151. Keep #131 (needed more, not less — work
    distribution is how contention on coordination keys stays low), #132, #206. Open four: PutObjectIf
    plus sentinels and the probe · the lease type with the re-assert rule · replace
    executeStrongConsistency's fan-out and fix the consistency-level taxonomy · verify MinIO and
    Wasabi against real endpoints.

  4. added a commit that references this issue on Aug 3, 2026
  5. scttfrdmn commented on Aug 3, 2026

    @scttfrdmn
    OwnerAuthor

    Decision: adopted

    The recommendation in docs/design/conditional-writes-vs-raft.md is adopted. Per-key S3
    conditional writes (CAS) replace the Raft build-out as ObjectFS's coordination primitive; gossip
    remains the membership mechanism.

    Closed as not-the-direction:

    why
    #128 — ConsensusLog §1: there is nothing to replicate. applyLogEntry is three empty arms and nothing appends EntryTypeOperation
    #130 — PersistentState The largest single saving, and the only priority: critical one. Nodes hold no authoritative state, so the hardest correctness obligation in the Raft direction does not exist in the other
    #133 — real broadcastProposal Half real: the stub is a genuine defect, but proposals are a consensus concept. The surviving half — real gossip broadcast — already landed via #279/#280
    #151 — log compaction / Snapshot Premise does not hold: it would snapshot a state machine that does not exist

    Opened:

    #282 Backend.PutObjectIf + Precondition + the two sentinels + the S3 implementation + the capability probe. Blocks the rest
    #283 A lease over it, with the rule that every guarded action re-asserts the CAS. Its own issue because §2 calls that the single most important thing to get right
    #284 Replace executeStrongConsistency's N-identical-PUT fan-out; delete or redefine the consistency taxonomy
    #285 Verify conditional-write semantics against real MinIO and Wasabi endpoints — §4's two weak rows

    Kept, unchanged: #132 (gossip stats), #206 (gossip authentication — a real security defect either
    way). #131 (rendezvous hashing) has already landed, so selectConsistentHash is a real HRW ring and
    no longer nodes[:count].

    Two corrections to §5 of the doc, for the record

    1. §5's closure list of four omitted A3-1: Implement BboltPersistentState and BboltConsensusLog #150 (A3-1, BboltPersistentState / BboltConsensusLog).
      Its own Background states the dependency: "The ConsensusLog and PersistentState interfaces
      were defined in A1-1 and A1-3"
      — i.e. A1-1: Define ConsensusLog interface and in-memory implementation #128 and A1-3: Add PersistentState interface — Raft safety prerequisite #130, both now closed. There is nothing left for
      it to implement. It is still open because it was not among the four in the approved set;
      flagging rather than assuming.
    2. The doc.go item is already done. §5 lists correcting the "Linearizable operations across
      cluster" claim as owed regardless of direction; grep for Linearizable now returns nothing.

    Also worth noting for whoever picks up #284: ConsistencySession and ConsistencyEventual are
    now nearly the same function
    — both execute on targetNodes[0] and then replicateAsync the
    remainder. Session's only distinguishing feature is a comment promising it will "try to use the same
    node for related operations," and there is no session state anywhere to make that true. So the
    taxonomy offers three names for two behaviours, one of which (§1) is mislabeled.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area: distributedeffort: largeneeds-designpriority: mediumtype: enhancement

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions