Over-fetching happens when an API client must retrieve more data than it needs. A board-game list might need only each game’s title and ID for a link, while a REST endpoint returns every property of every matching game. The extra traffic may barely matter for a small service but can become a performance problem at scale. section 10.1.1
There are several ways to limit the mismatch between a response and a client’s needs:
- Exclude properties from JSON with `[JsonIgnore]`. This applies to every client, including clients that need those properties. section 10.1.1
- Add endpoints backed by smaller DTOs. These can fit particular clients, but similar endpoints increase code and maintenance work. section 10.1.1
- Use GraphQL so a client requests the fields it needs through one declarative query to one endpoint. Consider the cost of processing custom queries and the lack of native caching support. section 10.2.1 section 10.2.2
Check the returned fields
In BananaCakePop, run a board-games query requesting the first three games, ordered by ID, with only `id`, `name`, and `year` in each node. Check that the response contains those fields and no other board-game properties. A query can also request related domains and mechanics in the same call. section 10.2.4
A faster transport alone does not solve over-fetching. gRPC returns predefined data structures and has no native declarative query language for choosing response fields, so it can face the same problem as REST. section 10.3.2
