liveBook · Manning

Handwritten DTO

As explained in Microservices Patterns, Second Edition

A handwritten DTO is a manually implemented data transfer object maintained by the client team.

A handwritten DTO is a client-maintained data model for messages exchanged with a service. Teams can write DTOs from scratch or generate them once from a schema and maintain the result manually. section 8.1.7

Handwritten DTOs trade tighter client control for more manual work:

  • They include only needed fields, can follow team conventions and contain logic, and avoid a code-generation build step. section 8.1.7
  • Complex schemas take longer to model; API changes require manual updates and can cause schema drift. Consumer-driven contract tests or schema validation can reduce that risk. Teams may also model the same messages inconsistently. section 8.1.7
Figure 8.3 An API client must have a data model of the messages that it exchanges with the service. The data model must serialize and deserialize correctly as defined by the schema. It can either be untyped (e.g. hash maps) or consist of handwritten or code-generated classes.
defining api client dtos

Compare handwritten classes with generated classes and untyped data models in an API client. section 8.1.7

How Microservices Patterns, Second Edition covers it

How deep it goes
Defines two manual-maintenance approaches and weighs their benefits and drawbacks, without detailing implementation steps.
What it assumes
Assumes an API client exchanges messages that must serialize and deserialize according to a schema.
What you can do after
Evaluate handwritten DTOs against client needs, schema complexity, maintenance effort, and drift risk.
How it connects
Connects API clients and schemas with code generation, consumer-driven contract testing, and the Law of Demeter.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Microservices Patterns, Second Edition. The section links point to the parts of the book it draws on.