Autoscale vs Reserved VM Speed Issue

I’m running a python script from a Node.js Express API endpoint. The script is designed to run even after Express responds to the user. The code works, but it’s alarmingly slow to initialize. It takes 4 minutes + before the python script starts running. When I run the script directly in the shell, it’s instant. When I deploy to a reserved VM and call the API, it’s instant. Basically, when I deploy my app with a reserved VM, I don’t have the issue. But when I use Autoscale, I do.

Here is a very simple excerpt of the code:

const path = require('node:path');
const { spawn } = require('node:child_process');
const express = require('express');
const router = express.Router();

router.get('/run_script', async (req, res) => {
  try {
    const options = {
      cwd: path.resolve(`${__dirname}/python/scripts`),
      shell: '/bin/bash',
      timeout: 30 * 60 * 1000,
      stdio: 'pipe',
      detached: false,

    const child = spawn('python', [''], options);

    child.stdout.on('data', async (data) => {

    child.stderr.on('data', async (data) => {

    child.on('close', async (code) => {
      console.log(`Closed with Code: ${code}.`);

    res.status(200).json({ message: 'Success' });
  } catch (err) {
    res.status(500).json({ message: 'Error' });

Here is my .replit file:

modules = ["nodejs-20:v8-20230920-bd784b9", "python-3.11:v14-20231207-2f65342", "bash:v7-20240329-787bc7d"]
hidden = ["package-lock.json", ".pythonlibs"]
run = "npm run dev"

requiredFiles = [".replit", "replit.nix", "package.json", "package-lock.json"]

channel = "stable-23_05"

language = "nodejs"

run = ["sh", "-c", "npm run prod"]
deploymentTarget = "cloudrun"

localPort = 3000
externalPort = 80


Does anyone have ideas into why Autoscale is causing major hanging/latency?

Could you send a repl link so that we can test it out ourselves?