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
| Backend | Use Case | Trade-offs |
|---|---|---|
SqliteBackend | Primary; embedded, ACID | Single-process access |
PostgresBackend | Multi-user, ACID | Requires PostgreSQL server |
FilesystemBackend | Fallback; simple | No transactional guarantees |
§Error Modes and Guarantees
All backends return Result<T> with errors propagated via crate::Error.
§Transactional Behavior
| Backend | Atomicity | Isolation | Durability |
|---|---|---|---|
SQLite | Full ACID | Serializable | On commit (WAL) |
| PostgreSQL | Full ACID | Serializable | On commit |
| Filesystem | None | None | On fsync |
§Error Recovery
| Error Type | Recovery Strategy |
|---|---|
Error::Storage | Retry with exponential backoff |
Error::NotFound | Expected for missing IDs; handle gracefully |
Error::InvalidInput | Validate input before calling |
Error::OperationFailed | Log and surface to user |
§Consistency Guarantees
- Read-after-write: Guaranteed for all backends
- Concurrent writes:
SQLiteuses WAL mode with busy timeout;PostgreSQLuses transactions - Partial failures:
SQLiterolls back;PostgreSQLrolls back
Traits§
- Persistence
Backend - Trait for persistence layer backends.