# Memory spikes killing my workers💀  need scaling advice

**URL:** <https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930>\
**Category:** AWS Networking\
**Tags:** load-balancer, ec2\
**Created:** [December 28, 2025, 9:03am UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930 "2025-12-28T09:03:41Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![tiln7](https://awshq.com/letter_avatar_proxy/v4/letter/t/f04885/32.png) [@tiln7](https://awshq.com/u/tiln7)\
**Post date:** [December 28, 2025, 9:03am UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/1 "2025-12-28T09:03:41Z")

</div>

So I’ve got this Node.js SaaS that’s processing way more data than I originally planned for and my infrastructure is starting to crack…

**Current setup (hosted on 1 EC2):**

- Main API container (duplicated, behind load balancer)
- Separate worker container handling background tasks

**The problem:** Critical tasks are not executed fast enough + memory spikes making my worker container being restarted 6-7x per day.

**What the workers handle:**

- API calls to external services (some slow/unpredictable)
- Heavy data processing and parsing
- Document generation
- Analysis tasks that crunch through datasets

Some jobs are time-critical (like onboardings) and others can take hours.

**What I’m considering:**

1. Managed Redis (AWS ElastiCache)
2. Switching to SQS

What approach should I take and why? How should I scale my workers based on the workload?

Thanks 🙏

* * *

**Related discussions:**

- [Why does restricting NLB SG to VPC CIDR cause timeouts?](https://awshq.com/t/why-does-restricting-nlb-sg-to-vpc-cidr-cause-timeouts/20234)
- [How do NLBs preserve the IP address of clients?](https://awshq.com/t/how-do-nlbs-preserve-the-ip-address-of-clients/12753)
- [AWS forcing everyone to Support+ now? What’s the community opinion?](https://awshq.com/t/aws-forcing-everyone-to-support-now-what-s-the-community-opinion/20859)
- [AWS RDS vs an equivalent EC2?](https://awshq.com/t/aws-rds-vs-an-equivalent-ec2/19552)
- [Amplify vs CloudFront + SE for frontend](https://awshq.com/t/amplify-vs-cloudfront-se-for-frontend/21257)

---

<div class="post-metadata">

**Author:** ![xzaramurd](https://awshq.com/letter_avatar_proxy/v4/letter/x/43a26b/32.png) [@xzaramurd](https://awshq.com/u/xzaramurd)\
**Post date:** [December 28, 2025, 9:19am UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/2 "2025-12-28T09:19:04Z")

</div>

For background tasks it sounds like you could use AWS Batch with Fargate or EC2 Spot instances.

---

<div class="post-metadata">

**Author:** ![vplatt](https://awshq.com/letter_avatar_proxy/v4/letter/v/5daacb/32.png) [@vplatt](https://awshq.com/u/vplatt)\
**Post date:** [December 28, 2025, 9:30am UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/3 "2025-12-28T09:30:09Z")

</div>

Rewrite your workers in Rust (probably best option) or Go (very good option). Or at least try one that’s been creating issues, and just do one of them as a POC. I think you’ll find the issues go away nearly entirely.

---

<div class="post-metadata">

**Author:** ![seanv507](https://awshq.com/letter_avatar_proxy/v4/letter/s/ce73a5/32.png) [@seanv507](https://awshq.com/u/seanv507)\
**Post date:** [December 28, 2025, 9:33am UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/4 "2025-12-28T09:33:36Z")

</div>

Its unclear what your question is.

Are you saying you need more compute resources (bigger instance/ aws batch serverless ,…) so handle memory spikes

or a better multiprocessing (so important quick tasks are performed in a timely way) eg a separate queue

…

---

<div class="post-metadata">

**Author:** ![mr\_q\_ukcs](https://awshq.com/letter_avatar_proxy/v4/letter/m/eb9ed0/32.png) [@mr\_q\_ukcs](https://awshq.com/u/mr_q_ukcs)\
**Post date:** [December 28, 2025, 9:38am UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/5 "2025-12-28T09:38:38Z")

</div>

What was the decision behind hosting it on a single ec2 ?

The memory spikes could be a number of application level issues, do they happen at a set timeframe or are they random?

Are your api calls asynchronous ? Do you have timeouts on them? All these things can cause a constraint on cpu resource.

I would look at moving your service to ECS Fargate if it’s handling tasks that are critical, a single ec2 isn’t going to give you the resilience you need.

---

<div class="post-metadata">

**Author:** ![MortTheLemur23](https://awshq.com/letter_avatar_proxy/v4/letter/m/3e96dc/32.png) [@MortTheLemur23](https://awshq.com/u/MortTheLemur23)\
**Post date:** [December 28, 2025, 9:53am UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/6 "2025-12-28T09:53:03Z")

</div>

For a starter I would recommend separating your API from your workers by placing them on separate instances. And for more resilience dockerize both and use an AWS managed service like ECS or Elastic Beanstalk (simple setup). That way a single api/worker failure won’t tear down your entire app.

And for the workers, I would (like you said) look into SQS or Bullmq to queue your worker jobs. That enables you to better manage your jobs and see what causes your memory spikes.

---

<div class="post-metadata">

**Author:** ![Dave3of5](https://awshq.com/letter_avatar_proxy/v4/letter/d/e5b9ba/32.png) [@Dave3of5](https://awshq.com/u/Dave3of5)\
**Post date:** [December 28, 2025, 11:40am UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/7 "2025-12-28T11:40:37Z")

</div>

Try to figure out the memory spikes / crashing first before doing anything arch / design related. There could be a problem there and then you are just shifting your problem around.

---

<div class="post-metadata">

**Author:** ![tiln7](https://awshq.com/letter_avatar_proxy/v4/letter/t/f04885/32.png) [@tiln7](https://awshq.com/u/tiln7)\
**Post date:** [December 28, 2025, 11:47am UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/8 "2025-12-28T11:47:45Z")

</div>

> [@Dave3of5](#):
>
> Try to figure out the memory spikes / crashing first before doing anything arch / design related. There could be a problem there and then you are just shifting your problem around.

will try!

---

<div class="post-metadata">

**Author:** ![hornetmadness79](https://awshq.com/letter_avatar_proxy/v4/letter/h/c68b51/32.png) [@hornetmadness79](https://awshq.com/u/hornetmadness79)\
**Post date:** [December 28, 2025, 11:59am UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/9 "2025-12-28T11:59:25Z")

</div>

You underestimated the necessary resources required to run your apps. Not uncommon really, but your reaction is. If an app is crashing 7 times a day, you can either fix the code, provision a larger node, or build better infra to handle the capacity problem. Throwing more cloudy solutions to fix a problem of your own making is what AWS is betting on.

---

<div class="post-metadata">

**Author:** ![FlamboyantKoala](https://awshq.com/letter_avatar_proxy/v4/letter/f/ec9cab/32.png) [@FlamboyantKoala](https://awshq.com/u/FlamboyantKoala)\
**Post date:** [December 28, 2025, 12:54pm UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/10 "2025-12-28T12:54:09Z")

</div>

Are you generating files in memory? 90% of the time I’ve had to fix issues with memory it’s caused by that.

---

<div class="post-metadata">

**Author:** ![Wide\_Commission\_1595](https://awshq.com/letter_avatar_proxy/v4/letter/w/919ad9/32.png) [@Wide\_Commission\_1595](https://awshq.com/u/Wide_Commission_1595)\
**Post date:** [December 28, 2025, 12:55pm UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/11 "2025-12-28T12:55:43Z")

</div>

So generally it seems like you’ve got a lot right! Separate API and workers is going to make scaling this an awful lot easier!

First of consider moving over to Fargate. If have the API auto scale based on CPU/memory to make sure it stays responsive. I would go with the SQS option for queueing jobs, because you can auto scale your workers based on queue length, and that way you keep background job processing responsive.

It’s not clear exactly how the background jobs work, i.e. is it always one type of job, or are there multiple different jobs? Basically I would go with one queue per job type, and have dedicated workers assigned to their own queue, but if that creates extra work, a single queue/worker combo will do fine

Longer term, depending on how the whole system works I might be tempted to convert the API to API gateway. You can use it to validate requests without code and place items direct into SQS. Other endpoints can use lambda functions. For the reports, save them S3 and then in the API return a redirect to a pre-signed S3 url so user can download easily without exposing the bucket itself. These are future suggestions though, for now just moving away from EC2 and into Fargate with SQS buffering should take you an awfully long way

---

<div class="post-metadata">

**Author:** ![Dangerous-Sale3243](https://awshq.com/letter_avatar_proxy/v4/letter/d/848f3c/32.png) [@Dangerous-Sale3243](https://awshq.com/u/Dangerous-Sale3243)\
**Post date:** [December 28, 2025, 1:39pm UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/12 "2025-12-28T13:39:21Z")

</div>

> [@vplatt](#):
>
> Rewrite your workers in Rust (probably best option) or Go (very good option). Or at least try one that’s been creating issues, and just do one of them as a POC. I think you’ll find the issues go away nearly entirely.

OP is unclear, but it doesn’t sound like there’s a memory leak, there’s just either “bad” programming (holding entire documents in memory perhaps too long) or just lack of scaling in the design.

OP could spend a lot of time rewriting to Rust but it wouldn’t solve the underlying mathematical problem that requests/sec \* avg request time \* avg document size is close to the memory limit.

I do think rewriting to Rust could be helpful though, but it’s further down the list of priorities. To me, #1 is stopping the bleeding, give everything more RAM to stop dropping requests. #2 is to switch to passing documents as s3 URIs and then migrate the background workers to Lambda.

---

<div class="post-metadata">

**Author:** ![cachemonet0x0cf6619](https://awshq.com/letter_avatar_proxy/v4/letter/c/5f9b8f/32.png) [@cachemonet0x0cf6619](https://awshq.com/u/cachemonet0x0cf6619)\
**Post date:** [December 28, 2025, 1:54pm UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/13 "2025-12-28T13:54:59Z")

</div>

i don’t think using another cloud service is going to fix your underlying issue of a poorly designed application. if you dm me we can talk about the shift aspect of lift and shift but i’d need to see the details

---

<div class="post-metadata">

**Author:** ![nekokattt](https://awshq.com/letter_avatar_proxy/v4/letter/n/5daacb/32.png) [@nekokattt](https://awshq.com/u/nekokattt)\
**Post date:** [December 28, 2025, 2:00pm UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/14 "2025-12-28T14:00:37Z")

</div>

> [@Wide\_Commission\_1595](#):
>
> So generally it seems like you’ve got a lot right! Separate API and workers is going to make scaling this an awful lot easier! First of consider moving over to Fargate. If have the API auto scale based on CPU/memory to …

Fargate is going to be more expensive and you still have to configure it to scale. While it removes the overhead of managing EC2, it does not remove the issue for OP.

---

<div class="post-metadata">

**Author:** ![AnomalyNexus](https://awshq.com/letter_avatar_proxy/v4/letter/a/ebca7d/32.png) [@AnomalyNexus](https://awshq.com/u/AnomalyNexus)\
**Post date:** [December 28, 2025, 3:32pm UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/15 "2025-12-28T15:32:35Z")

</div>

node.js is a poor choice for time-critical heavy data processing

You can try to patch over that by throwing more hardware at it to buy time but if the SaaS keeps growing you’ll hit a wall eventually forcing a rewrite of at least the core logic in something more suitable

---

<div class="post-metadata">

**Author:** ![mlhpdx](https://awshq.com/letter_avatar_proxy/v4/letter/m/dbc845/32.png) [@mlhpdx](https://awshq.com/u/mlhpdx)\
**Post date:** [December 28, 2025, 5:21pm UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/16 "2025-12-28T17:21:54Z")

</div>

Use Lambda. You already know Node.js and can keep your web server since it probably won’t need scaling for a bit if you put the workers elsewhere.

Ideally, have the web sever put messages for workers in a queue (or multiple queues if you have different priority levels) and use Lambda to work it/them. This isn’t an idea setup, but it’s an easy step from where you are and allows workers to scale from zero to whatever you need when spikes happen.

---

<div class="post-metadata">

**Author:** ![tiln7](https://awshq.com/letter_avatar_proxy/v4/letter/t/f04885/32.png) [@tiln7](https://awshq.com/u/tiln7)\
**Post date:** [December 28, 2025, 6:49pm UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/17 "2025-12-28T18:49:05Z")

</div>

> [@mlhpdx](#):
>
> Use Lambda. You already know Node.js and can keep your web server since it probably won’t need scaling for a bit if you put the workers elsewhere. Ideally, have the web sever put messages for workers in a queue (or …

Noted! Migrating everything to lambdas would require serious refactoring and probably I would need to open DB?

---

<div class="post-metadata">

**Author:** ![bot403](https://awshq.com/letter_avatar_proxy/v4/letter/b/858c86/32.png) [@bot403](https://awshq.com/u/bot403)\
**Post date:** [December 28, 2025, 7:01pm UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/18 "2025-12-28T19:01:34Z")

</div>

> [@vplatt](#):
>
> Rewrite your workers in Rust (probably best option) or Go (very good option). Or at least try one that’s been creating issues, and just do one of them as a POC. I think you’ll find the issues go away nearly entirely.

As a software engineer I’d rather spin up a second instance in minutes to hours than a week or weeks doing a risky language rewrite of my core application.

---

<div class="post-metadata">

**Author:** ![mlhpdx](https://awshq.com/letter_avatar_proxy/v4/letter/m/dbc845/32.png) [@mlhpdx](https://awshq.com/u/mlhpdx)\
**Post date:** [December 28, 2025, 7:19pm UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/19 "2025-12-28T19:19:58Z")

</div>

> [@tiln7](#):
>
> Noted! Migrating everything to lambdas would require serious refactoring and probably I would need to open DB?

Yeah, don’t migrate everything — just the worker code that runs in the background. The Lambda can connect to the same VPC that contains the DB, so it doesn’t need to be “open” in that sense.

---

<div class="post-metadata">

**Author:** ![vplatt](https://awshq.com/letter_avatar_proxy/v4/letter/v/5daacb/32.png) [@vplatt](https://awshq.com/u/vplatt)\
**Post date:** [December 28, 2025, 8:43pm UTC](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930/20 "2025-12-28T20:43:32Z")

</div>

> [@bot403](#):
>
> As a software engineer I’d rather spin up a second instance in minutes to hours than a week or weeks doing a risky language rewrite of my core application.

As a temporary measure, I’d be right there with you. But, that’s temporary. And if they were really risk adverse, it wouldn’t be a single instance architecture based on Node.js. Obviously their tolerance for risk is already quite high.

[Next page](https://awshq.com/t/memory-spikes-killing-my-workers-need-scaling-advice/20930.md?page=2)
