As we are increasingly using the Bokeh Server at our company, I decided to “standardize” all the Bokeh Server deployments inside our data science team.
Given that we love deploying web apps using Gunicorn (because it just works and it’s super-easy to manage), I was looking for a way of deploying with Gunicorn but without losing all async capabilities end-to-end.
Fortunately, ASGI (which is basically WSGI + native async support) is becoming increasingly popular, and most modern Python async web frameworks (Starlette, Sanic, Django Channels…) are embracing its usage.
Unfortunately Tornado (what Bokeh Server is based on) does not support ASGI deployments. Nevertheless, it is possible to embed the Bokeh Server inside one of these ASGI frameworks to have a fully ASGI async pipeline.
I have prepared an example here on how to embed the Bokeh Server inside an Starlette app, using Uvicorn (which is Gunicorn + ASGI support) to deploy. The nice thing is that both the Bokeh Server and the rest of the Starlette app share the same ioloop, which in fact can be written in C (such as uvloop)
Hope someone finds it interesting for wide production deployments!