r/devops • • 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:

  1. Security and architecture: What would you change in this architecture to make it more secure and production-grade?
  2. 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?
  3. SSH-based deployments: Is keeping port 22 publicly accessible a bad practice? If I close it, what's the recommended approach for automated deployments?
  4. 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.

0 Upvotes

26 comments sorted by

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.

2

u/Cyberbird85 14h ago

I would not say instafire but with opentofu and OTC there is no excuse no to go for it.

1

u/ahmedshahid786 34m ago

Got it. This answers my question and now I'm convinced that IaC is gonna be worth it of a move.

Any suggestions where to start or what to keep in mind while migrating workloads to IaC?

1

u/ahmedshahid786 35m ago

Thanks, man! I’m definitely leaning towards IaC now. Any advice on where to start learning Terraform and how to bring my existing infrastructure under it?

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.

1

u/ahmedshahid786 31m ago

Yeah, this is the direction I was leaning towards as well. My only concern is whether an ALB makes sense in front of a single EC2 instance. I don't see myself needing horizontal scaling anytime soon, and vertical scaling should serve us well for quite a while.

Can WAF be enough? What value would an ALB provide in this case beyond WAF integration and keeping EC2 private?

Like I want to understand the role of an ALB when we put it in front of a single instance

Thanks in advance :)

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.

1

u/ahmedshahid786 29m ago

So would putting Cloudflare in front of EC2 essentially replace the need for an ALB + WAF in my case? If cost isn't a major concern, which approach would you prefer and why? What would I gain or miss out on by going with Cloudflare instead?

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

1

u/ahmedshahid786 17m ago

Appreciate the input. This is exactly what I was looking for.

A second VM for redundancy makes sense. I'll explore Cloudflare Tunnels and Terraform.

I'm using GitHub Actions with SSH via SSH key, with password authentication and root login disabled. Only key based SSH enabled.

By agent, do you mean a self hosted runner? Wouldn't that require additional compute and maintenance?

My instance is provisioned with just enough resources for the backend and some headroom for traffic spikes. Would running an agent require additional compute or introduce another maintenance overhead?

Given my setup, would you prefer an agent, SSM, or key based SSH?

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/ahmedshahid786 16m ago

The database is hosted separately on MongoDB Atlas, which handles security, automated backups, maintenance, and updates. No data is stored on the instance.

Appreciate you bringing this up, though!

1

u/mitchy_darko 22h ago

Regarding IaC: have a look at AWS CDK. It’s been good for me so far.

1

u/ahmedshahid786 15m ago

Appreciate the suggestion!

Any particular reason you prefer AWS CDK over Terraform?

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/ahmedshahid786 13m ago

Good point! We use NoSql database, MongoDB. So we don't have to worry about schema migrations.

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/ahmedshahid786 9m ago

I'm pretty much sold on IaC at this point. As everyone is suggesting this.

Redundancy makes sense too, but would you consider ECS/Fargate worth the added complexity at barely 20 req/s?

As for WAF, we don't have one currently. But I'm evaluating AWS WAF + ALB versus Cloudflare, as others here have suggested. And would choose and implement either one of them soon.

Would you like to have a word on this?

1

u/Pitiful-Storage2189 16h ago

Really useful discussion!

1

u/ahmedshahid786 9m ago

Yeah, indeed it is. I must say

I'm learning a lot.

1

u/dariusbiggs 11h ago

Start by asking yourself

  • How can I break this.
  • What are the single points of failure
  • What automation do i need to implement to reduce the risks so that all systems are managed via Git and, CICD pipelines and only the absolute minimum is done manually (not all things have automation available, but all the most common stuff soes).
  • How much effort is it to recreate the entire setup when the account is compromised

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.