Reducing the number of API calls
To maintain optimum performance and ensure that infrastructure resources are not disproportionately used in an inefficient manner, Alma has Governance Thresholds in place.
Governance thresholds ensure that no single institution negatively impacts other Alma institutions, prevent performance degradation and can help reduce the risks of malicious attacks (See Alma Governance Thresholds for more details).
If you make a lot of API requests in a short amount of time, you may bump into the threshold limit:
- If you reached the Daily API Request Threshold, you will receive “Too Many Requests” response.
- If you reached the Concurrent API Request Threshold, your requests will be queued and processed later.
In this article we will share ideas for reducing the number of API calls:
- Optimize your code to eliminate any unnecessary API calls
For example, are some requests getting data items that aren’t used in your application? Are retrieved data items being put back with no changes made to them?
- Cache frequently used data
For example, in an user management application that updates user details, drop-down values such as user groups, user titles etc. should be kept in the application side instead of being retrieved every time the user form is opened.
- Cache data that is not changed often
There are pieces of information that are not changed often. For example: list of libraries in an institution. It is better to keep such information on the application side instead of getting it from Alma whenever necessary.
- Use webhooks in order to track changes
Alma webhooks infrastructure can be used in order to identify changes and react accordingly, rather than having to pull for work. For example, a webhook might notify that an import job has ended successfully. When this information arrives, the application can continue with appropriate actions. This is, instead of calling the Retrieve job instance API periodically and checking the status of the job.
- Consider batching multiple requests into a single request
Alma offers some APIs that handle multiple pieces of information. For example:
Get multiple BIB records – applications that give a results list page need information regarding a group of bibliographic records. Instead of getting each record separately using the GET BIB record API, it is possible to use the GET multiple BIB records API and retrieve the list at once.
Get multiple BIB records – applications that give a results list page need information regarding a group of bibliographic records. Instead of getting each record separately using the GET BIB record API, it is possible to use the GET multiple BIB records API and retrieve the list at once.
When combining multiple operations into a single request, it’s important to remember that most requests are atomic. If an operation fails, then the whole request will fail – and nothing will be updated.