Demo, all content is generated
Question

Replit Autoscale bill jumped after I added a setInterval job to my Express app

Solved · 534 views · asked by thiago_n · edited

Added a job that checks prices every 10 minutes:

setInterval(checkPrices, 10 * 60 * 1000)

Deployed on Autoscale. Two weird things: (1) sometimes the job just doesn't run for hours, (2) my usage for compute is 4x what it was. Which one is it, is it running or not?

What I’ve tried

Added console.log in checkPrices, logs show gaps of hours and then bursts. Asked the Agent, it suggested node-cron, same behavior.

Comment
Autoscale or Reserved VM? deploydan · edited
autoscale thiago_n · edited

2 answers

Marked as helpful by the asker
deploydan · edited

Both, and they're related. Autoscale spins instances up when requests come in and down when idle. A timer inside the process only runs while an instance is alive:

  • no traffic → scaled to zero → your interval is dead (the gaps)
  • traffic → instance up → interval fires, and while it's doing work the instance counts as busy, so it stays up longer (the bill)

Autoscale is for request/response. For "every 10 minutes", use a Scheduled deployment with a small script that runs checkPrices() once and exits. Keep the web app on Autoscale and remove the setInterval from it.

If the job needs to hold state in memory between runs, then it's a Reserved VM, but that's rarely the case for price checks. Store the results in the DB.

Comment
makes total sense now. Split it into a scheduled deployment, compute is back to normal after 3 days thiago_n · edited
Scheduled deployments are so underused. Thanks for writing it out. halima_s · edited
chidi_eze · edited

One extra with scheduled jobs: make checkPrices safe to run twice. If one run is slow and the next one starts, you don't want double notifications.

Comment