Backend Development 9 min read

Best Practices for Backend Application Layering and Domain Model Conversion

This article discusses the importance of proper backend application layering, outlines Alibaba's multi‑layer architecture (controller, service, manager, DAO, etc.), explains domain model transformations (DO, DTO, BO, VO, etc.), and offers practical recommendations for achieving clear responsibilities and maintainable code.

Top Architect
Top Architect
Top Architect
Best Practices for Backend Application Layering and Domain Model Conversion

1. Background

Many developers treat application layering as a simple three‑tier structure (controller, service, mapper), but in practice responsibilities are often mixed, leading to tangled code, poor reusability, and maintenance difficulties.

2. How to Layer

2.1 Alibaba Specification

Alibaba’s coding guidelines define a clear multi‑layer architecture:

Open Interface Layer : Exposes RPC or HTTP interfaces and handles gateway security and traffic control.

Presentation Layer : Renders templates for various clients (Velocity, JS, JSP, mobile).

Web Layer : Performs request routing, basic validation, and simple non‑reusable business handling.

Service Layer : Contains concrete business logic.

Manager Layer : Provides reusable services such as caching, MQ handling, and aggregates multiple services; also performs data conversion for HTTP/RPC managers.

DAO Layer : Direct data access to databases like MySQL, Oracle, HBase.

2.2 Optimized Layering

In practice, the topmost controller (or TService when using Thrift) should contain only lightweight logic, parameter validation, and exception handling, keeping business orchestration in the Service layer to avoid duplication when adding new entry points.

The Service layer should encapsulate business processes, while the Manager layer handles reusable cross‑cutting concerns (caching, messaging, composite operations). The DAO layer remains responsible solely for database interactions and should only be accessed by its corresponding Service.

3. Domain Model Conversion

Alibaba’s guidelines also define several domain model types:

DO (Data Object) : Direct mapping to database tables, used by the DAO layer.

DTO (Data Transfer Object) : Objects transferred from Service or Manager to callers.

BO (Business Object) : Encapsulates business logic output from the Service layer.

AO (Application Object) : Reusable objects between Web and Service layers, closely tied to presentation.

VO (View Object) : Objects sent to the view/template engine.

Query : Encapsulates query parameters; avoid using generic Maps for more than two parameters.

Strictly separating these models can cause excessive conversions (3‑4 times per request). A pragmatic approach is to allow Service/Manager layers to work directly with data‑domain models while preventing Controllers/TService from passing objects directly to DAO, and vice‑versa.

4. Summary

Proper backend layering is crucial for code reuse, clear responsibilities, and maintainability. While exact conventions may vary across teams, the key is to keep each layer’s purpose well defined and to avoid unnecessary duplication of business logic.

backendlayered architecturesoftware designservicedaodomain model
Top Architect
Written by

Top Architect

Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.