Repository & UoW — Notes
Sizing
- One repository per aggregate root, period.
- Repository methods follow named-query convention (
findActiveByCustomer).
- Pagination: cursor or page object as parameter, not exposed ORM type.
Concurrency
- Repository updates should respect aggregate version (
@Version in JPA, xmin in Postgres).
- UoW commit catches version-conflict exceptions for retry by caller.
Caching
- Read-through cache in the repository implementation (transparent to use cases).
- Invalidate on save / delete.
Testing
- Use cases test against
InMemoryOrderRepo — fast, deterministic.
- Adapter test suite runs the same contract against the real DB.
Refs
- Eric Evans: Domain-Driven Design — chapter on repositories.
- Martin Fowler: Patterns of Enterprise Application Architecture — Repository, Unit of Work, Data Mapper.
- Vaughn Vernon: Implementing DDD.
- "Architecture Patterns with Python" — Cosmic Python.