This guide covers deploying, monitoring, and scaling LATTICE.DB.
For applications that embed LATTICE.DB:
db, err := lattice.Open("./data", &lattice.Options{
EncryptionKey: loadKeyFromSecureStorage(),
})
if err != nil {
log.Fatal(err)
}
defer db.Close()File Location:
- Use app-specific directory (not user documents)
- Ensure sufficient disk space
- Consider backup strategy
Concurrent Access:
- Multiple goroutines can safely share a DB instance
- Each goroutine should use separate transactions
- Writable transactions serializably at commit
Resource Limits:
- Monitor memory usage with large datasets
- Set appropriate cache size based on working set
- Close database when application exits
- Transaction Throughput: Transactions per second
- Latency: P50, P95, P99 commit latency
- WAL Size: Current WAL file size
- Cache Hit Rate: Percentage of cache hits
- Sync Status: Last sync time, error count
// Get database stats
stats := db.Stats()
fmt.Printf("Transactions: %d\n", stats.TransactionCount)
fmt.Printf("Cache hits: %d\n", stats.CacheHits)
fmt.Printf("WAL size: %d\n", stats.WALSize)// Verify database integrity
result, err := db.Verify()
if err != nil {
// Database error
return err
}
if !result.Passed() {
// Database corruption detected
log.Printf("Corruption: %v", result.Errors)
}LATTICE.DB files can be backed up using standard tools:
# Hot backup (database can be in use)
cp -R /path/to/data /backup/location/data-$(date +%Y%m%d)
# Or use rsync for incremental backups
rsync -av /path/to/data/ /backup/location/# Stop application
# Restore backup
cp -R /backup/location/data-20250101 /path/to/data
# Start applicationImportant:
- Ensure database is not running during restore
- Verify file permissions
- Consider running verification after restore
Run periodic verification:
lattice verify --data=/path/to/dataRemove orphaned data:
lattice scrub --data=/path/to/dataUse --dry-run first to preview changes.
WAL segments are automatically compacted, but you can trigger manual compaction:
lattice compact --data=/path/to/dataMore Memory:
- Increase cache size
- Reduces disk I/O
- Better performance for large working sets
Faster Storage:
- Use SSD instead of HDD
- Reduces WAL latency
- Improves commit performance
LATTICE.DB scales horizontally via the sync server:
+-----------+ +-----------+ +-----------+
| Device 1 | <---> | Sync | <---> | Device 2 |
+-----------+ +-----------+ +-----------+
^
|
+-----------+
| Device 3 |
+-----------+
Server Considerations:
- Stateless operation (can load balance)
- Blob storage for encrypted chunks
- Rate limiting per device
- Session timeout management
For very large datasets, consider:
- Separate collections per tenant
- Separate database files per service
- Application-level sharding
Symptoms: High commit latency
Causes:
- WAL sync bottleneck
- Large transactions
- Cache misses
Solutions:
- Batch operations in single transaction
- Increase WAL segment size
- Add more memory to cache
Symptoms: Memory grows over time
Causes:
- Uncommitted transactions holding versions
- Large transactions
- Cache too large
Solutions:
- Commit transactions more frequently
- Reduce transaction size
- Reduce cache size
- Restart application (clears versions)
Symptoms: Many merge conflicts
Causes:
- Same documents edited concurrently
- High contention on hot documents
Solutions:
- Use document-level sharding
- Implement application-level conflict resolution
- Use collaborative editing patterns
Symptoms: Verification fails
Steps:
- Run
lattice verifyfor detailed report - If WAL corruption, truncate WAL to last valid record
- If data corruption, run
lattice repair - Restore from backup if repair fails
// Instead of:
for _, item := range items {
tx, _ := db.Begin(true)
tx.Insert("items", item)
tx.Commit()
}
// Do:
tx, _ := db.Begin(true)
for _, item := range items {
tx.Insert("items", item)
}
tx.Commit()// Use indexes
schema.Fields["email"].Indexed = true
// Limit results
query.Limit = 100
// Use specific fields
query.Fields = []string{"name", "email"}// Estimate cache size based on working set
workingSetPages := 10000 // ~40MB at 4KB pages
opts := &lattice.Options{
CacheSize: workingSetPages,
}Never hardcode keys:
// BAD
key := []byte{0x01, 0x02, ...}
// GOOD
key := os.Getenv("LATTICE_KEY")
keyBytes, _ := hex.DecodeString(key)Use key derivation:
// Derive from password with salt
masterKey := crypto.DeriveKey(password, salt)Enable encryption for sensitive data:
key := loadKeyFromSecureStorage()
db, _ := lattice.Open("./data", &lattice.Options{
EncryptionKey: key,
})- Always use HTTPS in production
- Validate server certificates
- Rotate device keys periodically
- Monitor for unauthorized access
- Daily Incremental Backups: WAL segments only
- Weekly Full Backups: Entire data directory
- Off-site Storage: Cloud or remote server
- Backup Verification: Periodically test restore
- Stop application
- Identify last good backup
- Restore data directory
- Run verification
- Start application
- Sync to catch up
- Verification Failed: Database corruption detected
- High WAL Size: WAL not compacting
- Sync Failure: Can't reach sync server
- High Latency: Performance degradation
- Low Disk Space: <10% remaining