This documentation package provides comprehensive information about OptimusDB's decentralized query mechanism, query strategies, and implementation guides.
- OptimusDB_Query_Strategies_Documentation.md (5.4 KB)
- Complete technical documentation of query strategies
- Architecture overview and data flow diagrams
- Implementation details and code examples
- Performance benchmarks and optimization techniques
- OptimusDB_Query_Strategies_Presentation.pptx (231 KB)
- Executive presentation for stakeholders
- Visual overview of architecture and strategies
- Key performance metrics and use cases
- SQLite_Metadata_OptimusDB_Guide.md (19 KB)
- Comprehensive guide for SQLite metadata integration
- Complete database schema definitions
- Go implementation examples
- Performance monitoring queries
- Deployment and maintenance procedures
OptimusDB implements 5 query strategies:
- LOCAL_ONLY - Query local node only (fastest, limited scope)
- REMOTE_ONLY - Query peer nodes only (distributed workload)
- LOCAL_THEN_REMOTE_MERGE - Query local first, then peers if needed (balanced, default)
- PARALLEL_MERGE - Query local and peers concurrently (maximum completeness)
- QUORUM - Continue until quorum achieved (consistency-critical)
Client Request
β
HTTP API (8089) β Query Engine β Strategy Selection
β β
Local Query β------------------β Peer Queries (via libp2p)
β β
Result Merge & Deduplication
β
Response to Client
| Strategy | Latency (P50) | Throughput |
|---|---|---|
| LOCAL_ONLY | 8ms | 5,000 qps |
| PARALLEL_MERGE | 95ms | 650 qps |
| QUORUM (n=3) | 210ms | 250 qps |
The SQLite metadata layer enhances OptimusDB with:
- Smart Peer Selection: Choose optimal peers based on reputation and response time
- Performance Tracking: Monitor query execution and cache effectiveness
- Network Analysis: Track connection quality and latency
- Data Distribution: Know which peers have which data ranges
// Initialize metadata store
metadataStore, err := metadata.NewMetadataStore("./optimusdb_metadata.db")
if err != nil {
log.Fatal(err)
}
// Use in query engine
engine := NewOptimizedEngine(10, 2*time.Second, 30*time.Second)
engine.SetMetadataStore(metadataStore)- β Development and testing
- β Privacy-sensitive queries
- β Known local data sufficiency
- β Distributed data requirements
- β Real-time analytics
- β Maximum data completeness needed
- β High-availability requirements
- β Bandwidth-constrained environments
- β Financial transactions
- β Consistency-critical operations
- β Byzantine fault tolerance scenarios
- β Low-latency requirements
- Enable Caching: 40-50% performance improvement with 30-second TTL
- Worker Pool Tuning: Set to CPU cores Γ 2 for optimal concurrency
- Smart Peer Selection: Use metadata to route queries to best-performing peers
- Strategy Selection: Choose based on consistency vs. performance trade-offs
{
"query_engine": {
"max_workers": 20,
"query_timeout_ms": 2000,
"cache_ttl_seconds": 30
},
"default_options": {
"strategy": "PARALLEL_MERGE",
"time_budget_ms": 2000,
"max_peers": 50,
"include_local": true
}
}- libp2p: P2P networking layer
- IPFS: Content-addressed storage
- OrbitDB: Decentralized database
- SQLite: Metadata and analytics
github.com/libp2p/go-libp2pberty.tech/go-orbit-dbgithub.com/mattn/go-sqlite3
- Peer Aggregation - Gather all connected and discovered peers
- Fan-out Limit - Apply MaxPeers constraint to control propagation
- Concurrent Propagation - Launch goroutine for each target peer
- Loop Prevention - Check tracePath to avoid query cycles
- Connection Attempt - Dial discovered but not yet connected peers
- Provenance Tagging - Add _source and _trace metadata to results
- Merge Results - Aggregate and deduplicate all peer responses
- Timeout Handling - Respect time budget to prevent deadlocks
curl -X POST http://localhost:8089/swarmkb/command \
-H "Content-Type: application/json" \
-d '{
"method": {"cmd": "querykbdata"},
"dstype": "dsswres",
"criteria": [{"status": "active", "region": "eu"}],
"options": {
"strategy": "PARALLEL_MERGE",
"time_budget_ms": 2000,
"max_peers": 10,
"include_local": true,
"annotate_source": true
}
}'{
"results": [
{
"_id": "record1",
"status": "active",
"region": "eu",
"_source": {
"type": "peer",
"peer_id": "QmPeer1...",
"path": ["QmInitiator...", "QmPeer1..."]
},
"_trace": {
"id": "uuid-trace-123",
"path": ["QmInitiator...", "QmPeer1..."]
}
}
]
}- CAP Theorem (Brewer, 2000)
- PACELC Framework (Abadi, 2012)
- Conflict-Free Replicated Data Types (Shapiro et al., 2011)
- Practical Byzantine Fault Tolerance (Castro & Liskov, 1999)
- Machine learning-based query planning
- Predictive peer selection and caching
- Causal+ consistency implementation
- Privacy-preserving query protocols
- Zero-knowledge proof validation
- Query Performance
- Execution time by strategy
- Cache hit rates
- Peer response times
- Network Health
- Peer availability
- Connection quality
- Latency distribution
- Data Distribution
- Records per peer
- Replication factor
- Data skew analysis
SELECT
strategy,
COUNT(*) as queries,
ROUND(AVG(execution_time_ms), 2) as avg_time_ms,
ROUND(AVG(peers_responded), 1) as avg_peers,
ROUND(SUM(CASE WHEN cache_hit THEN 1 ELSE 0 END) * 100.0 / COUNT(*), 2) as cache_hit_rate
FROM query_statistics
WHERE initiated_at >= datetime('now', '-24 hours')
GROUP BY strategy;- β Check network connectivity between peers
- β Review cache hit rates (target: >40%)
- β Adjust worker pool size (CPU cores Γ 2)
- β Consider switching to LOCAL_THEN_REMOTE_MERGE strategy
- β Verify peer connectivity and online status
- β Increase time_budget_ms
- β Check quorum_n settings
- β Review peer discovery logs
- β Reduce max_peers setting
- β Enable and tune caching
- β Use LOCAL_THEN_REMOTE_MERGE instead of PARALLEL_MERGE
- β Implement request batching
- Main Repository: https://github.com/georgegeorgakakos/optimusdb
- API Reference:
docs/INTERFACE.mdin repository - Architecture: See
README.mdin repository
- GitHub Issues for bug reports and feature requests
- Contributions welcome via pull requests
- Technical questions: Open GitHub issue
- Research collaboration: Contact OptimusDB team
All documentation and code examples are licensed under MPL 2.0.
Β© 2025 OptimusDB Research ICCS Team