NextJS Lambda vs ECS - My final thoughts.


NextJS Lambda vs ECS - My final thoughts.

Weighing the costs of running NextJS on AWS in a cost-effective Lambda or on the more performant ECS? Well here are my final thoughts on it.

My Experiment running NextJS in Lambda vs ECS is still ongoing. Now I need to decide which of the 2 solutions to go with.

Here are the factors:

Speed:

A special thanks to Nik A. who reminded me that pagespeed.web.dev is a thing.

After hitting both sites with that tool I was surprised.

image

Both sites measured abysmally but then I realized I was just looking at the data from mobile. From the desktop, it was a different story.

image

Since 35% of my users in the last 90 days are mobile then I should probably get on that. That is my fault as an infrastructure guy. The infrastructure is lightning fast but a mobile device running on a cell signal can only load a page so fast. I need to cut down what is sent over the net, better compression, etc. A problem for another day.

What about costs?

Lambda/APIGateway:

APIGateway rarely even costs me a dollar a day assuming I don’t leave 1GB of caching turned on my dev env for a few months… (face slap).

Lambda are flat at $0.00 per day. You heard it right, ZERO.

ALB/ECS:

The ALB costs $0.54 per day which is a bit stiff considering the volume of traffic I get on that site. This is flat based on hours. I am not getting enough traffic to rack up any throughput costs.

ECS and ECR sit right at $0.65 per day so I am just racking up hourly costs there.

Sadly since I have had this AWS account for over a decade none of the nice free-tier stuff applies to me.

Random Costs:

While I was in there today compiling this data I found several other costs I knew about but had not looked at in a while.

All of these costs pail in comparison to the 1TB of regular storage I was paying for neural nets from DrawnBy.ai that I kept stored because I was holding out hope that DrawnBy would pay off. The cost of that was $0.90 per day. But with CloudWarGames.com on the horizon, I finally bit the bullet and dropped them. I could have put them in cold storage but I decided it was highly unlikely we are going to pick up that project in the future so it is goodbye Pytorch models.

It also pales in comparison to the $42 I spent so far this month on buying new domains which is likely to ramp up.

Other top-line expenses I have are the NatGateway and the Kinesis Shard I am paying for that DrawnBy ran on. Eventually, I will use it but I should probably shut that down for now. The NAT I suppose I will keep. Not that I couldn’t secure it with just the SecurityGroups since I am really picky about those.

Conclusion:

For an extra $1.10 per day, I don’t think I need all the bells and whistles. Both Lambda and ECS run pretty fast now that I bumped up the Lambda’s memory. Maybe in the future when I get more traffic but it is tough to beat $0.01 per day for the APIGateway/Lambda combo. Serverless for the win here.