0
0
Spring Bootframework~8 mins

Why DTOs matter in Spring Boot - Performance Evidence

Choose your learning style9 modes available
Performance: Why DTOs matter
MEDIUM IMPACT
This affects the speed of data transfer between server and client and the efficiency of rendering data in the UI.
Sending data from backend to frontend in a Spring Boot application
Spring Boot
public class UserDTO {
  private String username;
  private String email;
  // getters and setters
}

@GetMapping("/user/{id}")
public UserDTO getUser(@PathVariable Long id) {
  UserEntity user = userRepository.findById(id).orElse(null);
  if (user == null) return null;
  UserDTO dto = new UserDTO();
  dto.setUsername(user.getUsername());
  dto.setEmail(user.getEmail());
  return dto;
}
DTO sends only needed fields, reducing payload size and avoiding sensitive data exposure.
📈 Performance GainSaves 50-150ms on LCP by reducing data transfer and parsing time.
Sending data from backend to frontend in a Spring Boot application
Spring Boot
public class UserEntity {
  private Long id;
  private String username;
  private String password;
  private String email;
  private Date createdAt;
  // getters and setters
}

// Controller returns UserEntity directly
@GetMapping("/user/{id}")
public UserEntity getUser(@PathVariable Long id) {
  return userRepository.findById(id).orElse(null);
}
Sending entire entity exposes sensitive data and sends unnecessary fields, increasing payload size and slowing rendering.
📉 Performance CostAdds extra KBs to response size, increasing LCP by 100-200ms depending on network.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Sending full entityNo extra DOM nodesNo reflows from dataHigher paint cost due to larger data[X] Bad
Sending DTO with minimal fieldsNo extra DOM nodesNo reflows from dataLower paint cost due to smaller data[OK] Good
Rendering Pipeline
When the backend sends data, the browser parses JSON and renders content. Smaller payloads reduce parsing and rendering time.
Network Transfer
Parsing
Rendering
⚠️ BottleneckNetwork Transfer and Parsing
Core Web Vital Affected
LCP
This affects the speed of data transfer between server and client and the efficiency of rendering data in the UI.
Optimization Tips
1Always send only the data needed by the frontend using DTOs.
2Avoid exposing sensitive or large fields in API responses.
3Smaller payloads reduce network time and improve loading speed.
Performance Quiz - 3 Questions
Test your performance knowledge
Why does using DTOs improve page load speed in a Spring Boot app?
AThey add more fields to the response
BThey reduce the amount of data sent over the network
CThey increase the number of database queries
DThey delay server response intentionally
DevTools: Network
How to check: Open DevTools, go to Network tab, reload the page, select the API call, and check the response size and timing.
What to look for: Look for smaller response payload size and faster time to first byte indicating better performance.