I have a few chat apps running on EC2 instances. The apps are built with Streamlit and have relatively low traffic at the moment.
I have a Web Application Firewall (WAF) that sits in front of an application load balancer (ALB) that sits in front of the EC2 instances that host these chatbots. Here’s the setup again for more clarity:
User => WAF => ALB => EC2 Streamlit App
For analytics I’m contemplating using the streamlit-analytics2 package.
To keep the streamlit apps alive, I use the systemd command.
For caching, I use the built-in st.cache_data decorator.
Given this setup, can you comment on the pros and cons of using Nginx as a webserver for deployment of a Streamlit app on AWS EC2? Do we really need Nginx?
Getting a robust discussion around this topic may be helpful to many other people in a similar situation.
Using Nginx as a web server for deploying Streamlit apps on AWS EC2 has both pros and cons. Here’s a brief overview to help you decide if you really need it:
Pros:
Load Balancing: Although you have an ALB, Nginx can provide additional load balancing, helping distribute traffic more efficiently among your instances.
SSL/TLS Termination: Nginx can handle SSL/TLS termination, reducing the load on your Streamlit apps and providing a layer of security.
Reverse Proxy: It can act as a reverse proxy, handling requests and forwarding them to your Streamlit apps, which can help with performance and security.
Caching: Nginx can cache static content, reducing the load on your Streamlit apps and improving response times.
Security: Additional security features like rate limiting and access control can be implemented using Nginx.
Cons:
Complexity: Adding Nginx introduces additional complexity to your setup, requiring configuration and maintenance.
Overhead: There is a slight performance overhead due to the additional layer in your stack, though this is usually minimal.
Redundancy: Since you already have a WAF and ALB, some of the benefits of Nginx might be redundant, depending on your specific use case.
Do You Really Need Nginx?
Given your current setup with WAF and ALB, adding Nginx might not be strictly necessary. However, if you require the specific benefits that Nginx provides (e.g., SSL termination, caching, additional security), it could still be valuable. For low-traffic apps, the added complexity may not be justified, and you might want to keep your setup simpler until traffic increases or specific needs arise.
But it would be great to get feedback from real humans
@Vikram_N Hi there I am the maintainer for streamlit-analytics2
I am glad to hear that you are contemplating using the package. I am here if you have any questions or suggestions for the project.
My two cents on this: NGINX is a great tool but what problem in your setup does it solve? With a WAF and an ALB(assumed to be an L7 ALB), your security and routing should be handled quite well.
I have run streamlit apps in containerized deployments before and it actually works incredibly well since the streamlit app can be used in a stateless manner by default. Throw in an API behind streamlit and now you have a use case for NGINX but tbh still overkill. Flask or even nowadays even just Golang is suitable for an API to connect your streamlit frontend to a backend and other data sources.
Maybe that level of system design is overkill but it is definitely scalable.
I can hardly think of a use case that requires NGINX these days with all the other tools that are afforded to us by cloud providers that can handle all the routing, SSL termination and scaling for us. It suits well if youre scaling VMs but since you mentioned there is low traffic right now, I would argue for a containerized version of streamlit as a FE with an API to connect to backends, etc
WAF → ALB → Streamlit stateless FE → Flask/golang API → stateful BE +
| → SQL server +
| → external resources +
| → internal cloud services
Thanks for stopping by! We use cookies to help us understand how you interact with our website.
By clicking “Accept all”, you consent to our use of cookies. For more information, please see our privacy policy.
Cookie settings
Strictly necessary cookies
These cookies are necessary for the website to function and cannot be switched off. They are usually only set in response to actions made by you which amount to a request for services, such as setting your privacy preferences, logging in or filling in forms.
Performance cookies
These cookies allow us to count visits and traffic sources so we can measure and improve the performance of our site. They help us understand how visitors move around the site and which pages are most frequently visited.
Functional cookies
These cookies are used to record your choices and settings, maintain your preferences over time and recognize you when you return to our website. These cookies help us to personalize our content for you and remember your preferences.
Targeting cookies
These cookies may be deployed to our site by our advertising partners to build a profile of your interest and provide you with content that is relevant to you, including showing you relevant ads on other websites.