liveBook · Manning

Storage abstraction

As explained in Designing AI Systems

A storage abstraction is an interface or design boundary that separates data-storage operations from the underlying persistence technology.

A storage abstraction separates session logic from persistence technology. This matters when requirements conflict: PostgreSQL provides durability and auditability, Redis provides speed, and DynamoDB provides automatic scaling. Rather than forcing one backend on every deployment, the service delegates persistence through a replaceable interface. section 4.3 section 4.3.1

The Session Service owns request validation, business rules, and response formatting. A configured storage implementation owns persistence details. The service calls interface methods such as get_or_create_session() and add_messages() without knowing whether they become PostgreSQL queries, Redis commands, or another backend. section 4.3 section 4.4.3

A practical implementation follows a small set of boundaries:

  • Define the storage interface around domain operations, such as retrieving or creating sessions and adding messages. section 4.4.3
  • Implement the interface for a selected backend; PostgreSQL is suited to durable, consistent, auditable session data, while alternatives support different latency, flexibility, or operations requirements. section 4.3.1
  • Inject the chosen implementation into the service constructor instead of instantiating a concrete storage class inside service logic. section 4.4.3
  • Reuse the same abstraction pattern for different domains while changing the operations: session storage looks up messages by ID, whereas vector storage searches floating-point embeddings by similarity. section 5.4

Swapping a session backend

A gRPC SessionServiceServicer receives Protocol Buffer requests, calls its injected SessionStorage object, and returns Protocol Buffer responses. Replacing PostgreSQL with Redis changes the configured implementation rather than the service methods or client code. Production migration still requires planning because moving millions of sessions is not automatic. section 4.4.3 section 4.3.1

Figure 4.3 The Session Service architecture. The SessionServiceServicer class receives Protocol Buffer requests from the API gateway and delegates to the abstract SessionStorage interface, enabling different storage backends to be swapped without changing service code.

Use the architecture figure to trace Protocol Buffer requests from the gateway through the service and into the swappable SessionStorage interface. section 4.4.3

How Designing AI Systems covers it

How deep it goes
Defines interface delegation and constructor injection, then demonstrates a gRPC service implementation while leaving backend-specific mechanics behind the interface.
Examples
Contrasts PostgreSQL, Redis, DynamoDB, MongoDB, and other backends, then applies the pattern to sessions and vector similarity search.
What you can do after
Build it from scratch by defining a storage interface, implementing a backend, and injecting that implementation into a service.
How it connects
Connects session services, dependency injection, gRPC, PostgreSQL, Redis, DynamoDB, and vector databases through a shared abstraction pattern.

Also explained in

Compare how 2 books explain storage abstraction →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Designing AI Systems. The section links point to the parts of the book it draws on.