liveBook · Manning

Load balancing

As explained in Build Python Web Apps with Streamlit

A load balancer is an infrastructure component that distributes incoming network traffic across multiple service instances and can route traffic away from unhealthy instances.

Load balancing places an infrastructure component between users and an application. It distributes incoming requests across multiple service instances, helping the application remain scalable and reliable when traffic increases or an instance fails. section 12.4.3

A typical request follows this path:

  • The browser sends a request to the load balancer. section 12.3.3
  • The load balancer forwards the request to one of the EC2 instances running the application. section 12.3.3
  • Each instance passes the request to its Docker container, where the application processes it and generates a response. section 12.3.3
  • The load balancer returns the response to the browser and can redirect traffic away from failed or overloaded instances. section 12.4.3

Creating a load-balanced Elastic Beanstalk environment

Running `eb create` provisions an environment with multiple EC2 instances, a load balancer, networking rules, and monitoring. The default application load balancer distributes traffic between instances. A single-instance deployment can avoid load-balancer costs, but it removes this multi-instance arrangement. section 12.3.6

A load balancer can also terminate HTTPS connections. Configure an HTTPS listener on port 443, attach the certificate, and forward traffic to the application instead of making the application handle encryption directly. section 12.4.3

Figure 12.4 The end state of the deployed Streamlit app on AWS

Use the deployment architecture diagram to trace traffic from the browser through the load balancer, EC2 instances, Docker containers, and application. section 12.3.3

Figure 12.12 Adding an HTTPS listener and a certificate to the load balancer

Use the configuration figure to inspect the HTTPS listener and certificate settings on the load balancer. section 12.4.3

How Build Python Web Apps with Streamlit covers it

How deep it goes
Explains request flow, instance failures, deployment choices, and HTTPS listeners, but defers detailed load-balancer internals.
Examples
Uses an Elastic Beanstalk deployment, an application load-balancer selection, a single-instance alternative, and an HTTPS listener configuration.
What it assumes
Assumes an application packaged for deployment and familiarity with Elastic Beanstalk environments, EC2 instances, Docker, and AWS configuration.
What you can do after
Operate/configure a load-balanced Elastic Beanstalk environment and attach an HTTPS listener and certificate.
How it connects
Connects load balancing with Elastic Beanstalk, EC2, Docker, Streamlit, HTTPS, SSL certificates, networking, and health monitoring.

Also explained in

Compare how 14 books explain load balancing →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Build Python Web Apps with Streamlit. The section links point to the parts of the book it draws on.