Performance: Message serialization
MEDIUM IMPACT
Message serialization affects the speed of data transfer between services and the time to process messages in the application.
public record User(String name, int age) {} // Using JSON with Jackson ObjectMapper mapper = new ObjectMapper(); String json = mapper.writeValueAsString(user); outputStream.write(json.getBytes(StandardCharsets.UTF_8));
public class User { private String name; private int age; // getters and setters } // Using default Java serialization ObjectOutputStream out = new ObjectOutputStream(socket.getOutputStream()); out.writeObject(user);
| Pattern | CPU Cost | Message Size | Network Impact | Verdict |
|---|---|---|---|---|
| Default Java Serialization | High | Large (~50-100kb) | High latency and bandwidth use | [X] Bad |
| XML Serialization | Medium | Very Large | High latency and bandwidth use | [!] OK |
| JSON Serialization | Low | Medium | Efficient network use | [OK] Good |
| Binary Serialization (Protobuf) | Very Low | Small | Minimal latency and bandwidth | [OK] Good |