Performance: DTO vs entity separation benefit
MEDIUM IMPACT
This concept affects the speed of data transfer and rendering by reducing unnecessary data processing and minimizing payload size.
public class UserDTO { private String username; private String email; // getters and setters } // Map UserEntity to UserDTO and return DTO in API response
public class UserEntity { private Long id; private String username; private String password; private String email; private Date createdAt; // getters and setters } // Returning UserEntity directly in API response
| Pattern | Payload Size | JSON Parsing Time | Rendering Delay | Verdict |
|---|---|---|---|---|
| Entity sent directly | Large (includes all fields) | High (more data to parse) | Longer (delays LCP) | [X] Bad |
| DTO sent | Smaller (only needed fields) | Low (less data to parse) | Shorter (faster LCP) | [OK] Good |