liveBook · Manning

Service layer

As explained in Effective Platform Engineering

A service layer is an architectural layer containing application service logic that coordinates capabilities without directly accessing datastore functions.

The application layer contains service logic that coordinates capabilities while remaining independent of datastore functions. A service calls repository operations rather than coupling directly to a database implementation. section 2.3.3

This separation keeps service and repository code stable when the platform changes database technology or cloud provider. The repository depends on a datastore interface, while the service depends on the repository. section 2.3.3

A practical layered arrangement assigns responsibilities as follows:

  • Handlers invoke service operations. section 2.3.3
  • Services coordinate application behavior through repositories. section 2.3.3
  • Repositories expose normal database methods through a datastore interface. section 2.3.3

Team onboarding API

A custom Teams API can construct a datastore, pass it to a teams repository, pass that repository to a team service, and pass the service to a handler. Replacing the datastore library then avoids rewriting service logic. section 2.3.3

Figure 2.12 When a particular service within the API needs to interact with the API database, it calls a repository function that provides all the normal database methods. The repository function would call the datastore functions for the type of database the API needs to use (relational or unstructured, in our case).
A close-up of a text

AI-generated content may be incorrect.

Trace the call path from an API service to repository methods and then to relational or unstructured datastore functions. section 2.3.3

How Effective Platform Engineering covers it

How deep it goes
Defines layer responsibilities, shows construction order, and enforces dependency direction with architecture fitness functions.
Examples
Uses a Teams onboarding API, relational and unstructured datastores, and a layered construction example.
What it assumes
Assumes familiarity with APIs and datastores while establishing repository-based dependency abstraction and layered architecture.
What you can do after
Apply it by routing service dependencies through repositories and testing that layer access remains decoupled.
How it connects
Connects handlers, repositories, datastore interfaces, dependency abstraction, and architecture fitness functions.

Also explained in

Compare how 3 books explain service layer →

Related concepts

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