Skip to main content

Module persistence

Module persistence 

Source
Expand description

Persistence backend trait.

The persistence layer is the authoritative source of truth for all memories. It handles durable storage, ensuring memories survive process restarts.

§Available Implementations

BackendUse CaseTrade-offs
SqliteBackendPrimary; embedded, ACIDSingle-process access
PostgresBackendMulti-user, ACIDRequires PostgreSQL server
FilesystemBackendFallback; simpleNo transactional guarantees

§Error Modes and Guarantees

All backends return Result<T> with errors propagated via crate::Error.

§Transactional Behavior

BackendAtomicityIsolationDurability
SQLiteFull ACIDSerializableOn commit (WAL)
PostgreSQLFull ACIDSerializableOn commit
FilesystemNoneNoneOn fsync

§Error Recovery

Error TypeRecovery Strategy
Error::StorageRetry with exponential backoff
Error::NotFoundExpected for missing IDs; handle gracefully
Error::InvalidInputValidate input before calling
Error::OperationFailedLog and surface to user

§Consistency Guarantees

  • Read-after-write: Guaranteed for all backends
  • Concurrent writes: SQLite uses WAL mode with busy timeout; PostgreSQL uses transactions
  • Partial failures: SQLite rolls back; PostgreSQL rolls back

Traits§

PersistenceBackend
Trait for persistence layer backends.