Authors: Burak Bagatarhan, Onur Cakmak
As Trendyol Search, based on the requests we received from our clients, we needed to develop a structure that would allow clients to retrieve only the specific fields they wanted from the response.
As a result of our research, we have determined that the Partial Response structure used in the REST API architecture will meet our needs.
If you are curious about what partial response is and how it provides benefits, we will discuss these in more detail in the later parts of the article, but to summarize for now:
Partial response is a technique used to retrieve only specific fields during a REST API call. This technique allows for a significant reduction in data transfer by only delivering relevant data to the clients, thereby increasing the performance of the API.
Before starting with Partial Response, our search was as follows: Clients were making requests to the search endpoint or lite-search endpoint according to the response type they wanted. The request was sent to the relevant content service according to the endpoint it came to, and the response was retrieved from the index.
After implementing Partial Response, we developed a structure that can work on a single endpoint. Here, a single request is made to the endpoint, and the fields are retrieved from Elasticsearch.
To determine the need for implementing the Partial Response structure and to decide on the overall design of the structure, we conducted a POC study. In this study, we determined how to bring the information about which fields are requested by the client into a format that the search API can understand through a parser. We also identified the need to establish a mapping structure to determine the corresponding fields in the Elasticsearch index for the fields brought into the requested format. We found that the response obtained from Elasticsearch will only contain the requested fields before being returned to the client, and certain checks need to be performed to ensure that this is done in a null-safe manner.
In this POC study, we also researched other structures that could replace Partial Response. One of the structures that comes to mind for everyone is GraphQL, and we also conducted research on this structure.
GraphQL is a query language for APIs. It is designed as an alternative for clients to retrieve data from services. Unlike REST APIs, GraphQL is a query language that allows clients to query the data they