
13 Designing an efficient API
This chapter covers
- Optimizing design when necessary
- Enabling caching and conditional readings
- Optimizing data volume
- Processing multiple elements with bulk operations
- Considering an optimization-specific API layer
Since the Shopping company implemented its newly redesigned API with additional features, the number of product purchases has dropped. Website and mobile analytics indicate that users are experiencing wait times of over 500 ms when searching for products. This problem is due not to a missing index in the database or inadequate infrastructure but rather to the inefficient design of the API. Searching for products necessitates firing multiple API requests for each product found to gather all the necessary data and display it to users.
Concern about efficiency is not limited to the implementation level. An efficient API design can lead to benefits including optimized smartphone battery usage, reduced wait times for end users, and minimal effects on 5G data plans. Furthermore, it can enhance provider infrastructure efficiency, reducing cloud infrastructure costs through reduced CPU usage and data downloads.