How to deal with third party API integration issues for web services?

How to deal with third party API integration issues for web services?

How to deal with third party API integration issues for web services?

Many web services offer beautiful APIs that solve your company problems.

However, what marketing landing pages don't mention can often decide the fate of your project.

Often this information is missing or hidden deep in the documentation. For example:

Response time

Usually something like P75-P90 is mentioned (average response time for 75-90 percent of users). Expensive platforms offer SLAs for this parameter.

Many services do not explicitly state this (loud HI to one paid AI image search service with p75 of 7 seconds and a maximum response time of 1-2 minutes, which, however, has already been fixed).

What to do?

0) Monitoring. If the service does not provide statistics, do it yourself, for example, by sending the service response time for 1% of users to the monitoring system (we will talk about them someday). Without this, it is difficult to say what the problem is - in the website itself or the API data source

1) Caching. If the site has a sane backend, you can store data from frequent/long running requests in Redis or Memcached, or cover GET endpoint of API with CloudFlare or Varnish. It would be great if the Cache-Control/Etag Header and HEAD method are implemented correctly.

2) Communication with the user. Instead of freezing for a long time, show the user jumping cats that pull kilobytes of data.

Remember, third-party API response times snowball if data has tight connections between services.

Limiting the frequency/number of requests

This may include:

a) Number of requests per unit of time (for example, 1200 requests per minute like CloudFlare)

b) Maximum number of requests in a tariff plan (for example, limits for services like Algolia or Contentful)

Solutions:

1) Exponential Backoff/Retry - the easiest to implement, but not always effective method. Helps if requests jump beyond the limits sometimes/a little.

2) Caching, as in the previous paragraph.

3) Request batching. Collecting many requests into one request (if the service allows this). Placing requests into a database that is processed by a service that knows API limits (I have already described an example of such a solution here https://www.dhirubhai.net/pulse/aws-optimizing-lambda-usage-trough-dynamodb-rules-ivan-vokhmin/)


What methods do you use? Write in the comments.

This article on other platforms: https://t.me/jsarchitect (in russian).

要查看或添加评论,请登录

Ivan Vokhmin的更多文章

社区洞察

其他会员也浏览了