About API calls that take about 3 seconds

Asked 5 months ago, Updated 5 months ago, 11 views

I would like your advice on how to design the API with the following specifications.

API specifications

  • If you hit yahoo.com://http://example.com/hoge?url=http with GET,
    Return url with json, where you can view screenshot images of the page specified by url parameter (upload the screenshot image to S3 on AWS and return the URL)
  • With this API, you can take screenshots of this URL and do other things (it's not too heavy because it's just one record).
  • You don't have to see the image for a few seconds from the client
  • I want the response time to be as short as possible

How to hit the API

  • Client like iOS or Android hits API with asynchronous communication
  • API return value is not currently handled and UX does not deteriorate even if it is delayed
    • The image is displayed as if it were a delayed read, so the UX will get worse, but
  • The image is displayed as if it were a delayed read, so the UX will get worse, but

Concerns

  • If you use PhantomJS on the server side to get screenshots, it will take 3 seconds to respond
  • Because of the long response time, if you create it as an API, you will be worried about the load on the server side

Design like this?

Supplementary

Rails 4.2.6 is running on AWS EC2.

ruby-on-rails

2022-09-30 11:39

1 Answers

The principle is

  • Give up some waiting time and process it in real time
  • Turn to the background to complete the process
    -- Client polls
    -- Push to Client

You can only use one or the other of the .

Either way, there are advantages and disadvantages, so you have to choose according to your application.

The more complicated you do, the more likely you are to have problems, so if you're worried about the load in the future, you can choose to keep it simple.


2022-09-30 11:39

If you have any answers or tips


© 2023 OneMinuteCode. All rights reserved.