Layered architecture

One of the core design aims is Separation of Concerns (SoC). One of the good practices, irrespective of the size of an application or microservice, is to create a layered architecture.

Each layer in a layered architecture has one concern, and it should implement it well. Layering the applications also helps in simplifying unit tests. The code in each layer can be completely unit tested by mocking out the following layer. The following figure shows some of the important layers in a typical microservice/web application:

The layers shown in the previous diagram are as follows:

  • Presentation layer: In a microservice, the presentation layer is where the Rest Controllers reside. In a typical web application, this layer would also contain the view-related content--JSPs, templates, and static content. The presentation layer talks to the services layer.
  • Services layer: This acts a facade to the business layer. Different views--mobile, web, and tablets, this might need different kinds of data. The Services layer understands their needs and provides the right data based on the presentation layer.
  • Business layer: This is where all the business logic is. Another best practice is to the put most of the business logic into the Domain Model. The business layer talks to data layer to get the data and add business logic on top of it.
  • Persistence layer: This takes care of retrieving and storing data to the database. This layer typically contains the JPA mappings or the JDBC code.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset