What is Caching?
Caching is the process of storing the data or response in temporary storage or RAM (Random Access Memory). The temporary storage provides faster access to the data which improves overall system performance and minimizes the load on backend services. Different websites and applications use caches to provide fast site reload.
How does caching work in API Gateway?
While storing the data, the API gateway uses in-memory storage or RAM (Random Access Memory). It generally provides fast and temporary storage for data that is frequently used. So storing response RAM can provide fast retrieval of data which is well suitable for caching purposes.
In the API gateway from the policy tab, you can select the caching option and configure a caching policy for a particular API endpoint. When caching is enabled, the gateway caches the response from the backend server after sending the first request to the server. After this, all the requests are served by the cached response of the gateway. Consequently, this reduces the load on servers as well as reduces response time, resulting in a better user experience.
The API gateway can send the response from the cache instead of servers for mentioned TTL time. The TTL time is defined in seconds and it decides how long the cached response will remain valid before it expires.
After completion of this expiration time, the response is sent from the server once and the process repeats. Users can also set the Cache-Control header while sending a response back from the API gateway.
What are the benefits of caching?
- Reduce Latency: While caching, the API gateway sends a response from the cache storage instead of the backend server. It aids in lowering network overhead and latency related to backend services. Ultimately improving response speed and overall system performance.
- Minimize backend load: User requests are served from the cache of the API gateway. Which reduces the backend traffic and improves the performance, availability, and scalability of backend services.
- Optimizes Cost: Caching minimizes the traffic load on the backend services which minimizes resources required to handle the incoming traffic. Therefore, you can scale down the infrastructure and reduce costs by handling less traffic.