-
Notifications
You must be signed in to change notification settings - Fork 1
SYSTEM_ARCHITECT_GUIDE
GitHub Actions edited this page Jan 2, 2026
·
1 revision
category: "⚙️ Operations/Admin" version: "v1.3.0" status: "✅" date: "22.12.2025" audience: "System architects, principal engineers, CTOs"
Comprehensive architecture guide for enterprise-scale deployment.
- 📋 Übersicht
- ✨ Features
- 🚀 Quick Start
- 📖 Architecture & Design
- 💡 Best Practices
- 🔧 Troubleshooting
- 📚 Weitere Ressourcen
- 📝 Changelog
ThemisDB provides enterprise-grade horizontal sharding with Raft consensus and Google Spanner-inspired TrueTime for strong consistency across distributed deployments.
Target Audience: System architects, principal engineers, CTOs
Version: 1.3.0
Last Updated: December 2025
- 🔀 Horizontal Sharding - Raft + TrueTime (only open-source implementation)
- 📈 Billion-Scale - Migration playbooks from hyperscalers
- 💰 46% Cost Savings - vs. AWS complete stack
- 🌍 Distributed Transactions - SAGA pattern support
- 🔐 Enterprise Security - mTLS, RBAC, encryption
Key Topics:
- Horizontal sharding with Raft + TrueTime (only open-source implementation)
- Migration playbooks: AWS/GCP/Azure → ThemisDB
- 46% cost savings vs. AWS complete stack
- Capacity planning for billion-scale deployments
- Distributed transactions with SAGA pattern
- Horizontal Sharding Architecture
- Sharding Strategy & Design
- Distributed Transactions
- Consistency Models
- Multi-Shard Queries
- Migration from Hyperscalers
- Capacity Planning
- Scalability Patterns
- Disaster Recovery Architecture
- Security Architecture
- Cost Optimization
- Reference Architectures
┌──────────────────────────────────────────────────────────┐
│ ThemisDB Cluster │
│ │
│ ┌─────────────┐ ┌─────────────┐ ┌─────────────┐ │
│ │ Leader │ │ Follower │ │ Follower │ │
│ │ Shard 1 │ │ Shard 1 │ │ Shard 1 │ │
│ │ (Write) │──│ (Read) │──│ (Read) │ │
│ └─────────────┘ └─────────────┘ └─────────────┘ │
│ │ │
│ Raft Log │
│ WAL Replication │
│ TrueTime Coordination │
└──────────────────────────────────────────────────────────┘
Key Components:
- Raft Consensus: Leader election, log replication, strong consistency
- TrueTime: Distributed timestamps with uncertainty intervals
- WAL: Write-ahead logging for durability
- Circuit Breaker: Prevents cascade failures
// TrueTime timestamp with uncertainty interval
struct TrueTimeStamp {
uint64_t earliest; // Lower bound
uint64_t latest; // Upper bound
uint64_t now() const { return (earliest + latest) / 2; }
uint64_t uncertainty() const { return latest - earliest; }
};
// Wait for uncertainty to pass
void wait_for_safe_time(const TrueTimeStamp& ts) {
while (current_time() < ts.latest) {
std::this_thread::sleep_for(std::chrono::microseconds(10));
}
}Benefits:
- External consistency (linearizability)
- Snapshot isolation without locks
- Distributed transactions across shards
// Consistent hashing with virtual nodes
uint64_t compute_shard(const std::string& key) {
uint64_t hash = murmur3_hash(key);
return hash % num_shards;
}
// With 150 virtual nodes per shard for better distribution
uint64_t compute_shard_virtual(const std::string& key) {
uint64_t hash = murmur3_hash(key);
uint64_t vnode = hash % (num_shards * 150);
return vnode / 150; // Map to physical shard
}// Shard by key ranges (e.g., user IDs, timestamps)
struct ShardRange {
std::string start_key;
std::string end_key;
uint64_t shard_id;
};
std::vector<ShardRange> shard_map = {
{"0000", "2999", 0},
{"3000", "5999", 1},
{"6000", "9999", 2}
};// Dynamic shard rebalancing
void rebalance_shards() {
// 1. Detect imbalance (>20% size difference)
auto stats = collect_shard_statistics();
// 2. Create rebalancing plan
auto plan = create_rebalancing_plan(stats);
// 3. Execute with joint consensus (Raft membership change)
execute_rebalancing(plan);
}SAGATransaction saga;
// Step 1: Reserve inventory
saga.addStep(
[]() {
return inventory.reserve(productId, quantity);
},
[]() {
inventory.unreserve(productId, quantity); // Compensation
}
);
// Step 2: Charge payment
saga.addStep(
[]() {
return payment.charge(userId, amount);
},
[]() {
payment.refund(userId, amount); // Compensation
}
);
// Step 3: Create order
saga.addStep(
[]() {
return orders.create(order);
},
[]() {
orders.delete(orderId); // Compensation
}
);
// Execute with automatic rollback on failure
saga.execute();Advantages over 2PC:
- No blocking coordinator
- Better availability
- Eventual consistency with compensation
Current AWS Stack:
- RDS PostgreSQL: $2,000/month
- DynamoDB: $1,500/month
- SageMaker: $3,000/month
- Total: $6,500/month = $78K/year
ThemisDB Equivalent:
- ThemisDB Self-Hosted: $1,500/month (3 × c6i.8xlarge + storage)
- vLLM Co-Located: $0/month (uses same infrastructure)
- Total: $1,500/month = $18K/year
- Savings: $60K/year (77% reduction)
Migration Steps:
# Phase 1: Setup ThemisDB (Week 1-2)
1. Provision infrastructure (EC2 instances, EBS volumes)
2. Deploy ThemisDB cluster (3 nodes)
3. Configure backups to S3
4. Set up monitoring (CloudWatch → OpenTelemetry)
# Phase 2: Data Migration (Week 3-4)
1. Export data from RDS/DynamoDB
aws rds export-db-snapshot-to-s3 --snapshot-id snapshot-123
2. Transform to ThemisDB format
themisdb-migrator transform --source rds --target themisdb
3. Bulk load into ThemisDB
themisdb-admin bulk-load --source s3://migration-bucket/
# Phase 3: Dual-Write (Week 5-6)
1. Update application to write to both RDS and ThemisDB
2. Validate data consistency
3. Monitor performance and errors
# Phase 4: Read Migration (Week 7-8)
1. Gradually shift reads to ThemisDB (10% → 50% → 100%)
2. Monitor latency and errors
3. Validate business metrics
# Phase 5: Cutover (Week 9-10)
1. Disable writes to RDS/DynamoDB
2. Final data reconciliation
3. Decommission AWS servicesService Mapping:
| AWS Service | ThemisDB Equivalent | Migration Complexity |
|---|---|---|
| RDS PostgreSQL | Multi-Model Relational | Medium (schema mapping) |
| DynamoDB | Document Model | Low (direct mapping) |
| Aurora | Multi-Model + Sharding | Medium (sharding setup) |
| SageMaker | vLLM Co-Location | Medium (model deployment) |
| Pinecone | FAISS Advanced | Low (API compatible) |
| Timestream | Hypertables | Low (time-series native) |
Service Mapping:
| GCP Service | ThemisDB Equivalent |
|---|---|
| Cloud SQL | Multi-Model Relational |
| Firestore | Document Model |
| Cloud Spanner | Sharding + TrueTime (compatible!) |
| Vertex AI | vLLM Co-Location |
| BigQuery | Arrow Parquet Export → BigQuery |
Service Mapping:
| Azure Service | ThemisDB Equivalent |
|---|---|
| Azure SQL Database | Multi-Model Relational |
| Cosmos DB | Document + Graph |
| Azure ML | vLLM Co-Location |
Small Deployment (< 1TB data, < 10K QPS):
- 3 nodes (for HA)
- 16 vCPUs, 64 GB RAM per node
- 1 TB SSD per node
- Cost: ~$1,500/month (self-hosted AWS)
Medium Deployment (1-10 TB data, 10K-100K QPS):
- 5 nodes
- 32 vCPUs, 128 GB RAM per node
- 2 TB NVMe SSD per node
- Cost: ~$5,000/month (self-hosted AWS)
Large Deployment (10-100 TB data, 100K-1M QPS):
- 10 nodes
- 64 vCPUs, 256 GB RAM per node
- 10 TB NVMe SSD per node
- Cost: ~$20,000/month (self-hosted AWS)
# Billion vectors storage calculation
vectors = 1_000_000_000
dimensions = 1536
bytes_per_float = 4
# Flat storage
flat_storage = vectors * dimensions * bytes_per_float
print(f"Flat: {flat_storage / 1e12:.1f} TB") # 6.1 TB
# IVF+PQ compression
compression_ratio = 100 # 100x with PQ
compressed_storage = flat_storage / compression_ratio
print(f"IVF+PQ: {compressed_storage / 1e9:.1f} GB") # 61 GB# Add new shard to cluster
themisdb-admin shard add \
--node themisdb-4:8530 \
--rebalance-strategy gradual
# Monitor rebalancing progress
themisdb-admin shard status# Add read replica
themisdb-admin replica add \
--primary themisdb-1:8530 \
--replica themisdb-5:8530 \
--lag-threshold 100ms| Solution | Infrastructure | Operations | Total (3Y) | vs ThemisDB |
|---|---|---|---|---|
| ThemisDB | $54K | $113K | $167K | Baseline |
| AWS Stack | $234K | $65K | $299K | +79% |
| PostgreSQL | $156K | $76K | $232K | +39% |
| MongoDB | $180K | $75K | $255K | +53% |
Cost Savings Breakdown:
- Infrastructure: 46-77% (self-hosted vs managed)
- Embedding Cache: 70-90% API cost reduction
- vLLM Co-Location: Share GPU infrastructure
- Zero egress costs: Save 10-20% on data transfer
┌──────────────────────────────────────────────────────────────┐
│ Application Layer │
│ ┌────────────┐ ┌────────────┐ ┌────────────┐ │
│ │ Web App │ │ Mobile │ │ API │ │
│ └────────────┘ └────────────┘ └────────────┘ │
└──────────────────────────────────────────────────────────────┘
│
┌──────────────────────────────────────────────────────────────┐
│ ThemisDB + vLLM │
│ ┌────────────────────────────────────────────────────┐ │
│ │ ThemisDB (50 cores, 200 GB RAM, 30% GPU) │ │
│ │ - Vector Index (FAISS IVF+PQ, 1B vectors) │ │
│ │ - Embedding Cache (70-90% cost savings) │ │
│ │ - Hybrid Search (BM25 + Vector RRF) │ │
│ │ - Document Store │ │
│ └────────────────────────────────────────────────────┘ │
│ ┌────────────────────────────────────────────────────┐ │
│ │ vLLM (14 cores, 56 GB RAM, 70% GPU) │ │
│ │ - LLaMA 2 70B / GPT-3.5 equivalent │ │
│ │ - Low-priority CUDA streams │ │
│ └────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────┘
Performance:
- Query latency: 50-200ms (p99)
- Embedding cache hit rate: 80%+
- vLLM inference: 1-2ms (GPU) vs 5-10ms (CPU fallback)
- Throughput: 10K+ queries/sec
┌──────────────────────────────────────────────────────────────┐
│ IoT Devices (100K+) │
│ Sensors → Edge Gateways → Data Ingestion │
└──────────────────────────────────────────────────────────────┘
│
┌──────────────────────────────────────────────────────────────┐
│ ThemisDB Cluster │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Hypertables (TimescaleDB compatibility) │ │
│ │ - 1-day chunks (Column Families) │ │
│ │ - TTL-based retention (30 days) │ │
│ │ - ZSTD compression (5x storage reduction) │ │
│ └─────────────────────────────────────────────────────┘ │
│ ┌─────────────────────────────────────────────────────┐ │
│ │ Time-Series Aggregates (Arrow SIMD) │ │
│ │ - Resample (1-second → 1-minute) │ │
│ │ - Rolling windows (5-minute, 1-hour) │ │
│ │ - Percentiles (P50, P95, P99) │ │
│ │ - 5-10x faster than SQL │ │
│ └─────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────┘
Performance:
- Ingestion rate: 1M+ points/sec
- Query latency (aggregates): 10-100ms
- Storage efficiency: 80% compression
- Retention: Automatic with TTL
┌──────────────────────────────────────────────────────────────┐
│ Internet │
└──────────────────────────────────────────────────────────────┘
│
┌──────────────────────────────────────────────────────────────┐
│ WAF + DDoS Protection │
└──────────────────────────────────────────────────────────────┘
│
┌──────────────────────────────────────────────────────────────┐
│ Load Balancer (mTLS) │
└──────────────────────────────────────────────────────────────┘
│
┌──────────────────────────────────────────────────────────────┐
│ ThemisDB Cluster │
│ ┌────────────────────────────────────────────────────┐ │
│ │ Security Layer │ │
│ │ - mTLS (client certificate validation) │ │
│ │ - RBAC (role-based access control) │ │
│ │ - Audit logging (all operations) │ │
│ │ - Encryption at rest (AES-256) │ │
│ │ - Signed requests (RSA-SHA256) │ │
│ └────────────────────────────────────────────────────┘ │
└──────────────────────────────────────────────────────────────┘
Architect's Checklist:
- ✅ Design sharding strategy (hash vs range)
- ✅ Plan capacity for 3-5 year growth
- ✅ Calculate TCO vs hyperscaler alternatives
- ✅ Define migration strategy (strangler pattern)
- ✅ Implement security in depth (mTLS, RBAC, encryption)
- ✅ Design for HA and DR (RTO/RPO targets)
- ✅ Monitor and optimize costs continuously
Key Benefits:
- 46% cost savings vs AWS complete stack
- Billion-scale vector search capability
- Strong consistency with TrueTime
- Zero vendor lock-in (self-hosted, multi-cloud)
- Production-ready (9.3/10 audit rating)
Next Steps:
- Review Enterprise Edition Features for commercial offerings
- Read Architecture Overview for technical details
- Check Roadmap for future development plans
- Architecture-ACCESS-MODEL-IMPLEMENTATION-SUMMARY
- Architecture-ADR-003-pg-dump-sql-parser
- Architecture-BASEENTITY-PRINCIPLE
- Architecture-CACHE-STORAGE-INTEGRATION
- Architecture-CMAKE-ARCHITECTURE
- Architecture-CMAKE-FLAGS-REFERENCE
- Architecture-CMAKE-MODULAR-ARCHITECTURE
- Architecture-CONCERNS-ARCHITECTURE-DIAGRAM
- Architecture-CONCERNS-IMPLEMENTATION-SUMMARY
- Architecture-CONTENT-MODEL
- Architecture-COPILOT-THEMISDB-GRAPH-RAG-BACKEND-ARCHITECTURE
- Architecture-CRYPTO-AND-KEYS
- Architecture-FEATURE-FLAGS-REFERENCE
- Architecture-GPU-ARCHITECTURE-REVIEW-TEMPLATE
- Architecture-HTTP-SHUTDOWN-HARDENING
- Architecture-MIGRATION-GUIDE-CONCERNS
- Architecture-MIGRATION-GUIDE-v13-v14
- Architecture-MODULARIZATION-GUIDE
- Architecture-MODULAR-ARCHITECTURE-ROADMAP
- Architecture-MODULE-ARCHITECTURE-INDEX
- Architecture-P1D01-ISSMPLUGIN-DESIGN-REVIEW
- Architecture-P1-D01-ISSMPLUGIN-DESIGN-REVIEW
- Architecture-P1-D08-MAMBA-GOVERNANCE-CONTRACT
- Architecture-P1-P2-IMPLEMENTATION-COMPLETION-INDEX
- Architecture-PHASE0-COMPLETION-ASSESSMENT
- Architecture-PHASE3-QUERYENGINE-DI-ARCHITECTURE
- Architecture-PHASE4-INDEX-MANAGER-DI
- Architecture-POSTGRESQL-WIRE-PROTOCOL
- Architecture-QUERYENGINE-IMPLEMENTATION-GUIDE
- Architecture-QUERY-SCHEDULING
- Architecture-RAFT-CONSENSUS-DESIGN
- Architecture-README
- Architecture-README-SSM-HYBRID-IMPLEMENTATION
- Architecture-REFACTORING-SUMMARY
- Architecture-RESOURCE-POOLING
- Architecture-SOURCE-DIRECTORY-GUIDE
- Architecture-THEMIS-CORE-GUIDE
- Architecture-UNIFIED-ACCESS-MODEL
- Architecture-WAL-GRPC-MTLS-CONFIGURATION
- Architecture-WIRE-PROTOCOL-RETRY
- Architecture-boltzmann-observability-draft
- Architecture-experimental-logarithmic-vector-storage
- Architecture-llm-wiki-mvp-adr
- Architecture-rewrite-engine-architecture
- Architecture-rope-api-architecture
- Architecture-ssm-gguf-mamba-status
- Architecture-ssm-hybrid-analysis
- Architecture-ssm-hybrid-rollout-plan
- Architecture-ssm-plugin-interface-design-review
- Architecture-transaction-coordinators
- Architecture-wiki-secondary-index
- Architecture-wire-protocol
- Governance-DISABLED-STUB-POLICY
- Governance-DOCS-PR-POLICY
- Governance-GA-PROMOTION-SIGN-OFF
- Governance-GITHUB-MILESTONES-SETUP
- Governance-MATURITY-CLAIM-VERIFICATION-CHECKLIST
- Governance-MATURITY-EVIDENCE-REGISTRY
- Governance-MERGE-GATE-BOT-CONFIG
- Governance-MERGE-GATE-STATUS-LIVE
- Governance-PHASE3-ENFORCEMENT-RUNBOOK
- Governance-PHASE-1-CLOSURE-REPORT
- Governance-PHASE-CLOSURE-POLICY
- Governance-PHASE-DEPENDENCY-GRAPH
- Governance-PLUGIN-SUBMODULE-ROLLBACK
- Governance-PRODUCTION-READY-2026-DELIVERY-PLAN
- Governance-PR-VERSION-TARGETING
- Governance-PR-VERSION-TARGETING-BACKFILL
- Governance-QUERY-MODULE-STATUS
- Governance-README
- Governance-RELEASE-PROMOTION-GATE-POLICY
- Governance-RELEASE-VALIDATION-CHECKLIST
- Governance-SECURITY-MODULE-5671-EVIDENCE-SUMMARY
- Governance-SHARDING-P6-RESIDUAL-RISK-ACCEPTANCE
- Governance-SOURCECODE-COMPLIANCE-GOVERNANCE
- Governance-UPDATES-DEVELOPMENT-STATUS-SIGN-OFF
- Governance-WAVE-C-IMPLEMENTATION-COMPLETE
- Module-acceleration-Roadmap
- Module-access-model-Roadmap
- Module-ai-Roadmap
- Module-analytics-Roadmap
- Module-api-Roadmap
- Module-aql-Roadmap
- Module-auth-Roadmap
- Module-base-Roadmap
- Module-cache-Roadmap
- Module-cdc-Roadmap
- Module-chaos-Roadmap
- Module-chimera-Roadmap
- Module-config-Roadmap
- Module-content-Roadmap
- Module-core-Roadmap
- Module-distributed-knowledge-Roadmap
- Module-distributed-tensor-Roadmap
- Module-document-Roadmap
- Module-ethics-ai-Roadmap
- Module-evaluation-Roadmap
- Module-execution-Roadmap
- Module-exporters-Roadmap
- Module-failover-Roadmap
- Module-geo-Roadmap
- Module-governance-Roadmap
- Module-gpu-Roadmap
- Module-graph-Roadmap
- Module-image-analysis-Roadmap
- Module-importers-Roadmap
- Module-index-Roadmap
- Module-ingestion-Roadmap
- Module-llama-cpp-Roadmap
- Module-llm-Roadmap
- Module-llm-streaming-Roadmap
- Module-llm-wiki-Roadmap
- Module-maintenance-Roadmap
- Module-metadata-Roadmap
- Module-network-Roadmap
- Module-observability-Roadmap
- Module-onnx-clip-Roadmap
- Module-performance-Roadmap
- Module-plugins-Roadmap
- Module-process-Roadmap
- Module-projects-Roadmap
- Module-prompt-engineering-Roadmap
- Module-query-Roadmap
- Module-rag-Roadmap
- Module-replication-Roadmap
- Module-retrieval-Roadmap
- Module-rpc-grpc-Roadmap
- Module-scheduler-Roadmap
- Module-scraper-Roadmap
- Module-search-Roadmap
- Module-security-Roadmap
- Module-server-Roadmap
- Module-sharding-Roadmap
- Module-stable-diffusion-Roadmap
- Module-storage-Roadmap
- Module-temporal-Roadmap
- Module-tensor-Roadmap
- Module-themis-Roadmap
- Module-timeseries-Roadmap
- Module-toolbox-Roadmap
- Module-training-Roadmap
- Module-transaction-Roadmap
- Module-updates-Roadmap
- Module-user-storage-encrypted-Roadmap
- Module-utils-Roadmap
- Module-vector-search-Roadmap
- Module-voice-Roadmap
- Module-whisper-Roadmap