r/flask Apr 14 '24

Tutorials and Guides Flask Deployment on AWS ECS

Hello! I have a fitness application that has around 3000 daily active users. Now, I want to scale it horizontally and I want to deploy it on AWS ECS and I am facing trouble with security groups, services, rules. Basically, I have never deployed on AWS before. Now, I want to deploy it on short notice for production. So, Kindly share any quick related helpful tutorial or guide. Thanks! PS: Currently It’s on digital ocean droplet and I have created docker image already and uploaded on amazon elastic registry. Image runs well on local. I have attached RDS with it. Having trouble connecting to Document Cluster.

2 Upvotes

17 comments sorted by

3

u/TollwoodTokeTolkien Apr 14 '24

You say your company wants it on AWS. Is EKS an option? Yes, it's another ~$72/month or so for the K8s control plane but IMO there are less issues with figuring out security groups and routing rules with EKS than ECS, especially with EKS managed node groups. Plus it's a lot easier to move your K8s manifests/Helm charts to AKS/GKE should your company decide to pull out of AWS.

1

u/bee_aayy Apr 14 '24

I searched about EKS, and came to know that my application is monolithic and not that big enough to put it on EKS and decided to go through ECS.

2

u/TollwoodTokeTolkien Apr 14 '24

I see. To be honest, I haven't really found a good tutorial that explains how to effectively configure tasks roles/security groups/networking in ECS better than the AWS provided documentation (assuming that you're using Fargate and not adding to complexity by provisioning EC2 container instances yourself). I guess if you get into the 11th hour and still don't have a working solution, you could just write an EC2 launch template that downloads/installs Docker, pulls your ECR image and fires up some containers in that, then wrap it in an ASG behind an ALB. Less complex than navigating ECS IMO.

1

u/bee_aayy Apr 14 '24

thanks for the heads up, I will avoid using ec2 then. Will check fargate though. I actually don’t have any senior worked on related things. Even an advice would be good for production, just like you said about using fargate

3

u/baubleglue Apr 14 '24

I don't know an answer, but number of daily users means almost nothing. You need to look first for the number of concurrent users at pick time (active sessions) and max requests per second.

1

u/bee_aayy Apr 14 '24

those are way less for now, but we are planning for future.

2

u/androgeninc Apr 14 '24

Cant help with guides, but are you sure you need to switch to AWS for scaling? What are the bottlenecks that AWS will solve?

1

u/bee_aayy Apr 14 '24

Need horizontal scaling for server, like our marketing team run campaigns and we got user load on server. According to the marketing team they said soon we will have around 8K daily active users. That’s why I thought to use containers for scaling. also my manager is getting on my nerves over this.

2

u/androgeninc Apr 14 '24

All right, understood. I'm not gonna tell you you're wrong, but keep in mind this: https://thmsmlr.com/cheap-infra

And wouldn't it be easier to just put a load balancer in front on DO, and add more droplets behind?

1

u/bee_aayy Apr 14 '24

I am new to this, however I tried implementing load balancer on DO droplet and It became slower.

2

u/androgeninc Apr 14 '24

Haha, backend architecture is the gift that keeps giving. AWS is great, but I would personally revisit load balancing on DO. Sounds overkill to need fancy AWS scaling solutions for an app with 8000 daily users. Know this doesn't help you. Just my 2 cents.

Edit: Also, the bottlenecks are kind of important.

1

u/bee_aayy Apr 14 '24

Checked APIs responses, they’re good. Structure wise, implemented Factory method pattern. Used ORMs for databases. Queries are pretty basic and simple ones.

1

u/androgeninc Apr 14 '24

Aha, so no bottlenecks yet. You just want to be prepared.

1

u/bee_aayy Apr 14 '24

Yess, exactly.

1

u/bee_aayy Apr 14 '24

It’s the company that wants AWS, so why not 🤷🏽‍♂️

1

u/caspii2 Apr 15 '24

My App has 10-20k visits per day. Single Flask instance running on Digital Ocean. I think you’re fine on DO. Sounds like a case of premature optimization

1

u/bee_aayy Apr 15 '24

Yeah, Manager wants me to do it for safer side.