2 Replies - 337 Views - Last Post: 14 September 2018 - 01:59 PM Rate Topic: -----

#1 evilsystemcracker   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 01-September 18

I have the following problem statement, i can't understand it

Posted 01 September 2018 - 02:32 AM

How to execute the problem statement step by step.

Problem statement
Context
In real world there are lots of scenarios where a direct response system might not be of use. For example if an API call takes more than 2 minutes to process, there is a high chance that the client will timeout before the server responds. So in those cases a callback mechanism is used.

Problem
If the server behind the callback, which was responsible for handling the data posted to callback URL is down, then the request is lost completely, with the original request creator having no idea regarding the same.

Solution
You need to device a retrial mechanism solution that can retry the requests to a callback URL if it fails. You can define the success criteria as the response code being 200. See a sample object below.


If you have constant retrial times then after some time the same requests keep retrying agian and again. Hence every request should decay. You can use a fibonacci sequence to setup the next retrial time, so that the time after next retry increases every time and request is decayed.


Expected output

You need to create an API endpoint, on which we can post the data in the below format (json format).
This API should store the request into the database.
Create a script that could read the data from the database and retry if the request fails. Next trial time is as mentioned in the property of a database.
Tech specifications
We create a decay mechanism in the elements entered in our system.


The idea is to try after more time as an API endpoint fails more and more. We will do it using fibonacci series.

Nth element will be called after Fn seconds, where Fn is nth fibonacci number.
The next time is to be calculated using
For example
Request 1 at 2 seconds after creation
Request 2 at 3 seconds after creation
Request 3 at 5 seconds after creation
Request 4 at 8 seconds after creation
Request 5 at 13 seconds after creation
Request 6 at 21 seconds after creation
Request 7 at 34 seconds after creation
Request 8 at 55 seconds after creation
Request 9 at 89 seconds after creation
Request 10 at 144 seconds after creation
Request 11 at 233 seconds after creation
Request 12 at 377 seconds after creation
Request 13 at 610 seconds after creation
Request 14 at 987 seconds after creation
Request 15 at 1597 seconds after creation
Request 16 at 2584 seconds after creation
Request 17 at 4181 seconds after creation
Request 18 at 6765 seconds after creation
Request 19 at 10946 seconds after creation
Request 20 at 17711 seconds after creation
Request 21 at 28657 seconds after creation
Request 22 at 46368 seconds after creation
Request 23 at 75025 seconds after creation
Request 24 at 121393 seconds after creation
Request 25 at 196418 seconds after creation
……….. And so forth

It is suggested to store the data in a mongoDB database.


The following is a an example of how we can store the data for queue in DB.


{

"key": "",

"bin": {

"workType": "httpRequest",

"createdAt": "1534357738912",

“nextTrialTime” : “1534357739912”,

“processedState” : true/false,

“failureCount” : 0,

"details": {

“successCriteria: : {

“statusCode” : 200, // optional

“statusResponse” : {

“error”: null, // optional

“body: “SUCCESS” // optional

}

}

"method": "POST",

"url": "http://206.189.141.232:7421/api/arqposts",

"headers": {

"content-type": "application/json",

"content-type": "application/json"

},

"body": "Stringified data of the request"

}

}

}

Callback URLs:
We have setup 10 callback URLs (API endpoints) that randomly fail with a defined failure percentage.


Following is a sample CURL to import in postman.


curl -X POST \

http://206.189.141.2...21/api/arqposts \

-H 'Cache-Control: no-cache' \

-H 'Content-Type: application/json' \

-H 'Postman-Token: 0cd978cc-6b13-4ddc-be4d-f3ac38066aed' \

-d '{

"basic": "request"

}'


Similar to the above endpoint on port 7421, we have setup 10 other endpoints as below.


http://206.189.141.2...21/api/arqposts - 50 % success rate
http://206.189.141.2...22/api/arqposts - 65 % success rate
http://206.189.141.2...23/api/arqposts - 60 % success rate
http://206.189.141.2...24/api/arqposts - 70 % success rate
http://206.189.141.2...25/api/arqposts - 75 % success rate
http://206.189.141.2...26/api/arqposts - 80 % success rate
http://206.189.141.2...27/api/arqposts - 85 % success rate
http://206.189.141.2...28/api/arqposts - 90 % success rate
http://206.189.141.2...29/api/arqposts - 95 % success rate
http://206.189.141.2...30/api/arqposts - 100 % success rate

Is This A Good Question/Topic? 0
  • +

Replies To: I have the following problem statement, i can't understand it

#2 andrewsw   User is offline

  • dependency injected
  • member icon

Reputation: 6668
  • View blog
  • Posts: 27,305
  • Joined: 12-December 12

Re: I have the following problem statement, i can't understand it

Posted 01 September 2018 - 02:35 AM

What is your question? What don't you understand?

If you are completely lost you should speak to your tutor.
Was This Post Helpful? 0
  • +
  • -

#3 Sheepings   User is offline

  • Senior Programmer
  • member icon

Reputation: 171
  • View blog
  • Posts: 1,023
  • Joined: 05-December 13

Re: I have the following problem statement, i can't understand it

Posted 14 September 2018 - 01:59 PM

Use the code tags and what Andrew said!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1