r/devops • u/ahmedshahid786 • 1d ago
Discussion Self taught backend engineer looking for feedback on my production architecture
TL;DR: Running a Dockerized Node.js backend on a single EC2 instance with Nginx, blue-green deployments, and SSH-based CI/CD. Serving 20–30K DAUs comfortably. Looking to improve security, filter junk traffic, and adopt better deployment practices without unnecessary complexity.
Current architecture:
- Single EC2 instance with a public IP.
- API domain resolves directly to the instance's public IP (which doesn't feel right).
- Nginx and Node.js backend run in Docker on the same network.
- Port 443 is publicly accessible and mapped to Nginx.
- GitHub Actions connects via SSH, pulls the latest image from Docker Hub, starts the inactive container, waits for the health check, switches Nginx traffic, and stops the previous container.
- Frontend builds are deployed to S3 and served through CloudFront.
- Self hosted Prometheus and Grafana on a separate instance.
Blue-green deployments work well with zero downtime. We rarely exceed 20 requests/sec, so scaling isn't currently a concern.
What I need advice on:
- Security and architecture: What would you change in this architecture to make it more secure and production-grade?
- Junk traffic: I've noticed increasing requests from automated scanners probing paths like "/.env". I'm considering moving EC2 into a private subnet behind an ALB. Would that help, or should I consider something like WAF? Is there a simpler, more cost effective solution?
- SSH-based deployments: Is keeping port 22 publicly accessible a bad practice? If I close it, what's the recommended approach for automated deployments?
- Infrastructure as Code: Most of my infrastructure is manually configured. If I ever need to recreate it, I'd have to configure everything from scratch. I'm considering IaC to make my entire AWS infrastructure reproducible. Can I do this with Terraform and would it be worth adopting at this scale?
A little background:
I joined this company as a full stack engineer. When my company needed someone to handle DevOps, I volunteered despite having no prior DevOps experience. I learned along the way and built the current deployment and monitoring infrastructure myself.
Everything works well so far, but I want to understand what experienced DevOps engineers would do differently.
I want to do things right, not just make them work. I want to follow the best industry practices and I'm willing to embrace complexity where it's justified, but I don't want to engineer solutions for problems we don't have.
Would appreciate any advice, architectural suggestions, or resources.
16
u/ang29g 1d ago
> Infrastructure as Code: Most of my infrastructure is manually configured. If I ever need to recreate it, I'd have to configure everything from scratch. I'm considering IaC to make my entire AWS infrastructure reproducible. Can I do this with Terraform and would it be worth adopting at this scale?
If it's not IaC I want nothing to do with it. Great value in moving it to IaC.
Even if your infra is just an ec2 and a bucket or whatever, Iac.
hand-built anything is insta get fired imo.
7
u/theonlywaye 1d ago
Honestly this all just depends on your budget. Everything costs money
For instance remove the public ip from the ec2 instance, put a ALB in front of it, attach a WAF and use the managed ruleset, add rules that it doesn’t cover specific for your app. Add another instance in a different AZ for redundancy.
5
u/Any-Appointment-814 1d ago
Honestly at 20 req/s I wouldn't overbuild it. The two things I'd change are getting the instance off a public IP (private subnet behind an ALB, or if you want it cheaper just Cloudflare in front with the security group only allowing their ranges) and killing the public port 22. For deploys you can have Actions assume a role via OIDC and trigger the container swap with SSM run command, so there's no SSH key sitting in GitHub at all. The /.env scanners are just background noise on any public IP, once nothing is directly exposed you mostly stop caring about them.
2
u/New-Entertainer6392 DevOps 1d ago
For me.
A second VM for sure. One day that VM will break or just disappear.
Then as other have said, perhaps cloudflare. Put a tunnel on each, route to that tunnel and cloudflare will route and balance them for you. It's a very crude balance, as the balance is "what's online".
How are the actual deployments? GitHub? Azdo? Can you put an agent on there to pull your code/image changes. If you've got ssh keys only, and no password logic (and no root login) you're probably good.
Terraform is never a bad idea, even if just to learn it
2
u/Lambrun-Massih 23h ago
Where is your database living in all of this? Before worrying about bot scanners or refactoring the deployment pipeline, making sure your stateful data is off that single box and has automated, tested backups is usually the biggest risk reducer.
1
u/mitchy_darko 22h ago
Regarding IaC: have a look at AWS CDK. It’s been good for me so far.
1
u/Aide_Sea 21h ago
Worth checking how migrations fit into the blue green setup. If the new version changes the schema, the old container still has to work against it, or rollback isn't really a rollback. I think additive changes first, cleanup later, helps :)
1
u/quiet0n3 18h ago
IAC is a must. Plus your single EC2 is a single point of failure. You're better off moving to ECS with an asg or Fargate, putting an ALB Infront and picking up on all that sweet redundancy.
Plus of you're going public, what's your waf situation looking like?
1
u/Pitiful-Storage2189 16h ago
Really useful discussion!
1
u/dariusbiggs 11h ago
Start by asking yourself
You need to plan for a security compromise, you plan for WHEN it happens, not IF it happens.
Configuration of that EC2 instance should be done using IaC, something like Ansible, Chef, Puppet, or SaltStack. That instance should be hardened at least to the CIS Benchmarks. The image being used should be built using an AMI builder, either the AWS one or something like packer. You should have the AWS SSM agent on it. Any SSH access should be protected by fail2ban, with an as secure as possible setup, and per user logins, no "generic" logins, and probably moved off the default port 22.
You should harden your infrastructure at least according to the AWS Foundational settings.
That container image should be scanned for vulnerabilities regularly, and you should be aiming to run it as non-root preferably distroless if you can.
NGINX should be configured according to suitable restrictive TLS1.3 configuration with the application firewall (ModSecurity?) enabled IF you don't replace it with AWS WAF, and an ALB.
That blue green container setup can be done with ECS instead, and combined with replacing NGINX with cloudfront, an api gateway, or an ALB, you can remove the need for that ec2 instance completely.
Lota and lots of options and choices you can make. But the most important is to get that working via IaC, import the existing resources, and get ready to be able to rebuild the entire thing.
1
u/NoDevelopment206 7h ago
20 requests a second on one box is fine so i wouldnt overbuild. the cheap wins are closing port 22 and using ssm session manager or a self hosted runner instead, and putting the instance behind an alb so the public ip goes away. a basic waf with the managed rules will drop most of the /.env scanner junk. on terraform, you dont need to import everything at once. start by writing the security group, alb and iam bits as code and add the rest over time, because even a half codified setup is easier to rebuild than none.
1
u/Unfair_Worth4366 2h ago
The current setup seems reasonable for that level of traffic, so there’s no need to introduce extra infrastructure all at once. Moving SSH access to SSM, putting the instance behind an ALB, and gradually bringing the setup into Terraform would be practical first steps. The Docker image also deserves attention through regular scanning, non-root execution and removing unnecessary packages; rapidfort is relevant to the broader discussion around container hardening.