PyData London 2024

Achieving Concurrency in Streamlit with a RQ scheduler, Building Responsive Data Applications
06-16, 16:30–17:10 (Europe/London), Salisbury

With increasing adoption of Streamlit to create interactive data applications in the usage of generative AI technologies, a challenge of maintaining responsiveness under heavy or concurrent user interactions has emerged as applications grow in complexity, sometimes with a long-running background job. This is where integrating task queueing systems like Redis Queue (RQ) into Streamlit applications can come in handy.
In this talk, we will explore how we can enable this integration between RQ and Streamlit to achieve concurrency, improve user experiences and effectively manage long-running tasks.


We will begin by discussing the limitations of Streamlit's default threading model when faced with CPU-bound or long-running operations. And then we will uncover how RQ, a light-weight, Redis-backed task queue for Python that offers a simple way to offload work out of Streamlit's main thread of execution can help to overcome these limitations.

This task is intended for Python developers, data scientists and engineers who are looking to improve concurrency and responsiveness in building their Streamlit data applications, such as those with long-running background AI tasks. Basic knowledge of Redis and task queues is beneficial but not required.
Outline

Our journey will include:

An overview of Streamlit's architecture and where concurrency challenges typically arise.

A primer on task queues and their importance in modern web applications.

A detailed examination of RQ, including its setup from a hands-on perspective

Step-by-step guidance on how to integrate RQ task queue into a Streamlit app, and eventually into a new Python package, including but not limited to:

Initiating RQ workers
Creating job functions
Enqueuing tasks
How the Streamlit front-end initiates the above workflows and receives returned results

Demonstrations of a real-world example where RQ effectively manages concurrent processing in Streamlit apps using the newly written Python library.

To solidify our understanding, we will walk through a sample Streamlit application enhanced by RQ, and a new Python library written for that purpose to streamline and simplify the process.

By the end of this talk, attendees will have a clear blueprint for making their Streamlit applications concurrent using RQ. They will leave equipped with the knowledge of the newly written Python library, how to build responsive and scalable data applications that can gracefully handle the demands of multiple users and complex operations.

Takeaways: How the newly written Python library bakes the following ingredients into building a seamless Streamlit user experience that:

overcomes the concurrency limitations in Streamlit with RQ.
RQ is integrated into a Steamlit app where the front-end communicates with RQ workers fluently.
long-running background tasks are handled in the best practices for a seamless user experience.
adopts strategies for concurrent applications to be built in a scalable and secured fashion with Streamlit and RQ.

Join us to unlock the full potential of your Streamlit applications by harnessing the power of RQ for responsive and concurrent data processing!


Prior Knowledge Expected

Previous knowledge expected

I have worked as a data scientist and BI developer for both the public and private sector in Canada. I have built Python applications in my day job including but not limited to: higher-education institutional teaching resource optimization for a major public research university, topic modeling for public opinion survey to facilitate better public policy making, risk detection in disease onset, record linkage to deduplicate fuzzy records in financial databases. I taught AI courses on a part-time basis for a public college post-graduate diploma program to better equip international students for North American analytics job markets. As a volunteer enthusiast to build up a local Python technology community, I also advocate for Python technologies together with AI modeling in founding the Public Data Technology Forum meetup group and running regular workshops since 2014, while running its corresponding YouTube tech talks channel too:

Public Data Townhall: https://www.youtube.com/channel/UCi6e2FiTbDrRdh90sPdCMXQ