We have API calls going from Laravel back-end to multiple providers for fetching flight fare/availability
data. The response from these providers come after different time periods. One provider may give us a response in 2 seconds, another in 5 seconds and so on. The customer ends up waiting till all providers return data to the back-end. As a workaround, now we are sending multiple requests from the front-end to Laravel - one for each provider. So the customer starts seeing data as soon as we get a response from one provider. This approach has issues - if we want to add one more provider, we have code changes at the UI level. If we want to enable/disable
providers, again code change at UI is necessary. We are using Ionic for UI and Laravel for the back-end. Which is the best approach to tackle this problem? We want to keep pushing data to the front-end as and when we receive responses at the back-end. The UI layer should be able to keep receiving data till the back-end sort of says - 'Done, no more data'. A combination of web sockets and Laravel queues? Just a wild guess based on google. Switching from Laravel to another technology can be considered.
Asked
Active
Viewed 135 times
0

Mujahid Bhoraniya
- 1,518
- 10
- 22

Jayadevan
- 1,306
- 2
- 12
- 33
-
"if we want to add one more provider, we have code changes at the UI level"...why? Can't the back-end pass the front-end a list (from its config) of providers and how to contact them, and it can just run through the list and then process each one according to the config? I don't see why you need to hard-code them, particularly. – ADyson Feb 27 '20 at 12:22
-
Or, for a more back-end solution, does this answer your question? [How to make asynchronous HTTP requests in PHP](https://stackoverflow.com/questions/124462/how-to-make-asynchronous-http-requests-in-php). You'll still have to wait for all of them before you can get a response to the user, but since they are done in parallel it will probably be much faster. A 3rd option would be to run all the requests on the back-end (synchronously or asynchronously), but use a websocket to transmit the result to the UI as each one arrives. – ADyson Feb 27 '20 at 12:23
-
1So, there are several possible approaches. The "best" one is subjective to your exact scenario (many small details of which we cannot be aware of), and as such the question is not really definitively answerable. Once you know some possible approaches, you can evaluate them in more detail against all of your functional and non-functional requirements. But we cannot directly tell you which one you should use. – ADyson Feb 27 '20 at 12:25
-
1You could consider using websockets ([Broadcasting in Laravel](https://laravel.com/docs/6.x/broadcasting)) to keep a continuous connect between the front and backend. – PtrTon Feb 27 '20 at 12:32
-
@ADyson - we could send the list from back-end, just wanted to avoid one round-trip. Based on comments so far, websockets seem to be the way forward. – Jayadevan Feb 27 '20 at 12:52