12 Designing an efficient API
This chapter covers
- Network-, processing-, and data-efficient API design
- Cache and conditional requests
- Data volume optimization
- Bulk operations
- Optimization-specific API layer
Since the Shopping company implemented its newly redesigned API with additional features, there has been a drop in the number of product purchases. Website and mobile analytics indicate that users are experiencing wait times of over 500 ms when searching for products. This issue is not due to a missing index in the database or inadequate infrastructure but rather the inefficient design of the API itself. Searching for products necessitates firing multiple API requests for each product found to gather all the necessary data and display it to the users.
Efficiency is not a concern only at the implementation level. An efficient API design can lead to several benefits. These include optimized smartphone battery usage, reduced wait times for end users, and minimal impact on 5G data plans. Furthermore, it can enhance provider infrastructure efficiency, lowering cloud infrastructure costs through reduced CPU usage and data downloads.