deividaspetraitis
deividaspetraitis

Reputation: 379

Request data design pattern

first of all i'm not sure about this question title so please correct me if it's not, thanks.

About:

I have two projects based on PHP: first project ( CLIENT ) who connects to second ( API ) via curl. In API project are done some calculations which are performed on CLIENT send data.

Problem:

If API project will have downtime by any issues or just slows down CLIENT must wait until API returns results, so it slows down too. Projects are in intensive development so calculations will increase so delay too.

Question:

How i can avoid mentioned problem, perfectly API must do not impact performance of CLIENT. Maybe there is any design patterns or something? I have read about ASYNCH PHP, caching patterns but still not found solution. If there's any solutions ( patterns ) it would be great to have examples in practise!

P.S. Request doesn't slows, slows calculations. And i agree that first of all they should be optimized. P.P.S. Total requests are more than 60 per minute ( > ~60 / min ).

Upvotes: 0

Views: 476

Answers (1)

arkascha
arkascha

Reputation: 42915

There are two approaches, both work but have different pros and cons...

  1. asynchronous processing, meaning that the client does not wait for each single call until it returns (its response returns), but moves on and relies on a mechanism like a callback or similar to handle the response once it comes in. This is for example what is typically done in web clients using javascript and ajax for remote calls. The makes the client considerably more fluent, but obviously involves a higher complexity of code and UI.

  2. queue based processing, meaning that the client does not at all do any such potentially blocking requests directly, but only creates jobs instead inside some queuing mechanism. Those job can be handled then one by one by some scheduler which also must take care of handling the response. This is extremely powerful if it comes to scaling and robustness against load peaks and outages of the API, but the implementation is much more expensive. Also the overall task must accept that response times are not guaranteed at all, typically the responses will take longer than in the first approach so cannot be shown interactively.

Upvotes: 1

Related Questions