Skip to content

Conversation

@sagdelen
Copy link

@sagdelen sagdelen commented Dec 28, 2025

What changed?

This PR adds MongoDB as a new persistence backend for Temporal Server, implementing the Direct Factory pattern (similar to Cassandra).

New Components:

  • common/persistence/mongodb/ - Complete MongoDB persistence plugin implementation

    • client/ - MongoDB client abstraction layer with topology detection
    • All store implementations: ShardStore, ExecutionStore, TaskStore, MetadataStore, ClusterMetadataStore, Queue, QueueV2, NexusEndpointStore
    • Native visibility store with SQL-to-MongoDB query conversion
    • Transaction support for replica sets with standalone fallback
  • config/development-mongodb.yaml - Development configuration for MongoDB

  • schema/mongodb/temporal/ - MongoDB schema initialization scripts

  • docs/development/persistence/ - Comprehensive documentation

    • persistence-plugin-development-guide.md - General guide for new persistence plugins
    • mongodb-persistence-plugin.md - MongoDB-specific implementation details
    • sql-vs-mongodb-persistence-comparison.md - Detailed comparison of SQL vs MongoDB schema design, denormalization decisions, and implementation challenges
  • Docker Compose integration with MongoDB replica set setup

  • Prometheus alerts for MongoDB monitoring

Why?

MongoDB is a widely adopted document database that offers:

  • Flexible schema evolution without migrations
  • Native JSON/BSON document storage aligned with Temporal's data model
  • Multi-document ACID transactions (replica sets)
  • Rich indexing capabilities for visibility queries
  • Large existing user base requesting MongoDB support

This expands Temporal's persistence options beyond SQL databases and Cassandra, giving users more flexibility in choosing their preferred database technology.

How did you test it?

  • built
  • run locally and tested manually
  • covered by existing tests
  • added new unit test(s)
  • added new functional test(s)

Testing Details:

  • Unit tests for all store implementations (*_test.go files)
  • Integration tests using persistence test suites (common/persistence/tests/mongodb_test.go)
  • Local testing with MongoDB replica set via Docker Compose
  • Ran make unit-test, make integration-test, make functional-test
  • Verified with make lint-code - 0 issues

Potential risks

  1. Transaction Support: MongoDB transactions require replica set deployment. Standalone mode works but without transactional guarantees - documented as development-only configuration.

  2. Query Conversion: The visibility query converter translates SQL-like queries to MongoDB aggregation pipelines. Complex queries may have edge cases not yet covered.

  3. Performance: While MongoDB is performant, this is a new implementation without production-scale benchmarking. Performance characteristics may differ from SQL/Cassandra implementations.

  4. New Dependency: Adds go.mongodb.org/mongo-driver to go.mod. This is the official MongoDB Go driver with active maintenance.

Implement MongoDB as a persistence backend for Temporal Server.
This plugin follows the Direct Factory pattern (like Cassandra).

Features:
- Full DataStoreFactory implementation with all stores
- Multi-document transaction support for replica sets
- Standalone mode fallback for development
- Native MongoDB visibility store with query conversion
- Docker Compose integration for local development
- Comprehensive unit and integration tests

New configuration: development-mongodb.yaml
Documentation: docs/development/persistence/
@sagdelen sagdelen requested review from a team as code owners December 28, 2025 12:05
@CLAassistant
Copy link

CLAassistant commented Dec 28, 2025

CLA assistant check
All committers have signed the CLA.

@sagdelen sagdelen marked this pull request as draft December 28, 2025 12:26
@sagdelen sagdelen force-pushed the feature/mongodb-plugin branch from 7705f5e to df7822c Compare December 28, 2025 14:11
@sagdelen sagdelen marked this pull request as ready for review December 28, 2025 14:17
@sagdelen sagdelen marked this pull request as draft December 28, 2025 14:28
The historyNodeFilter function had a bug where the MaxNodeID constraint
was not properly combined with the pagination $or condition. When using
token-based pagination, the $or filter for getting the next page of
results was not being AND-ed with the MaxNodeID upper bound.

Fixed by using $and to properly combine the pagination condition with
the MaxNodeID constraint when both are present.

Also removed MongoDB-specific workarounds from ndc_test.go since the
pagination bug is now fixed and MongoDB should return the same batch
counts as other persistence backends.
- Remove visibility store caching in MongoDB factory to ensure each
  service gets a store with its own chasm.Registry
- Convert ConverterError to InvalidArgument in buildQueryFilter for
  proper error handling
- Add ActivityId → WorkflowID transformation in query converter
  (upstream bug fix matching resolve.go behavior)
@sagdelen sagdelen marked this pull request as ready for review December 28, 2025 18:48
- Add MongoDB replica set service to docker-compose
- Add MongoDB to functional-test, functional-test-xdc, and
  functional-test-ndc CI matrices
QEMU is required for cross-platform Docker builds (arm64 on amd64 runner)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants