liveBook · Manning

Data layer

As explained in Grokking Software Architecture

A data layer isolates data access and persistence operations from other application responsibilities.

The data layer handles how an application fetches and stores data, keeping those mechanics separate from decisions about what the application should do. It commonly sits within the infrastructure layer and can provide implementations for interfaces defined by the application or domain layers. section 4.2.3

Use this boundary to sort responsibilities:

  • Put database operations—such as using an ORM or SQL to fetch or store data—in the data-access code. section 4.2.3
  • Keep decisions about what to do with the data in business logic, not in a repository. Shape repositories around use cases rather than individual database rows. section 5.3.5
  • Keep business policies such as atomicity or retries inside the core or an application service, where adapters do not hide them. section 5.3.5

A separate Data Access Layer can be useful in a large system, alongside infrastructure code for concerns such as email or external APIs. These are sibling parts: a message to an email service need not pass through the database layer. Layers describe code organization; tiers describe physical deployment, so several layers can run on one server or across multiple machines. section 4.2.3 section 4.2.3

Treat persistent databases differently from replaceable application code: a live database cannot simply be destroyed and rebuilt without risking its data, so changes require careful management. section 9.8.3

How Grokking Software Architecture covers it

How deep it goes
Defines database access through ORM or SQL and distinguishes fetch/store mechanics from business decisions and policies.
Examples
Names Entity Framework or SQL for database access and repositories as fetch/store translators.
What you can do after
Apply it by keeping fetch/store mechanics in repositories and business decisions and transaction policies inside the core or application service.
How it connects
Connects layered architecture with infrastructure, application and domain layers, interfaces, and repositories.

Also explained in

Compare how 8 books explain data layer →

Related concepts

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