Search code examples
javascriptamazon-web-servicesaws-lambdaaws-step-functions

Why use Step function(AWS) over setTimeout(Javascript) for scheduler functionality


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?


Solution

  • 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