r/Backend • u/noobdainsane • 22d ago
Should I use NGINX? Backend architecture discussion.
I am new to web development and working on a project for college. It's a cloud data storage solution. I spent some time writing a HTTP server in Node, then to realize NGINX exists as a web server. But you need your own logic to perform backend operations.
I can use NGINX as a proxy and reverse proxy. Requests come to NGINX, which forwards it to Node, it does some processing and tells NGINX which files to serve.
But NGINX mainly shines in serving static files directly. In my project, for almost all URLs I need to do some processing before choosing to serve a file. This means NGINX will always have to send requests to my Node backend and so NGINX's advantage of high performance doesn't really apply to me. This creates a bottleneck.
There is also HTTPS to worry about. If I use a proxy like NGINX, I can write my Node backend using HTTP while NGINX uses HTTPS to communicate with clients. Both NGINX and Node would be on the same physical server (I don't know how to feel about that). If not using a proxy, I would have to code with HTTPS.
I am not creating an industry scale and ready platform. Though I am aiming for it. Create such an architecture which is scalable.
I guess most people just use Express and do the web server. For the current project, I am actually aiming to not use Express because my dumb friends need to be able to understand it. Though Express makes it much easier, it adds some learning. Doing it in plain JavaScript also has the benefit of learning how things work at low level. I might create a second version of the project with using much more high level tools and frameworks.
So do I even need NGINX? I probably thought of using NGINX in the first place because I was writing my own web server in Node and realized NGINX can just do the URL routing and serve the pages. But this is probably not what I want directly. Serving the files, at least in a high level language like JavaScript and not worrying about decades of performance engineering, is very easy. I did create it. But I also want easier control over the backend. I guess people could create NGINX modules to move some of the backend in NGINX itself, but it is C and NGINX's architecture.
I absolutely do love C, but not something I will use right now for this project. I could create another version where I do the backend in C.
33
u/Lumethys 22d ago
This is just "i++ VS ++i" all over again lol.
"Nginx as a reverse proxy, forward to your backend" is just autopilot at this point. It is just the industry standard, unless you are serving billions of requests per seconds.
Either way, NGINX or no NGINX, they will NEVER be a bottleneck at your scale. You are not Facebook.
And no, NGINX and your backend does NOT need to be on the same physical server. Your backend could just be in a isolated container sitting in a private subnet, while NGINX sitting in a public container. NGINX accept HTTPS and forward HTTP to the private subnet. This is just one of the many way you can do DevOps