Overview
kSync provides flexible storage options to persist events locally. The storage layer is responsible for maintaining the event log and ensuring data durability across application restarts.IndexedDB
Browser-native storage with persistence and efficient querying
Memory
Fast in-memory storage for servers and testing environments
Custom
Implement your own storage backend for specific requirements
Automatic
kSync automatically chooses the best storage for your environment
Storage Implementations
IndexedDB Storage (Browser)
The default storage for browser environments, providing persistent storage across sessions:- Persistent: Data survives browser restarts and crashes
- Efficient: Optimized for event querying and retrieval
- Indexed: Fast lookups by event type, timestamp, and version
- Transactional: ACID compliance for data integrity
- Quota Management: Automatic cleanup of old events
Memory Storage (Server/Testing)
Fast in-memory storage ideal for servers and testing:- Fast: Blazing fast read/write operations
- Simple: No setup or configuration required
- Ephemeral: Data is lost on restart (by design)
- Testing: Perfect for unit tests and development
Storage Interface
All storage implementations follow theKSyncStorage interface:
Custom Storage Implementation
Create your own storage backend for specific requirements:SQLite Storage Example
Redis Storage Example
Storage Configuration
Automatic Storage Selection
kSync automatically selects the best storage for your environment:Explicit Storage Configuration
Performance Considerations
Event Cleanup
Prevent memory/storage bloat by cleaning up old events:Batch Operations
Use batch operations for better performance:Indexing Strategy
Design your storage schema for efficient queries:Storage Migration
Handle storage schema changes gracefully:Best Practices
Choose the Right Storage
Choose the Right Storage
Select storage based on your requirements:
- IndexedDB: Browser apps needing persistence
- Memory: Servers, testing, temporary data
- SQLite: Desktop apps, mobile apps
- Redis: Distributed systems, caching
- PostgreSQL: Enterprise apps, complex queries
Handle Storage Errors
Handle Storage Errors
Always handle storage errors gracefully:
Monitor Storage Usage
Monitor Storage Usage
Keep track of storage usage:
Backup and Recovery
Backup and Recovery
Implement backup strategies for important data:

