July 29, 2015

Data Transfer Objects

Data Transfer Objects

These are objects which are used to hold and transmit information between different processes. The processes could be different services within the same application or could be spread across multiple application in a distributed system. The application may be communicating with each other using Remote calls like RMI or web services (SOAP or REST).

Communication between different applications/modules is very expensive due to the fact that it involves steps like opening connection, transmitting data over the network  and closing it.

Data transfer objects are meant as a way of aggregating all the information that needs to be transferred, into a simple coherent entity and get it across to the other side without executing too many expensive operations.

  Below diagram describes a scenario without the user of data transfer objects. In this case multiple calls are being made to the application service to retrieve the required information.
Without Data Transfer Object
Fig 1: Without Data Transfer Object


With DTO ( data transfer objects) , the server will assemble all the required information into a single entity and send it back to the client. The client can use what ever fields it needs and simply ignore the other fields or store them for use at another time. Even though the payload returned back is larger, it does definitely reduce the amount of request the server needs to handle for an operation and also reduces any latency associated with data transmission over the internet.
With Data Transfer Object
Fig 2: Using Data Transfer Object