We have a problem of load time in our REST API, which is the result of having Fat DTO (nested DTO s) & the N+1 problem (which is off my question), means that we are loading too much data in one request, and a big chunk of this loaded data is not going to be used by the client (this is a classic problem in REST API).
ex:let's say we have endpoint that list all the buildings entities, so currently in the response we are loading all the related owners (list of UserDTO) in which each owner has a list of notifications (list of NotificationsDTO ) ... etc
GET /buildings
---- response
{
"name" : "Building X"
"owners" [
{
"name" : "Tarek B",
"notifications" : [
{
"title" : "title 1"
//....
}
]
//....
}
]
//....
}
I have a couple of solutions in mind (you are very welcome to add other ideas, or tools that might help me with this), so which one of the following options is the best (keep in mind the effort needed to the implementation and other factors as scaling and maintenance ... )
My current options:
- Cut all the relations with Ids, and offer foreach entity an endpoint to get multiple with a list of Ids.
- make a
query parameter
to specify which relations will be loaded ex:/buildings?with=owners,floors
and this will load the buildings with all the owners and floors. -I am a bit afraid this might expand in the future and endup re-inventing the wheel of graphQL - - rewrite only the Data requesting part (GET endpoints) of the API with GraphQL. -too much work in the backend, also i do not know if we could use the old search logic from our
Specification toPredicate()
-
Current tech stack : SpringBoot - Angular