Repository navigation
Closed
Description
SurrealDB Migration - Hybrid Architecture (Desktop-Only)
Context
Following successful completion of Epic #460 (SurrealDB Feasibility PoC), this epic tracks the migration from Turso to a hybrid database architecture:
- Desktop: SurrealDB embedded (RocksDB backend)
- Mobile: Turso (existing implementation)
PoC Findings Summary
Phase 1 Results (Desktop Embedding):
- ✅ Binary size: 10MB (50% under 20MB threshold)
- ✅ Startup time: 52ms (90% under 500ms threshold)
- ✅ SCHEMALESS: 100% working with arbitrary properties
- ✅ Dot notation queries: Clean and intuitive
Phase 2 Results (Scale & Performance):
- ✅ 100K nodes: Query in 104ms (90% under threshold)
- ✅ Deep pagination: 8.3ms (exceptional, no degradation)
- ✅ Complex queries: 211ms avg (within bounds)
Architect Recommendation: Proceed with Hybrid Migration (85% confidence)
Migration Strategy
Approach: Trait-based abstraction layer enabling parallel implementations without data migration.
Key Principles:
- No breaking changes to existing code
- Feature-flagged rollout (gradual A/B testing)
- Performance monitoring at every stage
- Mobile strategy deferred (evaluate in 6 months)
Architecture
trait NodeStore {
async fn create_node(&self, node: Node) -> Result<Node>;
async fn query_nodes(&self, filter: NodeFilter) -> Result<Vec<Node>>;
// ... (complete trait in sub-issues)
}
// Factory pattern for backend selection
let store: Box<dyn NodeStore> = if cfg!(feature = "surrealdb") {
Box::new(SurrealStore::new(path).await?)
} else {
Box::new(TursoStore::new(connection).await?)
};Phases
Phase 1: Abstraction Layer (Week 1-2)
Create trait-based abstraction and wrap existing Turso implementation.
Phase 2: SurrealDB Implementation (Week 2-3)
Implement NodeStore trait for SurrealDB using PoC code as foundation.
Phase 3: Testing & Validation (Week 3-4)
A/B testing framework, performance monitoring, parallel testing.
Phase 4: Gradual Rollout (Week 5-6)
Feature-flagged rollout: 10% → 25% → 50% → 100% (desktop only).
Success Criteria
- Zero regressions in existing Turso functionality
- SurrealDB performance meets/exceeds PoC benchmarks
- A/B testing shows <2% performance delta
- Desktop users can switch backends without data loss
- Complete test coverage for both backends
Out of Scope
- Data migration: Not needed (early development phase)
- Mobile migration: Deferred for 6 months (Turso remains mobile backend)
- Schema changes: Using SCHEMALESS mode for dynamic properties
Dependencies
- Epic SurrealDB Feasibility PoC - Quick Evaluation #460 (SurrealDB PoC) - ✅ Completed
- Existing Turso implementation - ✅ Stable
References
- Epic SurrealDB Feasibility PoC - Quick Evaluation #460: SurrealDB Feasibility PoC
/docs/architecture/data/surrealdb-feasibility-report.md- Architect's migration plan (6-week timeline with complete code)
Activity
Complete SurrealDB Feasibility PoC - All GO Criteria Met (#460)
malibio commentedon Nov 11, 2025
Test Baseline
Test Results (Before Implementation):
Test breakdown:
Status: Proceeding with Epic #461 implementation (SurrealDB Migration - Hybrid Architecture)
malibio commentedon Nov 11, 2025
Epic #461 Implementation Plan - Senior Architect Analysis
Executive Summary
After thorough architectural review, recommend implementing PHASE 1 ONLY for this epic:
✅ SCOPE FOR EPIC #461 (Phase 1):
❌ DEFER TO FUTURE EPICS:
Why Phase 1 Only?
Risk Mitigation (Critical):
Incremental Validation:
Architecture Design
NodeStore Trait (24 methods):
Abstraction Layer Location:
Implementation Strategy
3-Step Refactoring Process:
Arc<dyn NodeStore>instead of direct DatabaseServiceBranch Strategy: Single branch (
feature/issue-461-phase1-abstraction-layer)bun run test:allafter EACH commitSuccess Criteria
Timeline
2 weeks (14 days):
Risk Assessment
Confidence Level: 95% - Proven refactoring pattern with clear validation
Risk Level: LOW - Minimal complexity, easily reversible with feature flag
Next Steps
Proceeding with Phase 1 implementation. Full architectural details available in senior architect analysis.
Add Epic #461 Phase 1 architectural planning documentation
Address code review feedback for Epic #461 Phase 1 planning
malibio commentedon Nov 11, 2025
Architectural Decision: No Feature Flags for Backend Selection
Based on review feedback and project phase, we've simplified the migration approach by removing feature flag complexity.
Decision
No
--features surrealdbflag. Instead:git revertfor rollbackRationale
Early Development Phase
Simpler Implementation
#[cfg(feature = "surrealdb")])Cleaner Rollback
git reverttakes <1 hour (vs maintaining dual backends)Updated Rollback Plans
Phase 1 Rollback (Abstraction Layer):
Phase 2 Rollback (SurrealDB Implementation):
What This Means for Implementation
Phase 1 (Current):
NodeStoretrait with 22 methodsTursoStorewrapperNodeServiceto use traitPhase 2 (Future):
SurrealStorewith same 22 methodsTursoStore::new()→SurrealStore::new()Documentation Updated
All planning docs reflect this decision:
node-store-abstraction.md- No transaction method (deferred to Phase 2)surrealdb-migration-roadmap.md- Feature flags removed, git revert rollbacksurrealdb-migration-guide.md- Updated method count (22 methods)See PR #467 for complete changes.
SurrealDB Migration - Hybrid Architecture (Desktop-Only) (#467)
Extract create_node SQL to DatabaseService (#462)
Document SCHEMAFULL + FLEXIBLE pattern for SurrealDB migration (#469)
5 remaining items
malibio commentedon Nov 12, 2025
Phases 1-3 complete and merged. Phase 4 (gradual rollout) closed as unnecessary for pre-production software. Next: Issue #467 will remove abstraction layer and switch directly to SurrealDB.
SurrealDB Migration - Hybrid Architecture (Desktop-Only) (#467)
Extract create_node SQL to DatabaseService (#462)
Document SCHEMAFULL + FLEXIBLE pattern for SurrealDB migration (#469)
Fix TursoStore test failures - use TempDir and parse SQLite timestamps
Implement A/B Testing Framework for Backend Comparison (#465)
SurrealDB Migration - Hybrid Architecture (Desktop-Only) (#467)
Extract create_node SQL to DatabaseService (#462)
Document SCHEMAFULL + FLEXIBLE pattern for SurrealDB migration (#469)
Fix TursoStore test failures - use TempDir and parse SQLite timestamps
Implement A/B Testing Framework for Backend Comparison (#465)
Extract create_node SQL to DatabaseService (#462)
Fix TursoStore test failures - use TempDir and parse SQLite timestamps
Implement A/B Testing Framework for Backend Comparison (#465)