Repository pattern
The repository pattern is a software design pattern that abstracts access to and persistence of application or domain data, hiding storage-specific operations.
Spring in Action, Sixth Edition
A repository interface is an interface that declares data-access operations for an entity while leaving their persistence implementation to a supporting framework.
- How it is used
- Uses repositories to separate application data-access operations from persistence implementations in a taco-ordering application.
- How deep it goes
- Works through handwritten JDBC queries and generated Spring Data interfaces, without detailing generation internals.
- Examples
- Uses ingredient lookup and saving, plus order persistence with tacos and ingredient links.
- What you can do after
- Apply it via Spring Data by declaring CrudRepository interfaces and injecting them into controllers.
Read how Spring in Action, Sixth Edition explains repository pattern →
Learn Go with Pocket-Sized Projects
The repository pattern is an abstraction that mediates between an application’s domain model and persistent data storage.
- How it is used
- Separates data access from service handlers and domain logic in game and habit services.
- How deep it goes
- Works through map initialization, operation contracts, dependency injection, stubs, and locking; leaves Find and Update as exercises.
- Examples
- Uses an in-memory game repository and a habit repository with a deterministically ordered list.
- What you can do after
- Build it from scratch as an in-memory Go repository, inject it into service code, and test callers with stubs.
Read how Learn Go with Pocket-Sized Projects explains repository pattern →
Unit Testing Principles, Practices, and Patterns
A repository is an abstraction that provides access to and modification of persisted data for a particular domain object or aggregate.
- How it is used
- Separates domain-specific database access from transaction decisions during business operations.
- How deep it goes
- Defines responsibilities, lifespans, transaction enlistment, testing trade-offs, and a repository refactoring, but not database internals.
- Examples
- Uses UserRepository, CompanyRepository, CrmContext, a user email change, and an integration test sharing context.
- What you can do after
- Apply it via focused repositories and shared transactions, then evaluate repository tests by maintenance cost and regression value.
Read how Unit Testing Principles, Practices, and Patterns explains repository pattern →
Quarkus in Action
The repository pattern encapsulates data-access operations behind an abstraction that manages persistence and retrieval for domain objects.
- How it is used
- Replaces an inventory stub with a database-access object used by GraphQL and gRPC services.
- How deep it goes
- Builds a MySQL-backed repository from extensions and a JPA entity through a custom lookup, service calls, and transaction handling.
- Examples
- Uses a car inventory, a license-plate lookup, GraphQL and gRPC operations, and an SQL seed script.
- What you can do after
- Apply it via Panache to persist, list, find, and delete inventory entities through a repository.
Pro Angular 16
A repository is an abstraction that mediates access to data while hiding how that data is obtained from application components.
- How it is used
- Mediates application access to product data while hiding whether a data source supplies records statically or through a REST request.
- How deep it goes
- Builds product repositories with lookup and change operations, then elaborates signal exposure, computed categories, and asynchronous loading.
- Examples
- Uses product arrays, an ID lookup, derived categories, a product-count computation, and a REST-backed replacement for static data.
- What you can do after
- Build it from scratch with product operations and controlled signal access, then connect it to a static or REST data source.
Spring Start Here, Second Edition
A repository is an abstraction that provides access to stored application data.
- How it is used
- Separates data persistence from application logic and provides a consistent way to access stored data.
- How deep it goes
- Builds from a hand-written interface and implementation to Spring Data contracts, query methods, and startup validation rules.
- Examples
- Uses comment storage, DBCommentRepository, @Repository, and Spring Data interfaces with CRUD and custom query operations.
- What you can do after
- Apply it via Spring Data interfaces to implement data operations without writing routine database access code by hand.
Read how Spring Start Here, Second Edition explains repository pattern →
.NET in Action, Second Edition
The repository pattern is an architectural pattern that encapsulates access to and persistence of domain entities through a collection-like interface between the domain model and data-mapping or persistence layers.
- How it is used
- Abstracts data-store access to separate domain logic from persistence and support unit testing.
- How deep it goes
- Defines the collection-like role and demonstrates repository interfaces in an importer, without detailing persistence implementation.
- Examples
- Uses a CSV customer importer and an XKCD comic repository for unit and integration testing.
- What you can do after
- Apply it via repository interfaces to substitute fake data stores in unit tests without setting up test databases.
Read how .NET in Action, Second Edition explains repository pattern →
AI-Powered Developer: Build software with ChatGPT and Copilot
The Repository Pattern is a software design pattern that encapsulates data-access operations behind an interface separate from application logic.
- How it is used
- Separates asset data access from application services while preserving a consistent CRUD interface.
- How deep it goes
- Explains the abstraction, generic contract, in-memory implementation, service delegation, and database-backed replacement.
- Examples
- Uses BaseRepository, InMemoryAssetRepository, AssetManager, SQLAlchemyAssetRepository, and application wiring as concrete examples.
- What you can do after
- Build it from scratch by defining a repository contract, implementing storage adapters, and switching implementations through application wiring.
Read how AI-Powered Developer: Build software with ChatGPT and Copilot explains repository pattern →
Effective Platform Engineering
A repository layer is an architectural layer that exposes datastore operations through repository abstractions to higher layers.
- How it is used
- Supports service development by standardizing datastore access and reducing dependence on cloud-specific technologies.
- How deep it goes
- Explains the layer arrangement, interface boundary, migration effect, and automated architectural checks, without detailing repository method implementations.
- Examples
- Uses GCP migration, AWS RDS for PostgreSQL, Aurora Serverless for MySQL, relational and unstructured datastores, and layered pseudocode.
- What you can do after
- Apply it via repository and datastore interfaces to change supported databases or clouds while minimizing service rewrites.
Read how Effective Platform Engineering explains repository pattern →
Simple Object-Oriented Design: Create clean, maintainable applications
A repository is a component that encapsulates the logic for retrieving and persisting domain information.
- How it is used
- Separates domain data-access behavior from infrastructure and persistence implementation details.
- How deep it goes
- Defines repository responsibilities and demonstrates interface replacement, but defers the detailed challenges of implementing caching.
- Examples
- Uses EmployeeRepository, HibernateEmployeeRepository, findById, findByLastName, save, Hibernate, Postgres, and a cache.
- What you can do after
- Apply it via a repository interface that allows persistence implementations and infrastructure optimizations to change independently.
Data-Oriented Programming in Java
A repository is an abstraction that provides collection-like access to domain objects while hiding the underlying data storage mechanism.
- How it is used
- Frames repositories as boundaries that provide domain-oriented data access while coordinating persistence concerns with application logic.
- How deep it goes
- Contrasts generated CRUD repositories with evolving file loaders and explains how storage performance should shape exposed methods.
- Examples
- Uses CustomerRepo, entity-specific CRUD repositories, FileRepository loaders, and get-versus-scan database operations.
- What you can do after
- Evaluate repository boundaries, implement focused data-access methods, and diagnose abstractions that obscure storage costs or accumulate needless indirection.
Read how Data-Oriented Programming in Java explains repository pattern →
Also covered in
What to know first
- object-relational mapperAn object-relational mapper is software that maps between programming-language objects and operations and relational database structures and operations.
- domain modelA domain model is a software representation of the concepts, entities, relationships, rules, and behavior of a problem domain.
- lambdaA lambda is an expression that defines an unnamed function, specifying its parameters and body and producing a callable value.
- JSONJSON is a language-independent text-based data-interchange format that represents structured values using objects, arrays, strings, numbers, booleans, and null.
Related concepts
- Spring Data RESTused by · Spring Data REST is a Spring Data project that exposes repository-backed data and operations through RESTful resources.
- patternkind of · A pattern is a reusable approach to solving a recurring problem within a particular context.
- databaseuses · A database is an organized persistent data store, typically managed by software, that supports storing, retrieving, and modifying data.
- active record patternalternative to · The Active Record pattern combines an object representing a persistent data record with operations for querying, storing, updating, and deleting that record.
- data access objectequivalent to · A data access object is a component that encapsulates operations for accessing and manipulating data in a persistent store.
- data modelpart of · A data model is a structured representation that defines how data is organized, including its entities, attributes, relationships, and applicable constraints.
Questions about repository pattern
What is repository pattern?
The repository pattern is a software design pattern that abstracts access to and persistence of application or domain data, hiding storage-specific operations.
Which Manning books explain repository pattern?
Spring in Action, Sixth Edition, Learn Go with Pocket-Sized Projects, Unit Testing Principles, Practices, and Patterns, Quarkus in Action, Pro Angular 16, Spring Start Here, Second Edition, .NET in Action, Second Edition, AI-Powered Developer: Build software with ChatGPT and Copilot and 3 more.
What should I know before learning repository pattern?
Manning books that teach repository pattern usually introduce object-relational mapper, domain model, lambda and JSON first.
What is the difference between repository pattern and active record pattern?
The repository pattern is a software design pattern that abstracts access to and persistence of application or domain data, hiding storage-specific operations. The Active Record pattern combines an object representing a persistent data record with operations for querying, storing, updating, and deleting that record.
What is repository pattern a kind of?
Repository pattern is a kind of pattern. A pattern is a reusable approach to solving a recurring problem within a particular context.
What is repository pattern part of?
Repository pattern is part of data model. A data model is a structured representation that defines how data is organized, including its entities, attributes, relationships, and applicable constraints.
These guides are generated from the text of Manning books by Manning's knowledge graph and link to the sections they draw on. The full books are available on liveBook and at manning.com.










