Video in progress

How does the Interface Segregation principle show up at the API level between services? Is one big endpoint/DTO for all consumers bad?

Yes, ISP applies to network APIs too: any fields and operations beyond what a consumer needs bring it dependencies and security risk. I publish separate, small contracts (or a BFF) for different groups of consumers.

📖 Answer

This is how it usually goes: GET /customers/{id} returns 8 fields at first. Each team has the fields it needs added, and two years later there are 90 fields, including passport data and an internal risk score. The results:

  • It can't be changed. Nobody knows which consumer uses which field, so nothing is ever removed.
  • Security. Personal data goes to the mobile app too, because the DTO is the same.
  • Performance. 6 JOINs on every request, even if the consumer needs two fields.

Options:

  1. A contract per role. /customers/{id}/profile, /customers/{id}/risk, each with its own permission. One model internally, several small views outside.
  2. A BFF (Backend for Frontend). A separate layer for mobile and web that assembles the shape it needs.
  3. Field selection (GraphQL, ?fields=). Flexible, but caching and managing permissions at the field level get complicated.

Getting out of an existing "big" API:

  • collect from the access log or tracing which consumer calls which endpoint; at the field level, consumer-driven contracts (Pact) give precise data;
  • release new small endpoints and move consumers over one at a time;
  • put Deprecation and Sunset headers on the old endpoint, and announce when it will be removed.

Inside Java code it's the same: if one CustomerService with 40 methods is injected everywhere, that's a small version of the same problem.