Skip to main content

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:
Features:
  • 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:
Features:
  • 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 the KSyncStorage 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

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
Always handle storage errors gracefully:
Keep track of storage usage:
Implement backup strategies for important data:

Next Steps

Sync

Learn about real-time synchronization

Materializers

Transform events into queryable state

Performance Guide

Optimize your kSync application

Custom Storage Guide

Build your own storage backend