0

I am trying to create a API service where any client can pass me his HTTP request and time in seconds after which he would like his HTTP request to be executed. I can think of two approaches here to make it happen:

  1. Create a lambda with nodeJS and use setTimeout to wait
  2. Create a step function to wait for x number of seconds would call my lambda to execute HTTP request

What I am trying to understand is what are the pros and cons of each. setTimeout looks easy to implement and with no obvious flaws. Is there any reason I should go for step functions?

Ravi Chaudhary
  • 660
  • 6
  • 22

2 Answers2

2

In a flash, I can think of following, will update if I get more points in mind

  1. Lambda can timeout. Whereas StepFunctions can wait for e.g. a year also.
  2. Lambda will cost for the time it is waiting but StepFunction will not.
  3. There is a limit on concurrent executions for lambda totalling to 1000 whereas a StepFunction can have maximum 1,000,000 open executions.

Link:
https://docs.aws.amazon.com/step-functions/latest/dg/limits.html#service-limits-state-machine-executions
https://docs.aws.amazon.com/lambda/latest/dg/concurrent-executions.html#per-function-concurrency

raevilman
  • 3,169
  • 2
  • 17
  • 29
2

I don't have any knowledge about aws step functions, so I can't say anything about that. But using a setTimeout in nodejs with a possible really large delay, can be a real problem if you want to create a stable an maintainable API because fo the following reasons:

  • if you wan to roll out any updates for your application, you need to either kill waiting requests, or you need to keep the application online until the last request finished before you can shut down the old code.

  • if your application crashes, all currently waiting requests are lost.

  • if the system nodejs is running one needs to restart to install a critical security update then all pending requests are lost.

So setTimeout should not be used for this kind of takes. If you want to do that in node, you would need to store/mirror those requests in a persistent storage.

t.niese
  • 39,256
  • 9
  • 74
  • 101