<!-- llms-explorer concept facts · https://llms-explorer.com/tree/two-phase-simultaneous-index-builds/ · pack 2026-10-30 · ~1386 tokens -->

# Two-phase (simultaneous) index builds

> Source-anchored research for Two-phase (simultaneous) index builds. Run status: COMPLETED.

Parent: [Resumable index builds](https://llms-explorer.com/tree/resumable-index-builds/) · 4 facets · 15 facts · page: https://llms-explorer.com/tree/two-phase-simultaneous-index-builds/

## How it works

- Hybrid building is the local mechanism used underneath simultaneous builds: writes are captured in a side-writes table while collection scanning and key loading proceed, and final draining requires an exclusive collection lock. Simultaneous building does not mean the collection is never locked. (medium confidence) — [source](https://github.com/mongodb/mongo/blob/master/src/mongo/db/index_builds/README.md)
- A secondary must retain records of indexing errors for later constraint checking because it can become primary before the build commits; simply discarding those errors would lose the information needed to ensure consistency. (medium confidence) — [source](https://github.com/mongodb/mongo/blob/master/src/mongo/db/index_builds/README.md)
- For the MongoDB 8.0 documented recovery path, clean shutdown can preserve progress, whereas a process crash restarts construction from the beginning; resumability additionally depends on eligibility conditions, including the default votingMembers commit quorum. (high confidence) (verified as of 2026-10-30) — [source](https://www.mongodb.com/docs/v8.0/core/index-creation/)

## Problems, failure modes and limitations

- SERVER-85284 reports that attempting to abort two independent builds on the same collection in one named-index dropIndexes operation can fail with BackgroundOperationInProgressForNamespace (12587); the report distinguishes separate buildUUIDs from multiple indexes belonging to one builder. (low confidence) — [source](https://jira.mongodb.org/browse/SERVER-85284)

## Comparisons and alternatives

- MongoDB introduced simultaneous replica-set index building in 4.4: data-bearing members build locally in parallel instead of secondaries waiting for the primary to finish before starting. (high confidence) — [source](https://github.com/mongodb/mongo/blob/master/src/mongo/db/index_builds/README.md)
- The MongoDB 8.0 manual documents checkpoint resumption only once for the same in-progress build. SERVER-115247 explains that repeated resumption is constrained by unavailable majority-commit information during replication recovery and records a proposed solution rather than an implemented guarantee. (medium confidence) (verified as of 2026-07-22) — [source](https://www.mongodb.com/docs/v8.0/core/index-creation/)
- MongoDB introduced simultaneous replica-set index builds in 4.4; the documented path requires FCV 4.4 or later on each member. Secondaries build alongside the primary instead of waiting for its completed index. (high confidence) — [source](https://www.mongodb.com/docs/v8.0/core/index-creation/)
- The server design documents an exception for empty collections: these can use a synchronous, single-phase createIndexes oplog entry instead of the two-phase background-build protocol. (low confidence) (verified as of 2026-10-30) — [source](https://github.com/mongodb/mongo/blob/master/src/mongo/db/index_builds/README.md)

## Facts and statements

- The primary replicates startIndexBuild; secondaries begin background work after applying that entry. The primary later replicates commitIndexBuild or abortIndexBuild, which determines the secondary builds’ outcome. (high confidence) — [source](https://github.com/mongodb/mongo/blob/master/src/mongo/db/index_builds/README.md)
- Each replica independently scans its own collection and builds its local index. The node that starts the build need not remain primary through completion; the protocol supports replica-set role changes. (low confidence) — [source](https://github.com/mongodb/mongo/blob/master/src/mongo/db/index_builds/README.md)
- Two-phase coordination alone does not guarantee restart resumption. MongoDB's server design describes persisting the build phase, sorter state and internal table identifiers on clean shutdown, then reconstructing the build on startup; the 8.0 manual states that a crash instead restarts the build from the beginning. (medium confidence) — [source](https://github.com/mongodb/mongo/blob/master/src/mongo/db/index_builds/README.md)
- Each member constructs its index from its own collection data. Thus simultaneous builds overlap in time; they do not copy a completed primary index or require perfectly synchronized starts. (high confidence) — [source](https://github.com/mongodb/mongo/blob/master/src/mongo/db/index_builds/README.md)
- Two-phase describes the replicated coordination protocol, not a two-step local construction algorithm. Local construction includes collection scanning, sorting, bulk loading, and draining intercepted writes. (high confidence) — [source](https://github.com/mongodb/mongo/blob/master/src/mongo/db/index_builds/README.md)
- A running simultaneous build can survive a replica-set role change: the member that starts it need not be the member that decides to commit it. (low confidence) — [source](https://github.com/mongodb/mongo/blob/master/src/mongo/db/index_builds/README.md)
- The hybrid local algorithm permits reads and writes during most construction, but exclusive collection locks still bracket the build; simultaneous construction does not imply a lock-free operation. (high confidence) — [source](https://github.com/mongodb/mongo/blob/master/src/mongo/db/index_builds/README.md)
